From 40db6c75e460576c11f71b190a45c5804e00893e Mon Sep 17 00:00:00 2001 From: Goby56 <60710855+Goby56@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:53:14 +0200 Subject: [PATCH] nodes in wrong brick y level --- .../java/com/goby56/wakes/debug/WakeDebugRenderer.java | 7 +++++++ src/main/java/com/goby56/wakes/simulation/Brick.java | 1 + src/main/java/com/goby56/wakes/simulation/QuadTree.java | 2 +- src/main/java/com/goby56/wakes/simulation/WakeHandler.java | 2 +- src/main/java/com/goby56/wakes/simulation/WakeNode.java | 2 ++ 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java b/src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java index 37b8d32..9e2aba8 100644 --- a/src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java +++ b/src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java @@ -4,6 +4,7 @@ import com.goby56.wakes.simulation.Brick; import com.goby56.wakes.simulation.WakeHandler; import com.goby56.wakes.simulation.WakeNode; +import kroppeb.stareval.function.Type; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.minecraft.client.render.debug.DebugRenderer; @@ -11,6 +12,8 @@ import net.minecraft.util.math.Vec3d; import java.awt.*; +import java.util.HashMap; +import java.util.Map; import java.util.Random; public class WakeDebugRenderer implements WorldRenderEvents.DebugRender { @@ -18,14 +21,18 @@ public class WakeDebugRenderer implements WorldRenderEvents.DebugRender { @Override public void beforeDebugRender(WorldRenderContext context) { WakeHandler wakeHandler = WakeHandler.getInstance(); + Map nodeHeights = new HashMap<>(); + Map brickHeights = new HashMap<>(); if (WakesClient.CONFIG_INSTANCE.drawDebugBoxes) { for (var node : wakeHandler.getVisible(context.frustum(), WakeNode.class)) { + nodeHeights.merge((int) node.height, 1, Integer::sum); Box box = new Box(node.x, node.height - 0.1f, node.z, node.x + 1, node.height - 0.2f, node.z + 1); DebugRenderer.drawBox(context.matrixStack(), context.consumers(), box.offset(context.camera().getPos().negate()), 1, 0, 1, 0.5f); } for (var brick : wakeHandler.getVisible(context.frustum(), Brick.class)) { + brickHeights.merge((int) brick.pos.y, 1, Integer::sum); Vec3d pos = brick.pos; Box box = new Box(pos.x, pos.y - 0.2f, pos.z, pos.x + brick.dim, pos.y - 0.3f, pos.z + brick.dim); var col = Color.getHSBColor(new Random(pos.hashCode()).nextFloat(), 1f, 1f).getRGBColorComponents(null); diff --git a/src/main/java/com/goby56/wakes/simulation/Brick.java b/src/main/java/com/goby56/wakes/simulation/Brick.java index c606ba6..024025d 100644 --- a/src/main/java/com/goby56/wakes/simulation/Brick.java +++ b/src/main/java/com/goby56/wakes/simulation/Brick.java @@ -113,6 +113,7 @@ public WakeNode get(int x, int z) { } public void insert(WakeNode node) { + if (Math.abs(node.height - this.pos.y) > 1f) System.out.printf("INSERTING %s IN WRONG BRICK (%f)\n", node, this.pos.y); int x = Math.floorMod(node.x, dim), z = Math.floorMod(node.z, dim); if (nodes[z][x] != null) { nodes[z][x].revive(node); diff --git a/src/main/java/com/goby56/wakes/simulation/QuadTree.java b/src/main/java/com/goby56/wakes/simulation/QuadTree.java index 6957e55..de17362 100644 --- a/src/main/java/com/goby56/wakes/simulation/QuadTree.java +++ b/src/main/java/com/goby56/wakes/simulation/QuadTree.java @@ -38,7 +38,7 @@ private boolean hasLeaf() { private void initLeaf() { if (depth >= MAX_DEPTH) { - this.brick = new Brick(bounds.x, yLevel, bounds.z, bounds.width); + this.brick = new Brick(bounds.x, this.yLevel, bounds.z, bounds.width); this.ROOT.updateAdjacency(this); } } diff --git a/src/main/java/com/goby56/wakes/simulation/WakeHandler.java b/src/main/java/com/goby56/wakes/simulation/WakeHandler.java index a6b9371..b55dd37 100644 --- a/src/main/java/com/goby56/wakes/simulation/WakeHandler.java +++ b/src/main/java/com/goby56/wakes/simulation/WakeHandler.java @@ -94,7 +94,7 @@ private int getArrayIndex(int height) { if (height < this.minY || height > this.maxY) { return -1; } - return height + Math.abs(this.minY); + return height - this.minY; } public static void scheduleResolutionChange(Resolution newRes) { diff --git a/src/main/java/com/goby56/wakes/simulation/WakeNode.java b/src/main/java/com/goby56/wakes/simulation/WakeNode.java index d123b9a..92b6159 100644 --- a/src/main/java/com/goby56/wakes/simulation/WakeNode.java +++ b/src/main/java/com/goby56/wakes/simulation/WakeNode.java @@ -42,6 +42,8 @@ public class WakeNode implements Position, Age { public float t = 0; public int floodLevel; + public Entity spawner; + //TODO MORE GENERALIZED CONSTRUCTOR public WakeNode(Vec3d position, int initialStrength) { this.initValues();