/// <summary> /// Get the flow as a direction vector. /// </summary> public static Vector3i Direction(this VerticalFlow flow) { return(flow switch { VerticalFlow.Upwards => (0, 1, 0), VerticalFlow.Static => (0, 0, 0), VerticalFlow.Downwards => (0, -1, 0), _ => (0, 0, 0) });
private bool FlowVertical(World world, Vector3i position, IFillable?currentFillable, LiquidLevel level, VerticalFlow flow, bool handleContact, out int remaining) { (BlockInstance? blockVertical, LiquidInstance? liquidVertical) = world.GetContent( position + flow.Direction()); if (blockVertical?.Block is IFillable verticalFillable && verticalFillable.AllowInflow( world, position + flow.Direction(), flow.EntrySide(), this) && (currentFillable?.AllowOutflow(world, position, flow.ExitSide()) ?? true)) { if (liquidVertical?.Liquid == None) { SetLiquid(world, this, level, isStatic: false, verticalFillable, position + flow.Direction()); SetLiquid(world, None, LiquidLevel.Eight, isStatic: true, currentFillable, position); ScheduleTick(world, position + flow.Direction()); remaining = -1; return(true); } if (liquidVertical?.Liquid == this) { if (liquidVertical.Level == LiquidLevel.Eight) { remaining = (int)level; return(false); } int volume = LiquidLevel.Eight - liquidVertical.Level - 1; if (volume >= (int)level) { SetLiquid( world, this, liquidVertical.Level + (int)level + 1, isStatic: false, verticalFillable, position + flow.Direction()); SetLiquid(world, None, LiquidLevel.Eight, isStatic: true, currentFillable, position); remaining = -1; } else { SetLiquid( world, this, LiquidLevel.Eight, isStatic: false, verticalFillable, position + flow.Direction()); SetLiquid(world, this, level - volume - 1, isStatic: false, currentFillable, position); remaining = (int)(level - volume - 1); ScheduleTick(world, position); } if (liquidVertical.IsStatic) { ScheduleTick(world, position + flow.Direction()); } return(true); } if (handleContact && liquidVertical != null) { remaining = (int)level; return(ContactManager.HandleContact( world, this.AsInstance(level), position, liquidVertical, position + flow.Direction())); } } remaining = (int)level; return(false); }