From 8348e80f4c5b199a9ef24a17ef91fd0f4400481f Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Tue, 11 Jun 2024 23:17:38 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20#878=20fixed=20#879=20=E8=AE=A9?= =?UTF-8?q?=E7=94=B5=E8=8D=B7=E6=94=B6=E9=9B=86=E5=99=A8=E6=9C=895x5x5?= =?UTF-8?q?=E7=9A=84=E7=94=B5=E7=BD=91=E8=8C=83=E5=9B=B4=20=E4=B8=BA?= =?UTF-8?q?=E7=94=B5=E8=8D=B7=E6=94=B6=E9=9B=86=E5=99=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/block/BlockDevourerBlock.java | 1 + .../dubhe/anvilcraft/block/GiantAnvilBlock.java | 2 +- .../block/entity/ChargeCollectorBlockEntity.java | 14 +++++++++++++- .../data/recipe/transform/TransformOptions.java | 5 ++++- .../event/AnvilHitBlockDevourerEventListener.java | 9 +++++++-- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java index 914d5ceac..0897c344a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java @@ -129,6 +129,7 @@ public void neighborChanged( * @param devourerDirection 破坏方向 * @param range 破坏半径(正方形) */ + @SuppressWarnings("unreachable") public void devourBlock(ServerLevel level, BlockPos devourerPos, Direction devourerDirection, int range) { BlockPos outputPos = devourerPos.relative(devourerDirection.getOpposite()); BlockPos devourCenterPos = devourerPos.relative(devourerDirection); diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java index f51fdc26f..074903208 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/GiantAnvilBlock.java @@ -325,7 +325,7 @@ public boolean canPlace(Level level, BlockPos pos) { for (int y = 0; y <= range + 1; y++) { for (int z = -range; z <= range; z++) { BlockPos currentPos = pos.offset(x, y, z); - if (!level.isEmptyBlock(currentPos)) return false; + if (!level.isEmptyBlock(currentPos) || level.isOutsideBuildHeight(currentPos)) return false; } } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChargeCollectorBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChargeCollectorBlockEntity.java index 961f73214..c962218fc 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChargeCollectorBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/ChargeCollectorBlockEntity.java @@ -2,6 +2,7 @@ import dev.dubhe.anvilcraft.api.power.IPowerProducer; import dev.dubhe.anvilcraft.api.power.PowerGrid; +import dev.dubhe.anvilcraft.api.tooltip.IHasAffectRange; import dev.dubhe.anvilcraft.init.ModBlockEntities; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -9,10 +10,11 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public class ChargeCollectorBlockEntity extends BlockEntity implements IPowerProducer { +public class ChargeCollectorBlockEntity extends BlockEntity implements IPowerProducer, IHasAffectRange { private static final double MAX_POWER_PER_INCOMING = 128; private static final int COOLDOWN = 40; @@ -36,6 +38,11 @@ private ChargeCollectorBlockEntity(BlockEntityType type, BlockPos pos, BlockS super(type, pos, blockState); } + @Override + public int getRange() { + return 2; + } + @Override public Level getCurrentLevel() { return this.level; @@ -94,4 +101,9 @@ public double incomingCharge(double num) { this.chargeNum += num - surplus; return surplus; } + + @Override + public AABB shape() { + return AABB.ofSize(getBlockPos().getCenter(), 5, 5, 5); + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/TransformOptions.java b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/TransformOptions.java index 8afef9623..5b1cb0116 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/TransformOptions.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/TransformOptions.java @@ -11,6 +11,7 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.monster.Giant; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import org.jetbrains.annotations.NotNull; @@ -40,7 +41,9 @@ public void accept(Entity oldEntity, Entity newEntity) { || itemStack.is(Items.CHIPPED_ANVIL) || itemStack.is(Items.DAMAGED_ANVIL)) { o.setItemInHand(value, ModBlocks.GIANT_ANVIL.asItem().getDefaultInstance()); - n.setItemInHand(value, ModBlocks.GIANT_ANVIL.asItem().getDefaultInstance()); + if (newEntity instanceof Giant) { + n.setItemInHand(value, ModBlocks.GIANT_ANVIL.asItem().getDefaultInstance()); + } if (n instanceof Mob mob) { mob.setDropChance( value == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND, diff --git a/common/src/main/java/dev/dubhe/anvilcraft/event/AnvilHitBlockDevourerEventListener.java b/common/src/main/java/dev/dubhe/anvilcraft/event/AnvilHitBlockDevourerEventListener.java index 7d20d14b3..0b6b3d937 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/event/AnvilHitBlockDevourerEventListener.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/event/AnvilHitBlockDevourerEventListener.java @@ -30,10 +30,15 @@ public void onLand(@NotNull AnvilFallOnLandEvent event) { int range = (int) event.getFallDistance() + 2; range = Math.min(range, 3); level.setBlock(pos, state.setValue(BlockDevourerBlock.TRIGGERED, true), 2); + if (state.getValue(BlockDevourerBlock.FACING) == Direction.DOWN + && level.isOutsideBuildHeight(pos.below())) { + level.scheduleTick(pos, devourerBlock, 4); + return; + } devourerBlock.devourBlock(serverLevel, pos, - state.getValue(BlockDevourerBlock.FACING), range); + state.getValue(BlockDevourerBlock.FACING), range); if (state.getValue(BlockDevourerBlock.FACING) == Direction.DOWN - && level.getBlockState(pos.below()).getBlock().defaultDestroyTime() >= 0) { + && level.getBlockState(pos.below()).getBlock().defaultDestroyTime() >= 0) { level.setBlock(pos, Blocks.AIR.defaultBlockState(), 2); level.setBlock(pos.below(), state.setValue(BlockDevourerBlock.TRIGGERED, true), 2); level.scheduleTick(pos.below(), devourerBlock, 4);