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

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

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 src/main/java/dev/dubhe/anvilcraft/block/EndDustBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ public void tick(
BlockPos pos,
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);
}
}

@Override
Expand All @@ -56,12 +60,17 @@ public void neighborChanged(
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;
}
}
67 changes: 39 additions & 28 deletions src/main/java/dev/dubhe/anvilcraft/entity/FloatingBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.material.Fluids;
Expand All @@ -31,6 +32,7 @@ public class FloatingBlockEntity extends FallingBlockEntity {
private boolean underCeiling = false;

/**
*
*/
public FloatingBlockEntity(EntityType<? extends FallingBlockEntity> entityType, Level level) {
super(entityType, level);
Expand All @@ -51,20 +53,26 @@ private FloatingBlockEntity(Level level, double x, double y, double z, BlockStat
}

/**
* @param level 世界
* @param pos 方块坐标
* @param level 世界
* @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);
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,
isWater ? Fluids.WATER.defaultFluidState().createLegacyBlock()
: Blocks.AIR.defaultBlockState(),
3
);
level.addFreshEntity(floatingBlockEntity);
return floatingBlockEntity;
}
Expand All @@ -78,7 +86,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 All @@ -91,42 +102,42 @@ public void tick() {
if (!blockState.is(Blocks.MOVING_PISTON)) {
if (!this.cancelDrop) {
boolean bl3 = blockState.canBeReplaced(new DirectionalPlaceContext(
this.level(), blockPos, Direction.DOWN, ItemStack.EMPTY, Direction.UP));
this.level(), blockPos, Direction.DOWN, ItemStack.EMPTY, Direction.UP));
boolean bl5 = this.blockState.canSurvive(this.level(), blockPos);
if (bl3 && bl5) {
if (this.blockState.hasProperty(BlockStateProperties.WATERLOGGED)
&& this.level()
.getFluidState(blockPos)
.getType()
== Fluids.WATER) {
&& this.level()
.getFluidState(blockPos)
.getType()
== Fluids.WATER) {
this.blockState =
this.blockState.setValue(BlockStateProperties.WATERLOGGED, true);
this.blockState.setValue(BlockStateProperties.WATERLOGGED, true);
}

if (this.level().setBlock(blockPos, this.blockState, 3)) {
((ServerLevel) this.level())
.getChunkSource()
.chunkMap
.broadcast(
this,
new ClientboundBlockUpdatePacket(
blockPos,
this.level().getBlockState(blockPos)));
.getChunkSource()
.chunkMap
.broadcast(
this,
new ClientboundBlockUpdatePacket(
blockPos,
this.level().getBlockState(blockPos)));
this.discard();
if (block instanceof Fallable) {
((Fallable) block)
.onLand(this.level(), blockPos, this.blockState, blockState, this);
.onLand(this.level(), blockPos, this.blockState, blockState, this);
}
} else if (this.dropItem
&& this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
&& this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
this.discard();
this.callOnBrokenAfterFall(block, blockPos);
this.spawnAtLocation(block);
}
} else {
this.discard();
if (this.dropItem
&& this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
&& this.level().getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
this.callOnBrokenAfterFall(block, blockPos);
this.spawnAtLocation(block);
}
Expand Down
Loading