From 0056f064736ffc58081531e554ba6f7e907ded93 Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 4 Feb 2026 16:42:07 +0100 Subject: [PATCH] twice as many problems, half as much difficulty --- .../java/com/hbm/hrist/ConduitConnection.java | 18 +++++++ src/main/java/com/hbm/hrist/ConduitPiece.java | 50 +++++++++++++++++++ src/main/java/com/hbm/hrist/ConduitSpace.java | 10 ++-- src/main/java/com/hbm/hrist/PathNode.java | 17 ------- .../hbm/util/fauxpointtwelve/BlockPos.java | 16 ++++-- .../com/hbm/util/fauxpointtwelve/DimPos.java | 47 +++++++++++++++++ 6 files changed, 131 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/hbm/hrist/ConduitConnection.java create mode 100644 src/main/java/com/hbm/hrist/ConduitPiece.java delete mode 100644 src/main/java/com/hbm/hrist/PathNode.java create mode 100644 src/main/java/com/hbm/util/fauxpointtwelve/DimPos.java diff --git a/src/main/java/com/hbm/hrist/ConduitConnection.java b/src/main/java/com/hbm/hrist/ConduitConnection.java new file mode 100644 index 000000000..c21977013 --- /dev/null +++ b/src/main/java/com/hbm/hrist/ConduitConnection.java @@ -0,0 +1,18 @@ +package com.hbm.hrist; + +/** Generated out of multiple ConnectionDefinitions to form a straight segment, ends at a branch */ +public class ConduitConnection { + + protected boolean valid = true; + public ConduitConnection[] connectedTo = new ConduitConnection[2]; // a sausage always has two ends + public int stateKeepAlive; + public ConnectionStatus state = ConnectionStatus.OKAY; + + public boolean isValid() { return this.valid; } + public void invalidate() { this.valid = false; } + + public static enum ConnectionStatus { + OKAY, + BLOCKED + } +} diff --git a/src/main/java/com/hbm/hrist/ConduitPiece.java b/src/main/java/com/hbm/hrist/ConduitPiece.java new file mode 100644 index 000000000..5bd297bba --- /dev/null +++ b/src/main/java/com/hbm/hrist/ConduitPiece.java @@ -0,0 +1,50 @@ +package com.hbm.hrist; + +import com.hbm.util.fauxpointtwelve.BlockPos; + +// like a tile entity but without all the useless crap +public class ConduitPiece { + + protected boolean valid = true; + public ConnectionDefinition[] definitions; + public ConduitConnection[] liveConnections; + + public ConduitPiece(ConnectionDefinition... defs) { + definitions = defs; + for(ConnectionDefinition def : defs) def.withParent(this); + liveConnections = new ConduitConnection[defs.length]; + } + + public boolean isValid() { return this.valid; } + + // if a piece goes offline, the entire connection dies with it ad has to be recalculated out of the surviving pieces + public void invalidate() { + this.valid = false; + for(ConduitConnection con : this.liveConnections) { + if(con != null) con.invalidate(); + } + } + + /** Describes each branch or connecting line on a piece, building block and not a working instance */ + public static class ConnectionDefinition { + + public ConduitPiece parent; + public BlockPos[] connectors = new BlockPos[2]; + double distance; + + public ConnectionDefinition(BlockPos start, BlockPos end) { + this(start, end, start.distanceTo(end)); + } + + public ConnectionDefinition(BlockPos start, BlockPos end, double distance) { + this.connectors[0] = start; + this.connectors[1] = end; + this.distance = distance; + } + + public ConnectionDefinition withParent(ConduitPiece parent) { + this.parent = parent; + return this; + } + } +} diff --git a/src/main/java/com/hbm/hrist/ConduitSpace.java b/src/main/java/com/hbm/hrist/ConduitSpace.java index 536e0f23b..9abb0fa97 100644 --- a/src/main/java/com/hbm/hrist/ConduitSpace.java +++ b/src/main/java/com/hbm/hrist/ConduitSpace.java @@ -3,13 +3,11 @@ package com.hbm.hrist; import java.util.HashMap; import java.util.Map; -import net.minecraft.world.World; +import com.hbm.util.fauxpointtwelve.DimPos; +/// ROBUR PER UNITATEM /// public class ConduitSpace { - - public static Map worlds = new HashMap(); - public static class ConduitWorld { - - } + /** Maps conduit core pos to the actual conduit piece logical unit */ + public static Map pieces = new HashMap(); } diff --git a/src/main/java/com/hbm/hrist/PathNode.java b/src/main/java/com/hbm/hrist/PathNode.java deleted file mode 100644 index e09a339c6..000000000 --- a/src/main/java/com/hbm/hrist/PathNode.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.hbm.hrist; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class PathNode { - - // i suppose that's a tree now - public Map> inToOut = new HashMap(); - - public static class PathInfo { - - public PathNode leadsTo; - public double distance; - } -} diff --git a/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java b/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java index dfa363925..1315e728b 100644 --- a/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java +++ b/src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java @@ -9,9 +9,10 @@ import net.minecraftforge.common.util.ForgeDirection; */ public class BlockPos implements Cloneable { - private int x; - private int y; - private int z; + public static final int HASH_PRIME = 27644437; + protected int x; + protected int y; + protected int z; public BlockPos(int x, int y, int z) { this.x = x; @@ -27,6 +28,13 @@ public class BlockPos implements Cloneable { this((int)MathHelper.floor_double(x), (int)MathHelper.floor_double(y), (int)MathHelper.floor_double(z)); } + public double distanceTo(BlockPos pos) { + int dX = pos.x - x; + int dY = pos.y - y; + int dZ = pos.z - z; + return Math.sqrt(dX * dX + dY * dY + dZ * dZ); + } + /** Basically a setter for the coords. Violates the "muh unmutability" horseshit I don't care about and * lets me re-use the same instance for a ton of checks. RAM has priority over stupid religious bullshit. */ public BlockPos mutate(int x, int y, int z) { @@ -89,7 +97,7 @@ public class BlockPos implements Cloneable { } public static int getIdentity(int x, int y, int z) { - return (y + z * 27644437) * 27644437 + x; + return (y + z * HASH_PRIME) * HASH_PRIME + x; } @Override diff --git a/src/main/java/com/hbm/util/fauxpointtwelve/DimPos.java b/src/main/java/com/hbm/util/fauxpointtwelve/DimPos.java new file mode 100644 index 000000000..ef60d5551 --- /dev/null +++ b/src/main/java/com/hbm/util/fauxpointtwelve/DimPos.java @@ -0,0 +1,47 @@ +package com.hbm.util.fauxpointtwelve; + +/** BlockPos + dimension */ +public class DimPos extends BlockPos { + + protected int dim; + + public DimPos(int x, int y, int z, int dim) { + super(x, y, z); + this.dim = dim; + } + + public int getDim() { + return this.dim; + } + @Override + public int hashCode() { + return getIdentity(this.getX(), this.getY(), this.getZ(), this.getDim()); + } + + public static int getIdentity(int x, int y, int z, int dim) { + return ((y + dim * HASH_PRIME) + z * HASH_PRIME) * HASH_PRIME + x; // yeah fuck it why not + } + + @Override + public boolean equals(Object toCompare) { + if(this == toCompare) { + return true; + } else if(!(toCompare instanceof DimPos)) { + return false; + } else { + DimPos pos = (DimPos) toCompare; + if(this.getX() != pos.getX()) return false; + if(this.getY() != pos.getY()) return false; + if(this.getZ() != pos.getZ()) return false; + return this.getDim() == pos.getDim(); + } + } + + @Override + public DimPos clone() { + try { + return (DimPos) super.clone(); + } catch(Exception x) { } + return null; + } +}