diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java index de1d49de9..542eccfeb 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/SimpleChuteBlockEntity.java @@ -59,22 +59,24 @@ public void load(@NotNull CompoundTag tag) { @SuppressWarnings({"UnreachableCode", "DuplicatedCode"}) public void tick() { if (cooldown <= 0) { - if (ItemDepositoryHelper.getItemDepository(getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite()) != null) { - // 尝试向朝向容器输出 - if (!depository.isEmpty()) { - ItemDepositoryHelper.exportToTarget(depository, 64, stack -> true, getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite()); - } - } else { - Vec3 center = getBlockPos().relative(getDirection()).getCenter(); - AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125)); - if (getLevel().noCollision(aabb)) { - for (int i = 0; i < depository.getSlots(); i++) { - ItemStack stack = depository.getStack(i); - if (!stack.isEmpty()) { - ItemEntity itemEntity = new ItemEntity(getLevel(), center.x, center.y, center.z, stack, 0, 0, 0); - getLevel().addFreshEntity(itemEntity); - depository.setStack(i, ItemStack.EMPTY); - break; + if (getBlockState().getValue(SimpleChuteBlock.ENABLED)) { + if (ItemDepositoryHelper.getItemDepository(getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite()) != null) { + // 尝试向朝向容器输出 + if (!depository.isEmpty()) { + ItemDepositoryHelper.exportToTarget(depository, 64, stack -> true, getLevel(), getBlockPos().relative(getDirection()), getDirection().getOpposite()); + } + } else { + Vec3 center = getBlockPos().relative(getDirection()).getCenter(); + AABB aabb = new AABB(center.add(-0.125, -0.125, -0.125), center.add(0.125, 0.125, 0.125)); + if (getLevel().noCollision(aabb)) { + for (int i = 0; i < depository.getSlots(); i++) { + ItemStack stack = depository.getStack(i); + if (!stack.isEmpty()) { + ItemEntity itemEntity = new ItemEntity(getLevel(), center.x, center.y, center.z, stack, 0, 0, 0); + getLevel().addFreshEntity(itemEntity); + depository.setStack(i, ItemStack.EMPTY); + break; + } } } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java index eecd58908..d1434e80e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/init/ModBlocks.java @@ -19,6 +19,8 @@ import net.minecraft.data.recipes.RecipeCategory; import net.minecraft.data.recipes.ShapedRecipeBuilder; import net.minecraft.tags.BlockTags; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -120,7 +122,9 @@ public class ModBlocks { .properties(BlockBehaviour.Properties::noOcclusion) .blockstate((ctx, provider) -> { }) - .simpleItem() + .item(BlockItem::new) + .onRegister(blockItem -> Item.BY_BLOCK.put(ModBlocks.SIMPLE_CHUTE.get(), blockItem)) + .build() .defaultLoot() .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) .recipe((ctx, provider) -> ShapedRecipeBuilder.shaped(RecipeCategory.TOOLS, ModBlocks.CHUTE) @@ -138,7 +142,8 @@ public class ModBlocks { .block("simple_chute", SimpleChuteBlock::new) .initialProperties(() -> Blocks.IRON_BLOCK) .properties(BlockBehaviour.Properties::noOcclusion) - .blockstate((ctx, provider) -> {}) + .blockstate((ctx, provider) -> { + }) .loot((tables, block) -> tables.dropOther(block, ModBlocks.CHUTE)) .tag(BlockTags.MINEABLE_WITH_PICKAXE, BlockTags.MINEABLE_WITH_AXE) .register(); @@ -316,9 +321,9 @@ public class ModBlocks { .initialProperties(() -> Blocks.SLIME_BLOCK) .blockstate((ctx, provider) -> { provider.simpleBlock(ctx.get()); - provider.models().cubeAll(ctx.getName(), provider.modLoc( "block/" + ctx.getName())).renderType("translucent"); + provider.models().cubeAll(ctx.getName(), provider.modLoc("block/" + ctx.getName())).renderType("translucent"); }) - .properties(properties->properties.sound(SoundType.HONEY_BLOCK)) + .properties(properties -> properties.sound(SoundType.HONEY_BLOCK)) .simpleItem() .defaultLoot() .tag(BlockTags.MINEABLE_WITH_PICKAXE) @@ -335,7 +340,7 @@ public class ModBlocks { .initialProperties(() -> Blocks.EMERALD_BLOCK) .blockstate((ctx, provider) -> { provider.simpleBlock(ctx.get()); - provider.models().cubeAll(ctx.getName(), provider.modLoc( "block/" + ctx.getName())).renderType("translucent"); + provider.models().cubeAll(ctx.getName(), provider.modLoc("block/" + ctx.getName())).renderType("translucent"); }) .properties(BlockBehaviour.Properties::noOcclusion) .simpleItem()