Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使末地尘可与重力方块交换位置 #1233

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading