Search in sources :

Example 11 with LPTravelingItemServer

use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer in project LogisticsPipes by RS485.

the class LPItemDuct method transferItem.

@Override
public void transferItem(TravelingItem item) {
    ItemRoutingInformation info = (ItemRoutingInformation) item.lpRoutingInformation;
    if (info != null) {
        info.setItem(ItemIdentifierStack.getFromStack(item.stack));
        LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
        lpItem.setSpeed(info._transportMode == TransportMode.Active ? 0.3F : 0.2F);
        pipe.pipe.transport.injectItem(lpItem, ForgeDirection.getOrientation(item.direction));
    } else if (item.stack != null) {
        int consumed = pipe.injectItem(item.stack, true, dir);
        item.stack.stackSize -= consumed;
        if (item.stack.stackSize > 0) {
            pipe.pipe.transport._itemBuffer.add(new Triplet<>(ItemIdentifierStack.getFromStack(item.stack), new Pair<>(20 * 2, 0), null));
        }
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) Triplet(logisticspipes.utils.tuples.Triplet) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 12 with LPTravelingItemServer

use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer 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 13 with LPTravelingItemServer

use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer 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 14 with LPTravelingItemServer

use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer in project LogisticsPipes by RS485.

the class LPBCTileGenericPipe method getBCPipePluggable.

@Override
public IBCPipePluggable getBCPipePluggable(final ForgeDirection sideHit) {
    final PipePluggable plug = getPipePluggable(sideHit);
    if (plug == null) {
        return null;
    }
    return new IBCPipePluggable() {

        @Override
        public ItemStack[] getDropItems(LogisticsTileGenericPipe container) {
            return plug.getDropItems(container);
        }

        @Override
        public boolean isBlocking() {
            return plug.isBlocking(pipe.container, sideHit);
        }

        @Override
        public Object getOriginal() {
            return plug;
        }

        @Override
        @SideOnly(Side.CLIENT)
        public void renderPluggable(RenderBlocks renderblocks, ForgeDirection dir, int renderPass, int x, int y, int z) {
            if (plug.getRenderer() == null) {
                return;
            }
            plug.getRenderer().renderPluggable(renderblocks, bcPipe, dir, plug, FakeBlock.INSTANCE, renderPass, x, y, z);
        }

        @Override
        public boolean isAcceptingItems(LPTravelingItemServer arrivingItem) {
            if (plug instanceof RobotStationPluggable) {
                return true;
            }
            return false;
        }

        @Override
        public LPTravelingItemServer handleItem(LPTravelingItemServer arrivingItem) {
            DockingStation station = ((RobotStationPluggable) plug).getStation();
            if (!station.isTaken()) {
                return arrivingItem;
            }
            EntityRobotBase robot = station.robotTaking();
            if (!(robot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
                return arrivingItem;
            }
            if (!((LogisticsRoutingBoardRobot) robot.getBoard()).isAcceptsItems()) {
                return arrivingItem;
            }
            DoubleCoordinates robotPos = new DoubleCoordinates(robot);
            if (CoordinateUtils.add(new DoubleCoordinates(LPBCTileGenericPipe.this).center(), sideHit, 0.5).distanceTo(robotPos) > 0.05) {
                // Not at station
                return arrivingItem;
            }
            return ((LogisticsRoutingBoardRobot) robot.getBoard()).handleItem(arrivingItem);
        }
    };
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) RenderBlocks(net.minecraft.client.renderer.RenderBlocks) DockingStation(buildcraft.api.robots.DockingStation) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityRobotBase(buildcraft.api.robots.EntityRobotBase) ItemStack(net.minecraft.item.ItemStack) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 15 with LPTravelingItemServer

use of logisticspipes.transport.LPTravelingItem.LPTravelingItemServer in project LogisticsPipes by RS485.

the class PipeTransportLogistics method injectItem.

/**
	 * Accept items from BC
	 */
@ModDependentMethod(modId = "BuildCraft|Transport")
public void injectItem(TravelingItem item, ForgeDirection inputOrientation) {
    if (MainProxy.isServer(getWorld())) {
        if (item instanceof LPRoutedBCTravelingItem) {
            ItemRoutingInformation info = ((LPRoutedBCTravelingItem) item).getRoutingInformation();
            info.setItem(ItemIdentifierStack.getFromStack(item.getItemStack()));
            LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
            lpItem.setSpeed(item.getSpeed());
            this.injectItem(lpItem, inputOrientation);
        } else {
            ItemRoutingInformation info = LPRoutedBCTravelingItem.restoreFromExtraNBTData(item);
            if (info != null) {
                info.setItem(ItemIdentifierStack.getFromStack(item.getItemStack()));
                LPTravelingItemServer lpItem = new LPTravelingItemServer(info);
                lpItem.setSpeed(item.getSpeed());
                this.injectItem(lpItem, inputOrientation);
            } else {
                LPTravelingItemServer lpItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(item.getItemStack());
                lpItem.setSpeed(item.getSpeed());
                this.injectItem(lpItem, inputOrientation);
            }
        }
    }
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) LPRoutedBCTravelingItem(logisticspipes.proxy.buildcraft.LPRoutedBCTravelingItem) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer) ModDependentMethod(logisticspipes.asm.ModDependentMethod)

Aggregations

LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)18 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)3 ItemStack (net.minecraft.item.ItemStack)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 DockingStation (buildcraft.api.robots.DockingStation)2 EntityRobotBase (buildcraft.api.robots.EntityRobotBase)2 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)2 RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)2 ArrayList (java.util.ArrayList)2 ExitRoute (logisticspipes.routing.ExitRoute)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2 Pair (logisticspipes.utils.tuples.Pair)2 Triplet (logisticspipes.utils.tuples.Triplet)2 RenderBlocks (net.minecraft.client.renderer.RenderBlocks)2 TileEntity (net.minecraft.tileentity.TileEntity)2 PipeTransportItems (buildcraft.transport.PipeTransportItems)1