Skip to content

Commit

Permalink
fixed bugs about excepted block state change while fluids flow throug…
Browse files Browse the repository at this point in the history
…h connectable blocks such as fences or iron bars
  • Loading branch information
PajangForever committed Aug 12, 2024
1 parent b09541a commit 51b300c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 101 deletions.
38 changes: 25 additions & 13 deletions src/main/java/name/synchro/fluids/FluidUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,31 @@ public static FluidState getFluidStateInRenderedChunk(List<PalettedContainer<Flu
}

public static boolean worldSetFluidState(World world, BlockPos pos, FluidState fluidState, int flags, int maxDepth) {
BlockState blockState = world.getBlockState(pos);
if (blockState.isAir() || blockState.getBlock() instanceof FluidBlock){
if (fluidState.isEmpty()) return world.setBlockState(pos, Blocks.AIR.getDefaultState(), flags, maxDepth);
else return world.setBlockState(pos, fluidState.getBlockState(), flags, maxDepth);
BlockState originalBlockState = world.getBlockState(pos);
BlockState finalBlockState = originalBlockState;
boolean skipSetFluidState = false;
if (originalBlockState.isAir() || originalBlockState.getBlock() instanceof FluidBlock){
if (fluidState.isEmpty()) {
finalBlockState = Blocks.AIR.getDefaultState();
}
else {
finalBlockState = fluidState.getBlockState();
}
skipSetFluidState = true;
}
else if (blockState.getBlock() instanceof Waterloggable){
else if (originalBlockState.getBlock() instanceof Waterloggable){
if (fluidState.isEqualAndStill(Fluids.WATER)){
return world.setBlockState(pos, blockState.with(Properties.WATERLOGGED, true), flags, maxDepth);
finalBlockState = originalBlockState.with(Properties.WATERLOGGED, true);
skipSetFluidState = true;
}
else if (blockState.get(Properties.WATERLOGGED)){
world.setBlockState(pos, blockState.with(Properties.WATERLOGGED, false));
else if (originalBlockState.get(Properties.WATERLOGGED)){
finalBlockState = originalBlockState.with(Properties.WATERLOGGED, false);
world.setBlockState(pos, finalBlockState);
}
}
if (skipSetFluidState){
return world.setBlockState(pos, finalBlockState);
}
if (world.isOutOfHeightLimit(pos)) {
return false;
} else if (!world.isClient && world.isDebugWorld()) {
Expand All @@ -178,16 +190,16 @@ else if (blockState.get(Properties.WATERLOGGED)){
if ((flags & Block.NOTIFY_LISTENERS) != 0
&& (!world.isClient() || (flags & Block.NO_REDRAW) == 0)
&& (world.isClient() || worldChunk.getLevelType() != null && worldChunk.getLevelType().isAfter(ChunkLevelType.BLOCK_TICKING))) {
world.updateListeners(pos, replacedState.getBlockState(), fluidState.getBlockState(), flags);
world.updateListeners(pos, originalBlockState, finalBlockState, flags);
}

if ((flags & Block.NOTIFY_NEIGHBORS) != 0) {
world.updateNeighbors(pos, replacedState.getBlockState().getBlock());
world.updateNeighbors(pos, finalBlockState.getBlock());
}

if ((flags & Block.FORCE_STATE) == 0 && maxDepth > 0) {
int i = flags & ~(Block.NOTIFY_NEIGHBORS | Block.SKIP_DROPS);
fluidState.getBlockState().updateNeighbors(world, pos, i, maxDepth - 1);
finalBlockState.updateNeighbors(world, pos, i, maxDepth - 1);
}
world.onBlockChanged(pos, replacedState.getBlockState(), placedState.getBlockState());
}
Expand Down Expand Up @@ -460,10 +472,10 @@ public static void fluidReact(World world, BlockPos pos, BlockState blockState){
// ModDataContainer<?> container = ((ModDataManager.Provider)world).synchro$getModDataManager().getContents().get(FluidReactionData.ID);
// if (container instanceof FluidReactionData fluidReactionData){
// Map<Long, FluidReaction> map = fluidReactionData.data();
// long key = FluidReactionData.longKey(fluidState.getFluid(), blockState.getBlock());
// long key = FluidReactionData.longKey(fluidState.getFluid(), originalBlockState.getBlock());
// FluidReaction entry = map.get(key);
// if (entry == null) return;
// if (!entry.match(fluidState, blockState)) return;
// if (!entry.match(fluidState, originalBlockState)) return;
// for (LocationAction action: entry.actions()){
// action.act(world, pos);
// }
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 51b300c

Please sign in to comment.