diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/EndDustBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/EndDustBlock.java index c3a57186f..c00e5c0b7 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/EndDustBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/EndDustBlock.java @@ -32,9 +32,13 @@ public void onPlace( public void tick( @NotNull BlockState state, @NotNull ServerLevel level, @NotNull BlockPos pos, @NotNull RandomSource random ) { - if (!level.getFluidState(pos.above()).is(FluidTags.WATER)) return; - if (!FallingBlock.isFree(level.getBlockState(pos.above()))) return; - FloatingBlockEntity._float(level, pos, state); + boolean isWater = level.getFluidState(pos.above()).is(FluidTags.WATER); + if ( + (isWater && FallingBlock.isFree(level.getBlockState(pos.above()))) + || level.getBlockState(pos.above()).getBlock() instanceof FallingBlock + ) { + FloatingBlockEntity._float(level, pos, state, isWater); + } } @SuppressWarnings("deprecation") @@ -47,7 +51,7 @@ public void neighborChanged( @NotNull BlockPos neighborPos, boolean movedByPiston ) { - if (level.getFluidState(neighborPos).is(FluidTags.WATER)) { + if (isEligible(level, pos, neighborPos)) { level.scheduleTick(pos, this, this.getDelayAfterPlace()); } } @@ -55,4 +59,9 @@ public void neighborChanged( protected int getDelayAfterPlace() { return 2; } + + public static boolean isEligible(Level level, @NotNull BlockPos pos, @NotNull BlockPos neighborPos) { + return level.getFluidState(neighborPos).is(FluidTags.WATER) + || level.getBlockState(pos.above()).getBlock() instanceof FallingBlock; + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/entity/FloatingBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/entity/FloatingBlockEntity.java index 422f0c630..5cb2c7c65 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/entity/FloatingBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/entity/FloatingBlockEntity.java @@ -20,6 +20,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Fallable; +import net.minecraft.world.level.block.FallingBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; @@ -58,15 +59,22 @@ private FloatingBlockEntity(Level level, double x, double y, double z, BlockStat * @param pos 方块坐标 * @param blockState 方块状态 */ - public static FloatingBlockEntity _float(Level level, BlockPos pos, BlockState blockState) { + public static FloatingBlockEntity _float(Level level, BlockPos pos, BlockState blockState, boolean isWater) { FloatingBlockEntity floatingBlockEntity = new FloatingBlockEntity( level, (double) pos.getX() + 0.5, pos.getY(), (double) pos.getZ() + 0.5, blockState.hasProperty(BlockStateProperties.WATERLOGGED) - ? blockState.setValue(BlockStateProperties.WATERLOGGED, false) : blockState); - level.setBlock(pos, Fluids.WATER.defaultFluidState().createLegacyBlock(), 3); + ? blockState.setValue(BlockStateProperties.WATERLOGGED, false) : blockState + ); + + level.setBlock( + pos, + isWater ? Fluids.WATER.defaultFluidState().createLegacyBlock() + : Blocks.AIR.defaultBlockState(), + 3 + ); level.addFreshEntity(floatingBlockEntity); return floatingBlockEntity; } @@ -80,7 +88,10 @@ public void tick() { ++this.time; BlockPos blockPos = this.blockPosition(); - if (this.level().getFluidState(blockPos.above()).is(FluidTags.WATER) && !underCeiling) { + if ( + (this.level().getFluidState(blockPos.above()).is(FluidTags.WATER) && !underCeiling) + || this.level().getBlockState(blockPos.above()).getBlock() instanceof FallingBlock + ) { this.setDeltaMovement(this.getDeltaMovement().add(0.0, 0.04, 0.0)); } else { if (!this.level().isClientSide) {