diff --git a/src/main/java/mekanism/common/content/network/InventoryNetwork.java b/src/main/java/mekanism/common/content/network/InventoryNetwork.java index b515123ef02..5d88ac6feff 100644 --- a/src/main/java/mekanism/common/content/network/InventoryNetwork.java +++ b/src/main/java/mekanism/common/content/network/InventoryNetwork.java @@ -15,6 +15,7 @@ import mekanism.common.content.network.transmitter.LogisticalTransporterBase; import mekanism.common.content.transporter.PathfinderCache; import mekanism.common.content.transporter.TransporterManager; +import mekanism.common.content.transporter.TransporterPathfinder; import mekanism.common.content.transporter.TransporterStack; import mekanism.common.lib.inventory.TransitRequest; import mekanism.common.lib.inventory.TransitRequest.TransitResponse; @@ -42,7 +43,7 @@ public InventoryNetwork(Collection networks) { } public List calculateAcceptors(TransitRequest request, TransporterStack stack, Long2ObjectMap chunkMap, - Map> additionalFlowingStacks) { + Map> additionalFlowingStacks, LogisticalTransporterBase start) { List toReturn = new ArrayList<>(); for (Long2ObjectMap.Entry> entry : acceptorCache.getAcceptorEntrySet()) { BlockPos pos = BlockPos.of(entry.getLongKey()); @@ -53,6 +54,10 @@ public List calculateAcceptors(TransitRequest request, Transporter for (Map.Entry acceptorEntry : entry.getValue().entrySet()) { IItemHandler handler = acceptorEntry.getValue(); Direction side = acceptorEntry.getKey(); + PathfinderCache.CachedPath cachedPath = PathfinderCache.getSingleCache(start, pos, side); + if (cachedPath != null && !TransporterPathfinder.checkPath(this, cachedPath.path(), stack)) { + continue;//invalid path, no need to simulate + } //TODO: Figure out how we want to best handle the color check, as without doing it here we don't // actually need to even query the TE if (acceptor instanceof ISideConfiguration config) { diff --git a/src/main/java/mekanism/common/content/transporter/PathfinderCache.java b/src/main/java/mekanism/common/content/transporter/PathfinderCache.java index 8b33fefb05a..3edbeb85f85 100644 --- a/src/main/java/mekanism/common/content/transporter/PathfinderCache.java +++ b/src/main/java/mekanism/common/content/transporter/PathfinderCache.java @@ -3,7 +3,6 @@ import it.unimi.dsi.fastutil.longs.LongList; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -53,6 +52,17 @@ public static CachedPath getCache(LogisticalTransporterBase start, BlockPos end, return ret; } + @Nullable + public static CachedPath getSingleCache(LogisticalTransporterBase start, BlockPos end, Direction side) { + UUID uuid = start.getTransmitterNetwork().getUUID(); + Map pathMap = cachedPaths.get(uuid); + if (pathMap != null) { + BlockPos startPos = start.getBlockPos(); + return pathMap.get(new PathData(startPos, end, side)); + } + return null; + } + public static void reset() { cachedPaths.clear(); } diff --git a/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java b/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java index a53f8bb4e5b..73440aea979 100644 --- a/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java +++ b/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java @@ -52,7 +52,7 @@ private static List getPaths(LogisticalTransporterBase start, Trans return Collections.emptyList(); } Long2ObjectMap chunkMap = new Long2ObjectOpenHashMap<>(); - List acceptors = network.calculateAcceptors(request, stack, chunkMap, additionalFlowingStacks); + List acceptors = network.calculateAcceptors(request, stack, chunkMap, additionalFlowingStacks, start); List paths = new ArrayList<>(); for (AcceptorData data : acceptors) { Destination path = getPath(network, data, start, stack, min, chunkMap); @@ -64,7 +64,7 @@ private static List getPaths(LogisticalTransporterBase start, Trans return paths; } - private static boolean checkPath(InventoryNetwork network, LongList path, TransporterStack stack) { + public static boolean checkPath(InventoryNetwork network, LongList path, TransporterStack stack) { for (int i = path.size() - 1; i > 0; i--) { LogisticalTransporterBase transmitter = network.getTransmitter(path.getLong(i)); if (transmitter == null) {