Skip to content

Commit

Permalink
Merge pull request #1233 from QiuShui1012/end_dust
Browse files Browse the repository at this point in the history
使末地尘可与重力方块交换位置
  • Loading branch information
Gu-ZT authored Dec 4, 2024
2 parents eccc678 + 6e704ec commit 5075ea8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
17 changes: 13 additions & 4 deletions common/src/main/java/dev/dubhe/anvilcraft/block/EndDustBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -47,12 +51,17 @@ 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());
}
}

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 5075ea8

Please sign in to comment.