From 39d4985113031e8c65b517da72609bd89e64678b Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Tue, 25 Jul 2017 00:51:30 -0600 Subject: [PATCH] Fixes #4437 Add checks to TransporterPathfinder to make sure the current node is able to emit to the side(s) we're about to check. --- .../transporter/TransporterPathfinder.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java b/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java index 9cd40e355..cac5bb129 100644 --- a/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java +++ b/src/main/java/mekanism/common/content/transporter/TransporterPathfinder.java @@ -446,6 +446,9 @@ public final class TransporterPathfinder } double maxSearchDistance = start.distanceTo(finalNode) * 2; + ArrayList directionsToCheck = new ArrayList<>(); + Coord4D[] neighbors = new Coord4D[EnumFacing.VALUES.length]; + TileEntity[] neighborEntities = new TileEntity[neighbors.length]; while(!openSet.isEmpty()) { @@ -469,13 +472,34 @@ public final class TransporterPathfinder openSet.remove(currentNode); closedSet.add(currentNode); + TileEntity currentNodeTile = currentNode.getTileEntity(worldObj); + ILogisticalTransporter currentNodeTransporter = null; + if(currentNodeTile.hasCapability(Capabilities.LOGISTICAL_TRANSPORTER_CAPABILITY, null)) + { + currentNodeTransporter = + CapabilityUtils.getCapability(currentNodeTile, Capabilities.LOGISTICAL_TRANSPORTER_CAPABILITY, null); + } + + directionsToCheck.clear(); for(EnumFacing direction : EnumFacing.VALUES) { Coord4D neighbor = currentNode.offset(direction); - - if(transportStack.canInsertToTransporter(neighbor.getTileEntity(worldObj), direction)) + neighbors[direction.ordinal()] = neighbor; + TileEntity neighborEntity = neighbor.getTileEntity(worldObj); + neighborEntities[direction.ordinal()] = neighborEntity; + if(currentNodeTransporter == null || currentNodeTransporter.canEmitTo(neighborEntity, direction)) { - TileEntity tile = neighbor.getTileEntity(worldObj); + directionsToCheck.add(direction); + } + } + + for(EnumFacing direction : directionsToCheck) + { + Coord4D neighbor = neighbors[direction.ordinal()]; + + if(transportStack.canInsertToTransporter(neighborEntities[direction.ordinal()], direction)) + { + TileEntity tile = neighborEntities[direction.ordinal()]; double tentativeG = gScore.get(currentNode) + CapabilityUtils.getCapability(tile, Capabilities.LOGISTICAL_TRANSPORTER_CAPABILITY, direction.getOpposite()).getCost(); if(closedSet.contains(neighbor)) @@ -494,7 +518,7 @@ public final class TransporterPathfinder openSet.add(neighbor); } } - else if(neighbor.equals(finalNode) && destChecker.isValid(transportStack, direction, neighbor.getTileEntity(worldObj))) + else if(neighbor.equals(finalNode) && destChecker.isValid(transportStack, direction, neighborEntities[direction.ordinal()])) { side = direction; results = reconstructPath(navMap, currentNode);