Search in sources :

Example 56 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class TDDuctInformationProvider method acceptItem.

@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
    if (item instanceof LPTravelingItemServer) {
        LPTravelingItemServer serverItem = (LPTravelingItemServer) item;
        int id = serverItem.getInfo().destinationint;
        if (id == -1) {
            id = SimpleServiceLocator.routerManager.getIDforUUID(serverItem.getInfo().destinationUUID);
        }
        IRouter destination = SimpleServiceLocator.routerManager.getRouter(id);
        if (destination == null) {
            return false;
        }
        RouteCache routes = duct.getCache(true);
        Iterable<Route> paramIterable = routes.outputRoutes;
        Route route = null;
        Object cache = null;
        Triplet<Integer, ItemIdentifier, Boolean> key = new Triplet<>(id, item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active);
        if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
            cache = ((ILPTEInformation) duct).getObject().getCacheHolder().getCacheFor(CacheTypes.Routing, key);
        }
        if (cache instanceof Route) {
            route = (Route) cache;
            if (!routes.outputRoutes.contains(route)) {
                route = null;
            }
        }
        if (route == null) {
            Pair<Double, Route> closesedConnection = null;
            List<DoubleCoordinates> visited = new ArrayList<>();
            visited.add(new DoubleCoordinates(from));
            for (Route localRoute1 : paramIterable) {
                if (localRoute1.endPoint instanceof LPItemDuct) {
                    LPItemDuct lpDuct = (LPItemDuct) localRoute1.endPoint;
                    double max = Integer.MAX_VALUE;
                    if (closesedConnection != null) {
                        max = closesedConnection.getValue1();
                    }
                    DoubleCoordinates pos = new DoubleCoordinates((TileEntity) lpDuct.pipe);
                    if (visited.contains(pos)) {
                        continue;
                    }
                    visited.add(pos);
                    double distance = lpDuct.pipe.getDistanceTo(id, ForgeDirection.getOrientation(localRoute1.pathDirections.get(localRoute1.pathDirections.size() - 1)).getOpposite(), item.getItemIdentifierStack().getItem(), serverItem.getInfo()._transportMode == TransportMode.Active, localRoute1.pathWeight, max, visited);
                    visited.remove(pos);
                    if (distance != Integer.MAX_VALUE && (closesedConnection == null || distance + localRoute1.pathDirections.size() < closesedConnection.getValue1())) {
                        closesedConnection = new Pair<>(distance + localRoute1.pathWeight, localRoute1);
                    }
                }
            }
            if (closesedConnection != null) {
                route = closesedConnection.getValue2();
            }
        }
        if (route != null) {
            if (duct instanceof ILPTEInformation && ((ILPTEInformation) duct).getObject() != null) {
                ((ILPTEInformation) duct).getObject().getCacheHolder().setCache(CacheTypes.Routing, key, route);
            }
            TravelingItem travelItem = new TravelingItem(item.getItemIdentifierStack().makeNormalStack(), duct, route.copy(), (byte) serverItem.output.ordinal(), (byte) 1);
            travelItem.lpRoutingInformation = serverItem.getInfo();
            duct.insertNewItem(travelItem);
            return true;
        }
    } else {
        return true;
    }
    return false;
}
Also used : ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) Triplet(logisticspipes.utils.tuples.Triplet) ArrayList(java.util.ArrayList) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRouter(logisticspipes.routing.IRouter) TravelingItem(cofh.thermaldynamics.duct.item.TravelingItem) LPTravelingItem(logisticspipes.transport.LPTravelingItem) RouteCache(cofh.thermaldynamics.multiblock.RouteCache) Route(cofh.thermaldynamics.multiblock.Route) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 57 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class LogisticsRoutingBoardRobot method findTarget.

private Pair<Double, LogisticsRoutingBoardRobot> findTarget() {
    Pair<Double, LogisticsRoutingBoardRobot> result = null;
    DoubleCoordinates robotPos = new DoubleCoordinates(robot);
    for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : connectionDetails.localConnectedRobots) {
        if (robot.getLinkedStation() == null) {
            continue;
        }
        if (canidatePos.getValue1().equals(new DoubleCoordinates(robot.getLinkedStation().x(), robot.getLinkedStation().y(), robot.getLinkedStation().z()))) {
            continue;
        }
        double distance = CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(robotPos);
        if (result == null || result.getValue1() > distance) {
            TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(robot.worldObj);
            if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
                continue;
            }
            LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
            if (!connectedPipe.isRoutingPipe()) {
                continue;
            }
            PipePluggable connectedPluggable = ((TileGenericPipe) connectedPipe.tilePart.getOriginal()).getPipePluggable(canidatePos.getValue2());
            if (!(connectedPluggable instanceof RobotStationPluggable)) {
                continue;
            }
            DockingStation connectedStation = ((RobotStationPluggable) connectedPluggable).getStation();
            if (!connectedStation.isTaken()) {
                continue;
            }
            EntityRobotBase connectedRobot = connectedStation.robotTaking();
            if (connectedRobot == null) {
                continue;
            }
            if (!(connectedRobot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
                continue;
            }
            if (connectedRobot.isDead) {
                continue;
            }
            if (connectedRobot.getZoneToWork() != null && !connectedRobot.getZoneToWork().contains(robotPos.getXCoord(), robotPos.getYCoord(), robotPos.getZCoord())) {
                continue;
            }
            if (!((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).isAcceptsItems()) {
                continue;
            }
            if (((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).getCurrentTarget() != null && ((LogisticsRoutingBoardRobot) connectedRobot.getBoard()).getCurrentTarget().getValue2() != robot.getBoard()) {
                continue;
            }
            DoubleCoordinates connectedRobotPos = new DoubleCoordinates(connectedRobot);
            if (CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(connectedRobotPos) > 0.05) {
                // Not at station
                continue;
            }
            Double mindis = Double.NaN;
            for (LPTravelingItemServer item : items) {
                item.checkIDFromUUID();
                if (item.getInfo().destinationint < 0) {
                    continue;
                }
                ExitRoute route = connectedPipe.getRoutingPipe().getRouter().getExitFor(item.getInfo().destinationint, item.getInfo()._transportMode == TransportMode.Active, item.getItemIdentifierStack().getItem());
                if (route == null) {
                    continue;
                }
                if (mindis.isNaN()) {
                    mindis = route.distanceToDestination;
                }
                mindis = Math.min(mindis, route.distanceToDestination);
            }
            if (mindis.isNaN()) {
                continue;
            }
            double distanceToItem = ((distance * 3) + 21) + mindis;
            if (result == null || result.getValue1() > distanceToItem) {
                result = new Pair<>(distanceToItem, (LogisticsRoutingBoardRobot) connectedRobot.getBoard());
            }
        }
    }
    return result;
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) DockingStation(buildcraft.api.robots.DockingStation) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) TileGenericPipe(buildcraft.transport.TileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) EntityRobotBase(buildcraft.api.robots.EntityRobotBase) ExitRoute(logisticspipes.routing.ExitRoute) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 58 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class LogisticsRoutingBoardRobot method startTransport.

private void startTransport(LogisticsRoutingBoardRobot target, DockingStation station) {
    acceptsItems = false;
    targetStationPos = new DoubleCoordinates(station.x(), station.y(), station.z());
    targetStationSide = station.side();
    startDelegateAI(new AIRobotGotoBlock(robot, station.x() + station.side().offsetX, station.y() + station.side().offsetY, station.z() + station.side().offsetZ));
}
Also used : DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) AIRobotGotoBlock(buildcraft.robotics.ai.AIRobotGotoBlock)

Example 59 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class TesseractConnection method getConnections.

@Override
public List<TileEntity> getConnections(TileEntity tile) {
    boolean onlyOnePipe = false;
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(tile), direction);
        TileEntity canidate = p.getTileEntity(tile.getWorldObj());
        if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(tile, canidate, direction)) {
            if (onlyOnePipe) {
                onlyOnePipe = false;
                break;
            } else {
                onlyOnePipe = true;
            }
        }
    }
    if (!onlyOnePipe) {
        return new ArrayList<>(0);
    }
    List<? extends TileEntity> connections = SimpleServiceLocator.thermalExpansionProxy.getConnectedTesseracts(tile);
    connections.remove(tile);
    List<TileEntity> list = new ArrayList<>();
    for (TileEntity connected : connections) {
        LogisticsTileGenericPipe pipe = null;
        for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
            DoubleCoordinates p = CoordinateUtils.add(new DoubleCoordinates(connected), direction);
            TileEntity canidate = p.getTileEntity(connected.getWorldObj());
            if (canidate instanceof LogisticsTileGenericPipe && MainProxy.checkPipesConnections(connected, canidate, direction)) {
                if (pipe != null) {
                    pipe = null;
                    break;
                } else {
                    pipe = (LogisticsTileGenericPipe) canidate;
                }
            }
        }
        if (pipe != null && pipe.pipe instanceof CoreRoutedPipe) {
            list.add(pipe);
        }
    }
    if (list.size() == 1) {
        return list;
    } else {
        return new ArrayList<>(0);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ArrayList(java.util.ArrayList) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 60 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates in project LogisticsPipes by RS485.

the class TDPart method getInternalDuctForSide.

@Override
public TileEntity getInternalDuctForSide(ForgeDirection opposite) {
    if (opposite.ordinal() < 6) {
        LPItemDuct duct = thermalDynamicsDucts[opposite.ordinal()];
        if (duct == null) {
            duct = thermalDynamicsDucts[opposite.ordinal()] = new LPItemDuct(pipe, opposite);
            if (MainProxy.isServer(pipe.getWorldObj())) {
                TickHandler.addMultiBlockToCalculate(duct);
            }
            duct.setWorldObj(pipe.getWorldObj());
            duct.xCoord = pipe.xCoord;
            duct.yCoord = pipe.yCoord;
            duct.zCoord = pipe.zCoord;
            duct.validate();
            DoubleCoordinates pos = CoordinateUtils.add(new DoubleCoordinates((TileEntity) pipe), opposite);
            duct.onNeighborTileChange(pos.getXInt(), pos.getYInt(), pos.getZInt());
        }
        return duct;
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LPItemDuct(logisticspipes.proxy.td.LPItemDuct) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Aggregations

DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)70 TileEntity (net.minecraft.tileentity.TileEntity)44 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)15 ArrayList (java.util.ArrayList)14 LPPositionSet (logisticspipes.utils.LPPositionSet)10 Block (net.minecraft.block.Block)10 SideOnly (cpw.mods.fml.relauncher.SideOnly)8 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)8 ItemStack (net.minecraft.item.ItemStack)8 World (net.minecraft.world.World)8 LogisticsTileGenericSubMultiBlock (logisticspipes.pipes.basic.LogisticsTileGenericSubMultiBlock)6 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)6 IIcon (net.minecraft.util.IIcon)6 DockingStation (buildcraft.api.robots.DockingStation)5 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)5 DoubleCoordinatesType (network.rs485.logisticspipes.world.DoubleCoordinatesType)5 EntityRobotBase (buildcraft.api.robots.EntityRobotBase)4 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)4 RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)4