2 Commits

Author SHA1 Message Date
4220e94e38 improved overwrite 2025-06-28 14:35:16 +02:00
b0b5e95eda adjusted liquid behavior 2025-05-25 13:12:26 +02:00
3 changed files with 14 additions and 7 deletions

View File

@@ -69,15 +69,16 @@ public class Chunk {
return;
}
// check if not empty and overwrite not allowed:
if (!Elements[x,y].IsEmpty() && !Main.Instance.AllowOverwrite)
return;
else if (!Elements[x,y].IsEmpty()) {
Elements[x, y].Chunk.RemoveFromChunk(Elements[x, y]);
}
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;
}
Elements[x, y].Chunk.RemoveFromChunk(Elements[x, y]);
Elements[x, y] = o as Element;
Elements[x, y].Active = true;
}

View File

@@ -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;

View File

@@ -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))