Skip to content

Commit

Permalink
nodes in wrong brick y level
Browse files Browse the repository at this point in the history
  • Loading branch information
Goby56 committed Aug 23, 2024
1 parent 65197dd commit 40db6c7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@
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;
import net.minecraft.util.math.Box;
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 {

@Override
public void beforeDebugRender(WorldRenderContext context) {
WakeHandler wakeHandler = WakeHandler.getInstance();
Map<Integer, Integer> nodeHeights = new HashMap<>();
Map<Integer, Integer> 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);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/goby56/wakes/simulation/Brick.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/goby56/wakes/simulation/QuadTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/goby56/wakes/simulation/WakeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/goby56/wakes/simulation/WakeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class WakeNode implements Position<WakeNode>, Age<WakeNode> {
public float t = 0;
public int floodLevel;

public Entity spawner;

//TODO MORE GENERALIZED CONSTRUCTOR
public WakeNode(Vec3d position, int initialStrength) {
this.initValues();
Expand Down

0 comments on commit 40db6c7

Please sign in to comment.