private bool FlowHorizontal(World world, Vector3i position, LiquidLevel level, IFillable currentFillable) { Vector3i horizontalPosition = position; var isHorStatic = false; var levelHorizontal = LiquidLevel.Eight; IFillable?horizontalFillable = null; foreach (Orientation orientation in Orientations.ShuffledStart(position)) { if (CheckNeighbor( currentFillable.AllowOutflow(world, position, orientation.ToBlockSide()), orientation.Offset(position), orientation.Opposite().ToBlockSide())) { return(true); } } if (horizontalPosition == position) { return(false); } SetLiquid(world, this, levelHorizontal + 1, isStatic: false, horizontalFillable, horizontalPosition); if (isHorStatic) { ScheduleTick(world, horizontalPosition); } bool hasRemaining = level != LiquidLevel.One; SetLiquid( world, hasRemaining ? this : None, hasRemaining ? level - 1 : LiquidLevel.Eight, !hasRemaining, currentFillable, position); if (hasRemaining) { ScheduleTick(world, position); } return(true); bool CheckNeighbor(bool outflowAllowed, Vector3i neighborPosition, BlockSide side) { (BlockInstance? blockNeighbor, LiquidInstance? liquidNeighbor) = world.GetContent(neighborPosition); if (!outflowAllowed || blockNeighbor?.Block is not IFillable neighborFillable || !neighborFillable.AllowInflow(world, neighborPosition, side, this)) { return(false); } bool isStatic = liquidNeighbor?.IsStatic ?? false; if (liquidNeighbor?.Liquid == None) { isStatic = true; Vector3i belowNeighborPosition = neighborPosition + FlowDirection; (BlockInstance? belowNeighborBlock, LiquidInstance? belowNeighborLiquid) = world.GetContent( belowNeighborPosition); if (belowNeighborLiquid?.Liquid == None && belowNeighborBlock?.Block is IFillable belowFillable && belowFillable.AllowInflow( world, belowNeighborPosition, Direction.EntrySide(), this) && neighborFillable.AllowOutflow( world, neighborPosition, Direction.ExitSide())) { SetLiquid(world, this, level, isStatic: false, belowFillable, belowNeighborPosition); ScheduleTick(world, belowNeighborPosition); SetLiquid(world, None, LiquidLevel.Eight, isStatic: true, currentFillable, position); } else { SetLiquid(world, this, LiquidLevel.One, isStatic: false, neighborFillable, neighborPosition); if (isStatic) { ScheduleTick(world, neighborPosition); } bool remaining = level != LiquidLevel.One; SetLiquid( world, remaining ? this : None, remaining ? level - 1 : LiquidLevel.Eight, !remaining, currentFillable, position); if (remaining) { ScheduleTick(world, position); } } return(true); } if (liquidNeighbor != null && liquidNeighbor.Liquid != this) { if (ContactManager.HandleContact( world, this.AsInstance(level), position, liquidNeighbor, neighborPosition)) { return(true); } } else if (liquidNeighbor?.Liquid == this && level > liquidNeighbor.Level && liquidNeighbor.Level < levelHorizontal) { bool allowsFlow = liquidNeighbor.Level != level - 1 || level == LiquidLevel.Eight && !IsAtSurface(world, position) && IsAtSurface(world, neighborPosition) || HasNeighborWithLevel(world, level - 2, neighborPosition) || HasNeighborWithEmpty(world, neighborPosition); if (!allowsFlow) { return(false); } levelHorizontal = liquidNeighbor.Level; horizontalPosition = neighborPosition; isHorStatic = isStatic; horizontalFillable = neighborFillable; } return(false); }