Skip to content

Commit 5712d72

Browse files
authored
Fix #8295: CPU IGridMultiblock returning null nodes (#8298)
Confirmed to be an issue with our CPUs too. Going for the easy fix for now.
1 parent 35cc2dc commit 5712d72

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import java.util.Iterator;
2424
import java.util.Set;
2525

26-
import com.google.common.collect.Iterators;
27-
2826
import net.minecraft.Util;
2927
import net.minecraft.core.BlockPos;
3028
import net.minecraft.core.Direction;
@@ -332,7 +330,18 @@ private Iterator<IGridNode> getMultiblockNodes() {
332330
if (this.getCluster() == null) {
333331
return new ChainedIterator<>();
334332
}
335-
return Iterators.transform(this.getCluster().getBlockEntities(), CraftingBlockEntity::getGridNode);
333+
var nodes = new ArrayList<IGridNode>();
334+
var it = this.getCluster().getBlockEntities();
335+
while (it.hasNext()) {
336+
var node = it.next().getGridNode();
337+
if (node != null) {
338+
// We might have built the multiblock before all nodes have been initialized.
339+
// As a quick fix just ignore null nodes, which matches previous pathing behavior.
340+
// See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/8295
341+
nodes.add(node);
342+
}
343+
}
344+
return nodes.iterator();
336345
}
337346

338347
@Override

src/main/java/appeng/me/pathfinding/PathingCalculation.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
import java.util.Queue;
2626
import java.util.Set;
2727

28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
2831
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
2932

3033
import appeng.api.networking.GridFlags;
@@ -46,6 +49,8 @@
4649
* Second, a DFS is performed to propagate the channel count upwards.
4750
*/
4851
public class PathingCalculation {
52+
private static final Logger LOG = LoggerFactory.getLogger(PathingCalculation.class);
53+
4954
private final IGrid grid;
5055
/**
5156
* Path items that are part of a multiblock that was already granted a channel.
@@ -152,7 +157,12 @@ private void processQueue(Queue<IPathItem> oldOpen, int queueIndex) {
152157
var oni = multiblock.getMultiblockNodes();
153158
while (oni.hasNext()) {
154159
final IGridNode otherNodes = oni.next();
155-
if (otherNodes != pi) {
160+
if (otherNodes == null) {
161+
// Only a log for now until addons are fixed too. See
162+
// https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/8295
163+
LOG.error("Skipping null node returned by grid multiblock node {}",
164+
multiblock);
165+
} else if (otherNodes != pi) {
156166
this.multiblocksWithChannel.add((GridNode) otherNodes);
157167
}
158168
}

0 commit comments

Comments
 (0)