From 6d2340957dac62165c779fd3a56566594b6906d4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 11 Feb 2015 21:32:25 -0700 Subject: [PATCH] Fix remaining issues with fluid dynamics --- TrueCraft.Core/Logic/Blocks/FluidBlock.cs | 26 +++++++++++++++++------ TrueCraft.Core/Logic/Blocks/LavaBlock.cs | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/TrueCraft.Core/Logic/Blocks/FluidBlock.cs b/TrueCraft.Core/Logic/Blocks/FluidBlock.cs index 6fe61e2..4cc8f7c 100644 --- a/TrueCraft.Core/Logic/Blocks/FluidBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/FluidBlock.cs @@ -36,12 +36,14 @@ namespace TrueCraft.Core.Logic.Blocks protected abstract byte FlowingID { get; } protected abstract byte StillID { get; } + protected virtual bool AllowSourceCreation { get { return true; } } + private static readonly Coordinates3D[] Neighbors = { - Coordinates3D.Left, - Coordinates3D.Right, - Coordinates3D.Forwards, - Coordinates3D.Backwards + Coordinates3D.North, + Coordinates3D.South, + Coordinates3D.East, + Coordinates3D.West }; /// @@ -93,7 +95,7 @@ namespace TrueCraft.Core.Logic.Blocks private void AutomataUpdate(IMultiplayerServer server, IWorld world, Coordinates3D coords) { - if (world.GetBlockID(coords) != ID) + if (world.GetBlockID(coords) != FlowingID && world.GetBlockID(coords) != StillID) return; server.BlockUpdatesEnabled = false; var again = DoAutomata(server, world, coords); @@ -183,7 +185,7 @@ namespace TrueCraft.Core.Logic.Blocks neighboringSourceBlocks++; } } - if (neighboringSourceBlocks >= 2) + if (neighboringSourceBlocks >= 2 && AllowSourceCreation) currentLevel = 0; if (highestNeighboringFluid > 0) currentLevel = (byte)(highestNeighboringFluid + 1); @@ -278,6 +280,18 @@ namespace TrueCraft.Core.Logic.Blocks outwardFlow.Add(new LiquidFlow(zCoordinateCheck, (byte)(currentLevel + 1))); } } + + // Occasionally, there are scenarios where the nearest candidate hole is not acceptable, but + // there is space immediately next to the block. We should fill that space. + if (outwardFlow.Count == 0 && blockBelow.ID != FlowingID && blockBelow.ID != StillID) + { + for (int i = 0; i < Neighbors.Length; i++) + { + var b = world.BlockRepository.GetBlockProvider(world.GetBlockID(coords + Neighbors[i])); + if (!b.Opaque && b.ID != StillID && b.ID != FlowingID) + outwardFlow.Add(new LiquidFlow(Neighbors[i] + coords, (byte)(currentLevel + 1))); + } + } } return outwardFlow.ToArray(); } diff --git a/TrueCraft.Core/Logic/Blocks/LavaBlock.cs b/TrueCraft.Core/Logic/Blocks/LavaBlock.cs index 11eac8b..6f46bed 100644 --- a/TrueCraft.Core/Logic/Blocks/LavaBlock.cs +++ b/TrueCraft.Core/Logic/Blocks/LavaBlock.cs @@ -33,6 +33,8 @@ namespace TrueCraft.Core.Logic.Blocks public override string DisplayName { get { return "Lava"; } } + protected override bool AllowSourceCreation { get { return false; } } + protected override double SecondsBetweenUpdates { get { return 2; } } private byte _MaximumFluidDepletion { get; set; }