Skip to content

Commit

Permalink
fix: fluid flow using incorrect direction in bfs
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Jun 19, 2024
1 parent 1f97499 commit dad1367
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ private DirectionConstants() {}
public static final Direction[] ALL = Direction.values();
public static final Direction[] VERTICAL = {Direction.DOWN, Direction.UP};
public static final Direction[] HORIZONTAL = {Direction.WEST, Direction.EAST, Direction.NORTH, Direction.SOUTH};
public static final byte[] HORIZONTAL_OPPOSITE_INDICES = {1, 0, 3, 2};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
Expand Down Expand Up @@ -68,6 +69,9 @@ public abstract class FlowableFluidMixin {
protected abstract boolean receivesFlow(Direction face, BlockView world, BlockPos pos, BlockState state, BlockPos fromPos, BlockState fromState);


@Shadow
protected abstract void flow(WorldAccess world, BlockPos pos, BlockState state, Direction direction, FluidState fluidState);

@Unique
private static int getNumIndicesFromRadius(int radius) {
return (radius + 1) * (2 * radius + 1);
Expand Down Expand Up @@ -218,8 +222,10 @@ private void calculateComplexFluidFlowDirections(World world, BlockPos startPos,

for (int j = 0; j < DirectionConstants.HORIZONTAL.length; j++) {
Direction flowDirection = DirectionConstants.HORIZONTAL[j];
if (((currentInfo >> 4) & (1 << ((j + 2) % 4))) != (byte) 0) {
//In this direction is one of the disallowed directions, +2%4 to get opposite direction index
int oppositeDirection = DirectionConstants.HORIZONTAL_OPPOSITE_INDICES[j];

if (((currentInfo >> 4) & (1 << oppositeDirection)) != (byte) 0) {
//In this direction is one of the disallowed directions
continue;
}
BlockPos flowTargetPos = currentPos.offset(flowDirection);
Expand Down

0 comments on commit dad1367

Please sign in to comment.