Search in sources :

Example 16 with PipePluggable

use of buildcraft.api.transport.pluggable.PipePluggable in project LogisticsPipes by RS485.

the class LPRobotConnectionControl method getConnections.

@Override
public List<ConnectionInformation> getConnections(IPipeInformationProvider startPipe, EnumSet<PipeRoutingConnectionType> connection, ForgeDirection side) {
    List<ConnectionInformation> list = new ArrayList<>();
    LogisticsTileGenericPipe pipe = (LogisticsTileGenericPipe) startPipe;
    if (pipe == null || pipe.tilePart.getOriginal() == null) {
        // Proxy got disabled
        return list;
    }
    DoubleCoordinates pos = new DoubleCoordinates(startPipe);
    pos.center();
    for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
        PipePluggable pluggable = ((TileGenericPipe) pipe.tilePart.getOriginal()).getPipePluggable(dir);
        if (!(pluggable instanceof RobotStationPluggable)) {
            continue;
        }
        DockingStation station = ((RobotStationPluggable) pluggable).getStation();
        if (!station.isTaken()) {
            continue;
        }
        EntityRobotBase robot = station.robotTaking();
        if (robot == null) {
            continue;
        }
        if (!(robot.getBoard() instanceof LogisticsRoutingBoardRobot)) {
            continue;
        }
        if (robot.isDead) {
            continue;
        }
        if (!((LogisticsRoutingBoardRobot) robot.getBoard()).isAcceptsItems()) {
            continue;
        }
        DoubleCoordinates robotPos = new DoubleCoordinates(robot);
        if (((LogisticsRoutingBoardRobot) robot.getBoard()).getCurrentTarget() != null) {
            Pair<Double, LogisticsRoutingBoardRobot> currentTarget = ((LogisticsRoutingBoardRobot) robot.getBoard()).getCurrentTarget();
            DoubleCoordinates pipePos = currentTarget.getValue2().getLinkedStationPosition();
            TileEntity connectedPipeTile = pipePos.getTileEntity(pipe.getWorldObj());
            if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
                continue;
            }
            LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
            if (!connectedPipe.isRoutingPipe()) {
                continue;
            }
            IPipeInformationProvider connectedInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(connectedPipe);
            EntityRobotBase connectedRobot = currentTarget.getValue2().robot;
            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;
            }
            DoubleCoordinates connectedRobotPos = new DoubleCoordinates(connectedRobot);
            if (CoordinateUtils.add(new DoubleCoordinates(pipePos).center(), currentTarget.getValue2().robot.getLinkedStation().side(), 0.5).distanceTo(connectedRobotPos) > 0.05) {
                // Not at station
                continue;
            }
            EnumSet<PipeRoutingConnectionType> newCon = connection.clone();
            newCon.removeAll(EnumSet.of(PipeRoutingConnectionType.canPowerFrom, PipeRoutingConnectionType.canPowerSubSystemFrom));
            double distance = CoordinateUtils.add(new DoubleCoordinates(currentTarget.getValue2().getLinkedStationPosition()).center(), currentTarget.getValue2().robot.getLinkedStation().side(), 0.5).distanceTo(robotPos);
            list.add(new ConnectionInformation(connectedInfo, newCon, currentTarget.getValue2().robot.getLinkedStation().side().getOpposite(), dir, (distance * 3) + 21));
        } else {
            if (CoordinateUtils.add(new DoubleCoordinates(pos), dir, 0.5).distanceTo(robotPos) > 0.05) {
                // Not at station
                continue;
            }
            for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : ((LogisticsRoutingBoardRobot) robot.getBoard()).getConnectionDetails().localConnectedRobots) {
                if (canidatePos.getValue1().equals(new DoubleCoordinates(startPipe))) {
                    continue;
                }
                double distance = CoordinateUtils.add(new DoubleCoordinates(canidatePos.getValue1()).center(), canidatePos.getValue2(), 0.5).distanceTo(robotPos);
                TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(pipe.getWorldObj());
                if (!(connectedPipeTile instanceof LogisticsTileGenericPipe)) {
                    continue;
                }
                LogisticsTileGenericPipe connectedPipe = (LogisticsTileGenericPipe) connectedPipeTile;
                if (!connectedPipe.isRoutingPipe()) {
                    continue;
                }
                IPipeInformationProvider connectedInfo = SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(connectedPipe);
                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;
                }
                EnumSet<PipeRoutingConnectionType> newCon = connection.clone();
                newCon.removeAll(EnumSet.of(PipeRoutingConnectionType.canPowerFrom, PipeRoutingConnectionType.canPowerSubSystemFrom));
                list.add(new ConnectionInformation(connectedInfo, newCon, canidatePos.getValue2().getOpposite(), dir, (distance * 3) + 21));
            }
        }
    }
    return list;
}
Also used : ConnectionInformation(logisticspipes.proxy.specialconnection.SpecialPipeConnection.ConnectionInformation) RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) DockingStation(buildcraft.api.robots.DockingStation) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) ArrayList(java.util.ArrayList) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) TileEntity(net.minecraft.tileentity.TileEntity) IPipeInformationProvider(logisticspipes.routing.pathfinder.IPipeInformationProvider) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) TileGenericPipe(buildcraft.transport.TileGenericPipe) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) EntityRobotBase(buildcraft.api.robots.EntityRobotBase)

Example 17 with PipePluggable

use of buildcraft.api.transport.pluggable.PipePluggable 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 18 with PipePluggable

use of buildcraft.api.transport.pluggable.PipePluggable 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 19 with PipePluggable

use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.

the class BlockPipeHolder method canBeConnectedTo.

@Override
public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        return false;
    }
    PipePluggable pluggable = tile.getPluggable(facing);
    return pluggable != null && pluggable.canBeConnected();
}
Also used : TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable)

Example 20 with PipePluggable

use of buildcraft.api.transport.pluggable.PipePluggable in project BuildCraft by BuildCraft.

the class BlockPipeHolder method getPickBlock.

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null || target == null) {
        return ItemStack.EMPTY;
    }
    if (target.subHit <= 6) {
        Pipe pipe = tile.getPipe();
        if (pipe != null) {
            PipeDefinition def = pipe.getDefinition();
            Item item = (Item) PipeApi.pipeRegistry.getItemForPipe(def);
            if (item != null) {
                int meta = pipe.getColour() == null ? 0 : pipe.getColour().getMetadata() + 1;
                return new ItemStack(item, 1, meta);
            }
        }
    } else if (target.subHit <= 12) {
        int pluggableHit = target.subHit - 7;
        EnumFacing face = EnumFacing.VALUES[pluggableHit];
        PipePluggable plug = tile.getPluggable(face);
        if (plug != null) {
            return plug.getPickStack();
        }
    } else {
        EnumWirePart part = null;
        EnumWireBetween between = null;
        if (target.subHit > 6) {
            part = getWirePartHit(target);
            between = getWireBetweenHit(target);
        }
        if (part != null && tile.wireManager.getColorOfPart(part) != null) {
            return new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(part).getMetadata());
        } else if (between != null && tile.wireManager.getColorOfPart(between.parts[0]) != null) {
            return new ItemStack(BCTransportItems.wire, 1, tile.wireManager.getColorOfPart(between.parts[0]).getMetadata());
        }
    }
    return ItemStack.EMPTY;
}
Also used : TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) Item(net.minecraft.item.Item) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) PipeDefinition(buildcraft.api.transport.pipe.PipeDefinition) ItemStack(net.minecraft.item.ItemStack) EnumWireBetween(buildcraft.transport.wire.EnumWireBetween)

Aggregations

PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)30 EnumFacing (net.minecraft.util.EnumFacing)17 TilePipeHolder (buildcraft.transport.tile.TilePipeHolder)10 Pipe (buildcraft.transport.pipe.Pipe)6 DockingStation (buildcraft.api.robots.DockingStation)5 EnumWirePart (buildcraft.api.transport.EnumWirePart)5 RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)5 TileEntity (net.minecraft.tileentity.TileEntity)5 EntityRobotBase (buildcraft.api.robots.EntityRobotBase)4 EnumWireBetween (buildcraft.transport.wire.EnumWireBetween)4 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 ItemStack (net.minecraft.item.ItemStack)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4 IPipe (buildcraft.api.transport.pipe.IPipe)3 TileGenericPipe (buildcraft.transport.TileGenericPipe)3 LogisticsRoutingBoardRobot (logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot)3 Vec3d (net.minecraft.util.math.Vec3d)3 IPipeTile (buildcraft.api.transport.IPipeTile)2 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)2