twice as many problems, half as much difficulty

This commit is contained in:
Boblet 2026-02-04 16:42:07 +01:00
parent e287412332
commit 0056f06473
6 changed files with 131 additions and 27 deletions

View File

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

View File

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

View File

@ -3,13 +3,11 @@ package com.hbm.hrist;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.world.World; import com.hbm.util.fauxpointtwelve.DimPos;
/// ROBUR PER UNITATEM ///
public class ConduitSpace { public class ConduitSpace {
public static Map<World, ConduitWorld> worlds = new HashMap();
public static class ConduitWorld { /** Maps conduit core pos to the actual conduit piece logical unit */
public static Map<DimPos, ConduitPiece> pieces = new HashMap();
}
} }

View File

@ -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<PathInfo, List<PathInfo>> inToOut = new HashMap();
public static class PathInfo {
public PathNode leadsTo;
public double distance;
}
}

View File

@ -9,9 +9,10 @@ import net.minecraftforge.common.util.ForgeDirection;
*/ */
public class BlockPos implements Cloneable { public class BlockPos implements Cloneable {
private int x; public static final int HASH_PRIME = 27644437;
private int y; protected int x;
private int z; protected int y;
protected int z;
public BlockPos(int x, int y, int z) { public BlockPos(int x, int y, int z) {
this.x = x; 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)); 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 /** 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. */ * 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) { 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) { 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 @Override

View File

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