Skip to content

Commit

Permalink
Fixed pipe issue with multiple machines at same pipe segment
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Apr 2, 2024
1 parent d2d92fe commit 0e3f58c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public BlockState getStateForNeighborUpdate(BlockState state, Direction directio
return normalPipeState;
}

if (!interfaceState.equals(state)) {
// reload connection when state has changed (e.g. machine added/removed)
GenericPipeInterfaceEntity.addNode(pos, true, interfaceState, getNetworkData((World) world));
}

return interfaceState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public GenericPipeInterfaceEntity(BlockEntityType<?> type, BlockPos pos, BlockSt
}

public static void addNode(BlockPos pos, boolean isInterface, BlockState newState, PipeNetworkData data) {
System.out.println("registering node: " + pos);
System.out.println("registering/updating node: " + pos);

data.pipes.add(pos);
if (isInterface) {
var connectedMachines = new HashSet<BlockPos>(1);
var connectedMachines = new HashSet<BlockPos>(6);
if (newState.get(GenericPipeConnectionBlock.INTERFACE_NORTH))
connectedMachines.add(pos.north());
if (newState.get(GenericPipeConnectionBlock.INTERFACE_SOUTH))
Expand All @@ -45,9 +45,9 @@ public static void addNode(BlockPos pos, boolean isInterface, BlockState newStat
if (newState.get(GenericPipeConnectionBlock.INTERFACE_DOWN))
connectedMachines.add(pos.down());

System.out.println(connectedMachines);

data.machineInterfaces.put(pos, connectedMachines);
} else {
data.machineInterfaces.remove(pos);
}

updateFromNode(pos, data);
Expand Down Expand Up @@ -88,8 +88,9 @@ private static void updateFromNode(BlockPos pos, PipeNetworkData data) {
var searchInstance = new FloodFillSearch(pos, data.pipes);
var foundNetwork = new HashSet<>(searchInstance.complete());
var foundMachines = findConnectedMachines(foundNetwork, data);

System.out.println("Nodes: " + foundNetwork.size() + " | " + foundNetwork);
System.out.println("Machines: " + foundMachines.size() + " | " + foundMachines);
System.out.println("Machines: " + foundMachines.size() + " | " + foundMachines.stream().map(elem -> elem.getLeft() + ":" + elem.getRight()).toList());

var netID = foundNetwork.hashCode();
data.pipeNetworks.put(netID, foundNetwork);
Expand All @@ -109,8 +110,6 @@ private static void updateFromNode(BlockPos pos, PipeNetworkData data) {
});

data.markDirty();

System.out.println("Total Networks: " + data.pipeNetworks.keySet().size());
}

private static Set<Pair<BlockPos, Direction>> findConnectedMachines(Set<BlockPos> network, PipeNetworkData data) {
Expand Down

0 comments on commit 0e3f58c

Please sign in to comment.