Skip to content

Commit

Permalink
Cherry picked Fix #8295: CPU IGridMultiblock returning null nodes (#8298
Browse files Browse the repository at this point in the history
) (#8299)

(cherry picked from commit 5712d72)

Co-authored-by: Bruno Ploumhans <[email protected]>
  • Loading branch information
Aresiel and Technici4n authored Dec 22, 2024
1 parent b6c4fe3 commit dd4c67d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.Iterator;
import java.util.Set;

import com.google.common.collect.Iterators;

import net.minecraft.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -331,7 +329,18 @@ private Iterator<IGridNode> getMultiblockNodes() {
if (this.getCluster() == null) {
return new ChainedIterator<>();
}
return Iterators.transform(this.getCluster().getBlockEntities(), CraftingBlockEntity::getGridNode);
var nodes = new ArrayList<IGridNode>();
var it = this.getCluster().getBlockEntities();
while (it.hasNext()) {
var node = it.next().getGridNode();
if (node != null) {
// We might have built the multiblock before all nodes have been initialized.
// As a quick fix just ignore null nodes, which matches previous pathing behavior.
// See https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/8295
nodes.add(node);
}
}
return nodes.iterator();
}

@Override
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/appeng/me/pathfinding/PathingCalculation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.util.Queue;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;

import appeng.api.networking.GridFlags;
Expand All @@ -46,6 +49,8 @@
* Second, a DFS is performed to propagate the channel count upwards.
*/
public class PathingCalculation {
private static final Logger LOG = LoggerFactory.getLogger(PathingCalculation.class);

private final IGrid grid;
/**
* Path items that are part of a multiblock that was already granted a channel.
Expand Down Expand Up @@ -152,7 +157,12 @@ private void processQueue(Queue<IPathItem> oldOpen, int queueIndex) {
var oni = multiblock.getMultiblockNodes();
while (oni.hasNext()) {
final IGridNode otherNodes = oni.next();
if (otherNodes != pi) {
if (otherNodes == null) {
// Only a log for now until addons are fixed too. See
// https://github.com/AppliedEnergistics/Applied-Energistics-2/issues/8295
LOG.error("Skipping null node returned by grid multiblock node {}",
multiblock);
} else if (otherNodes != pi) {
this.multiblocksWithChannel.add((GridNode) otherNodes);
}
}
Expand Down

0 comments on commit dd4c67d

Please sign in to comment.