From 7b6467fb3758bd84c1250d3935ecaa528bf7c076 Mon Sep 17 00:00:00 2001 From: Boblet Date: Tue, 2 Apr 2024 14:41:26 +0200 Subject: [PATCH] my head hurts --- .../java/api/hbm/energymk2/Nodespace.java | 44 +++++++++++++++++-- .../loader/WavefrontObjDisplayList.java | 16 ++----- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/main/java/api/hbm/energymk2/Nodespace.java b/src/main/java/api/hbm/energymk2/Nodespace.java index 82b431742..891076ecf 100644 --- a/src/main/java/api/hbm/energymk2/Nodespace.java +++ b/src/main/java/api/hbm/energymk2/Nodespace.java @@ -39,6 +39,7 @@ public class Nodespace { if(node != null) worlds.get(world).popNode(node); } + /** Goes over each node and manages connections */ public static void updateNodespace() { for(World world : MinecraftServer.getServer().worldServers) { @@ -46,15 +47,46 @@ public class Nodespace { for(Entry entry : nodes.nodes.entrySet()) { PowerNode node = entry.getValue(); - if(node.net == null || !node.net.isValid()) { - tryConnectNode(world, node); - } + checkNodeConnection(world, node); } } } - private static void tryConnectNode(World world, PowerNode node) { + /** Goes over each connection point of the given node, tries to find neighbor nodes and to join networks with them */ + private static void checkNodeConnection(World world, PowerNode node) { + for(DirPos con : node.connections) { + + PowerNode conNode = getNode(world, con.getX() + con.getDir().offsetX, con.getY() + con.getDir().offsetY, con.getZ() + con.getDir().offsetZ); // get whatever neighbor node intersects with that connection + + if(conNode != null) { // if there is a node at that place + + if(conNode.hasValidNet() && conNode.net == node.net) continue; // if the net is valid and both nodes have the same net, skip + + for(DirPos revCon : conNode.connections) { // check if neighbor node also has a valid reverse connection + + // god i hope i didn't fuck this up my brain is hurting already + if(revCon.getX() - revCon.getDir().offsetX == con.getX() && revCon.getY() - revCon.getDir().offsetY == con.getY() && revCon.getZ() - revCon.getDir().offsetZ == con.getZ() && revCon.getDir() == con.getDir().getOpposite()) { + connectToNode(node, conNode); + break; + } + } + } + } + + if(node.net == null || !node.net.isValid()) new PowerNetMK2().joinLink(node); + } + + /** Links two nodes with different or potentially no networks */ + private static void connectToNode(PowerNode origin, PowerNode connection) { + + if(origin.hasValidNet() && connection.hasValidNet()) { // both nodes have nets, but the nets are different (previous assumption), join networks + origin.net.joinNetworks(connection.net); + } else if(!origin.hasValidNet() && connection.hasValidNet()) { // origin has no net, connection does, have origin join connection's net + connection.net.joinLink(origin); + } else if(origin.hasValidNet() && !connection.hasValidNet()) { // ...and vice versa + origin.net.joinLink(connection); + } } public static class NodeWorld { @@ -99,5 +131,9 @@ public class Nodespace { this.connections = connections; return this; } + + public boolean hasValidNet() { + return this.net != null && this.net.isValid(); + } } } diff --git a/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java b/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java index 79f33e16f..99eef4360 100644 --- a/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java +++ b/src/main/java/com/hbm/render/loader/WavefrontObjDisplayList.java @@ -56,7 +56,7 @@ public class WavefrontObjDisplayList implements IModelCustom { @Override public void renderAll() { for(Pair p : nameToCallList) - callList(p.getRight()); + GL11.glCallList(p.getRight()); } @Override @@ -64,7 +64,7 @@ public class WavefrontObjDisplayList implements IModelCustom { for(Pair p : nameToCallList){ for(String name : groupNames){ if(p.getLeft().equalsIgnoreCase(name)){ - callList(p.getRight()); + GL11.glCallList(p.getRight()); break; } } @@ -75,7 +75,7 @@ public class WavefrontObjDisplayList implements IModelCustom { public void renderPart(String partName) { for(Pair p : nameToCallList){ if(p.getLeft().equalsIgnoreCase(partName)){ - callList(p.getRight()); + GL11.glCallList(p.getRight()); } } } @@ -91,16 +91,8 @@ public class WavefrontObjDisplayList implements IModelCustom { } } if(!skip){ - callList(p.getRight()); + GL11.glCallList(p.getRight()); } } } - - protected static void callList(int i) { - boolean prevBlend = GL11.glIsEnabled(GL11.GL_BLEND); - GL11.glCallList(i); - boolean newBlend = GL11.glIsEnabled(GL11.GL_BLEND); - if(prevBlend && !newBlend) GL11.glEnable(GL11.GL_BLEND); - if(!prevBlend && newBlend) GL11.glDisable(GL11.GL_BLEND); - } } \ No newline at end of file