Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry picked Fix #8295: CPU IGridMultiblock returning null nodes (#8298) #8299

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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