From e8193ba5787a980b65b217dca1a15eb32cebbf81 Mon Sep 17 00:00:00 2001 From: Bruno Ploumhans <13494793+Technici4n@users.noreply.github.com> Date: Sun, 22 Dec 2024 21:17:50 +0100 Subject: [PATCH] Fix #8295: CPU IGridMultiblock returning null nodes (#8298) Confirmed to be an issue with our CPUs too. Going for the easy fix for now. (cherry picked from commit 5712d726882183bd1d83857f53004b970f11fb84) --- .../blockentity/crafting/CraftingBlockEntity.java | 15 ++++++++++++--- .../appeng/me/pathfinding/PathingCalculation.java | 12 +++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java b/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java index c5639290481..dda7b18ed91 100644 --- a/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java +++ b/src/main/java/appeng/blockentity/crafting/CraftingBlockEntity.java @@ -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; @@ -331,7 +329,18 @@ private Iterator getMultiblockNodes() { if (this.getCluster() == null) { return new ChainedIterator<>(); } - return Iterators.transform(this.getCluster().getBlockEntities(), CraftingBlockEntity::getGridNode); + var nodes = new ArrayList(); + 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 diff --git a/src/main/java/appeng/me/pathfinding/PathingCalculation.java b/src/main/java/appeng/me/pathfinding/PathingCalculation.java index 56c23fa849c..0cfa2546225 100644 --- a/src/main/java/appeng/me/pathfinding/PathingCalculation.java +++ b/src/main/java/appeng/me/pathfinding/PathingCalculation.java @@ -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; @@ -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. @@ -152,7 +157,12 @@ private void processQueue(Queue 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); } }