Skip to content

Commit

Permalink
fix: Ensure single conduit graphs are initialised correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Feb 20, 2025
1 parent 306fcec commit e788845
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ private ConduitSavedData(Level level, CompoundTag nbt) {
ListTag graphObjectsTag = graphTag.getList(KEY_GRAPH_OBJECTS, Tag.TAG_COMPOUND);
ListTag graphConnectionsTag = graphTag.getList(KEY_GRAPH_CONNECTIONS, Tag.TAG_COMPOUND);

// Skip any graphs which have no objects in them, they should not have been
// saved.
if (graphObjectsTag.isEmpty()) {
// TODO: Warning or something?
continue;
}

List<ConduitGraphObject<?>> graphObjects = new ArrayList<>();
List<Pair<GraphObject<Mergeable.Dummy>, GraphObject<Mergeable.Dummy>>> connections = new ArrayList<>();

Expand All @@ -94,6 +101,10 @@ private ConduitSavedData(Level level, CompoundTag nbt) {
connections.add(new Pair<>(graphObjects.get(connectionTag.getInt("0")), graphObjects.get(connectionTag.getInt("1"))));
}

// Create a graph for the first object, in case it is a single-node graph
var firstGraphObject = graphObjects.get(0);
Graph.integrate(firstGraphObject, List.of());

for (ConduitGraphObject<?> graphObject : graphObjects) {
// Find neighbors
var neighbors = connections
Expand All @@ -108,9 +119,21 @@ private ConduitSavedData(Level level, CompoundTag nbt) {
}
}

// Get the graph from the loaded data
var firstGraphObject = graphObjects.get(0);
// Store the resulting graph in our network map.
var graph = firstGraphObject.getGraph();

// If the graph is null after linking all the objects together, something has
// gone really wrong.
// While we *should* maybe check that there isn't a graph in all places (in case
// of corruption and try to recover)
// it is likely best that we throw this as an error and deal with it once we
// have context for why this could happen (it shouldn't).
if (graph == null) {
EnderIO.LOGGER.error(
"Graph is null after loading a network. Please report this issue to Ender IO, loading cannot continue.");
throw new IllegalStateException("Graph was null after loading the conduit network");
}

networks.computeIfAbsent(value, ignored -> new ArrayList<>()).add(graph);
}
}
Expand Down

0 comments on commit e788845

Please sign in to comment.