From b0b5e95edaad796dd039f8125d16c70995ac33e0 Mon Sep 17 00:00:00 2001 From: rogo Date: Sun, 25 May 2025 13:12:26 +0200 Subject: [PATCH] adjusted liquid behavior --- Scripts/Chunk.cs | 6 +++--- Scripts/Elements/Element.cs | 2 +- Scripts/Elements/Liquid.cs | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Scripts/Chunk.cs b/Scripts/Chunk.cs index 7f175aa..a9c0a17 100644 --- a/Scripts/Chunk.cs +++ b/Scripts/Chunk.cs @@ -69,14 +69,14 @@ public class Chunk { return; } - Type type = typeof(T); - object o = Activator.CreateInstance(type, x, y, this); - // check if not empty and overwrite not allowed: if (!Elements[x,y].IsEmpty() && !Main.Instance.AllowOverwrite) { return; } + Type type = typeof(T); + object o = Activator.CreateInstance(type, x, y, this); + Elements[x, y].Chunk.RemoveFromChunk(Elements[x, y]); Elements[x, y] = o as Element; Elements[x, y].Active = true; diff --git a/Scripts/Elements/Element.cs b/Scripts/Elements/Element.cs index b4a2029..4933735 100644 --- a/Scripts/Elements/Element.cs +++ b/Scripts/Elements/Element.cs @@ -31,7 +31,7 @@ public class Element{ Chunk.SetElementActive(this, Active); } - public Element(int x, int y, Chunk chunk) { + public Element(int x, int y, Chunk chunk, bool active = true) { Position.X = x; Position.Y = y; Chunk = chunk; diff --git a/Scripts/Elements/Liquid.cs b/Scripts/Elements/Liquid.cs index d7b18aa..7c9ffd4 100644 --- a/Scripts/Elements/Liquid.cs +++ b/Scripts/Elements/Liquid.cs @@ -24,11 +24,17 @@ public abstract class Liquid : Element { if (Chunk.IsEmpty(Position + Vector2I.Down)) Chunk.Swap(this, Position + Vector2I.Down); + else if (Chunk.IsEmpty(Position + randomDirection)) Chunk.Swap(this, Position + randomDirection); else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE)) Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE); + else if (Chunk.IsEmpty(Position + 1 * randomDirection)) + Chunk.Swap(this, Position + 1 * randomDirection); + else if (Chunk.IsEmpty(Position - 1 * randomDirection * VERTICAL_OPPOSITE)) + Chunk.Swap(this, Position - 1 * randomDirection * VERTICAL_OPPOSITE); + else if (Chunk.IsEmpty(Position + 2 * randomDirection)) Chunk.Swap(this, Position + 2 * randomDirection); else if (Chunk.IsEmpty(Position - 2 * randomDirection * VERTICAL_OPPOSITE))