Search in sources :

Example 1 with RobotStationPluggable

use of buildcraft.robotics.RobotStationPluggable in project LogisticsPipes by RS485.

the class LPBCTileGenericPipe method updateEntity_LP.

@Override
@SneakyThrows({ NoSuchFieldException.class, SecurityException.class, IllegalArgumentException.class, IllegalAccessException.class, NoSuchMethodException.class, InvocationTargetException.class })
public void updateEntity_LP() {
    //Make sure we still have the same TE values
    xCoord = lpPipe.xCoord;
    yCoord = lpPipe.yCoord;
    zCoord = lpPipe.zCoord;
    if (attachPluggables) {
        attachPluggables = false;
        // Attach callback
        PipePluggable[] pluggables = ReflectionHelper.getPrivateField(PipePluggable[].class, SideProperties.class, "pluggables", sideProperties);
        for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
            if (pluggables[i] != null) {
                pipe.eventBus.registerHandler(pluggables[i]);
                pluggables[i].onAttachedPipe(this, ForgeDirection.getOrientation(i));
            }
        }
        notifyBlockChanged();
    }
    if (!BlockGenericPipe.isValid(pipe)) {
        return;
    }
    pipe.updateEntity();
    boolean recheckThisPipe = false;
    for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
        PipePluggable p = getPipePluggable(direction);
        if (p != null) {
            p.update(this, direction);
            //Check Gate for ActionChanges
            if (p instanceof GatePluggable && lpPipe.isRoutingPipe()) {
                if (!activeActions.containsKey(direction)) {
                    activeActions.put(direction, new ArrayList<>());
                }
                if (!listEquals(activeActions.get(direction), pipe.gates[direction.ordinal()].activeActions)) {
                    activeActions.get(direction).clear();
                    activeActions.get(direction).addAll(pipe.gates[direction.ordinal()].activeActions);
                    lpPipe.getRoutingPipe().triggerConnectionCheck();
                    recheckThisPipe = true;
                }
            } else if (activeActions.containsKey(direction)) {
                activeActions.remove(direction);
            }
            if (p instanceof RobotStationPluggable) {
                if (((RobotStationPluggable) p).getStation() != null && ((RobotStationPluggable) p).getStation().robotTaking() != null && ((RobotStationPluggable) p).getStation().robotTaking().getBoard() instanceof LogisticsRoutingBoardRobot) {
                    ((RobotStationPluggable) p).getStation().robotTaking().getBoard().cycle();
                }
            }
        }
    }
    if (recheckThisPipe) {
        LPRobotConnectionControl.instance.checkAll(worldObj);
    }
    if (worldObj.isRemote) {
        if (resyncGateExpansions) {
            ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "syncGateExpansions", new Class[] {}, new Object[] {});
        }
        return;
    }
    if (blockNeighborChange) {
        //ReflectionHelper.invokePrivateMethod(Object.class, TileGenericPipe.class, this, "computeConnections", new Class[]{}, new Object[]{});
        pipe.onNeighborBlockChange(0);
        blockNeighborChange = false;
        refreshRenderState = true;
    }
    if (refreshRenderState) {
        refreshRenderState();
        refreshRenderState = false;
    }
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) GatePluggable(buildcraft.transport.gates.GatePluggable) SneakyThrows(lombok.SneakyThrows)

Example 2 with RobotStationPluggable

use of buildcraft.robotics.RobotStationPluggable in project LogisticsPipes by RS485.

the class BuildCraftProxy method checkRobot.

/**
	 * @see buildcraft.robotics.ItemRobot#onItemUse(ItemStack, EntityPlayer,
	 *      World, int, int, int, int, float, float, float)
	 */
private boolean checkRobot(World world, int x, int y, int z, EntityPlayer player, ItemStack currentItem) {
    if (!world.isRemote) {
        Pipe<?> bcPipe = BlockGenericPipe.getPipe(world, x, y, z);
        if (bcPipe == null) {
            return false;
        }
        BlockGenericPipe pipeBlock = BuildCraftTransport.genericPipeBlock;
        BlockGenericPipe.RaytraceResult rayTraceResult = pipeBlock.doRayTrace(world, x, y, z, player);
        if (rayTraceResult != null && rayTraceResult.hitPart == BlockGenericPipe.Part.Pluggable && bcPipe.container.getPipePluggable(rayTraceResult.sideHit) instanceof RobotStationPluggable) {
            RobotStationPluggable pluggable = (RobotStationPluggable) bcPipe.container.getPipePluggable(rayTraceResult.sideHit);
            DockingStation station = pluggable.getStation();
            if (!station.isTaken()) {
                RedstoneBoardRobotNBT robotNBT = ItemRobot.getRobotNBT(currentItem);
                if (robotNBT == RedstoneBoardRegistry.instance.getEmptyRobotBoard()) {
                    return true;
                }
                EntityRobot robot = ((ItemRobot) currentItem.getItem()).createRobot(currentItem, world);
                RobotEvent.Place robotEvent = new RobotEvent.Place(robot, player);
                FMLCommonHandler.instance().bus().post(robotEvent);
                if (robotEvent.isCanceled()) {
                    return true;
                }
                if (robot != null && robot.getRegistry() != null) {
                    robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());
                    float px = x + 0.5F + rayTraceResult.sideHit.offsetX * 0.5F;
                    float py = y + 0.5F + rayTraceResult.sideHit.offsetY * 0.5F;
                    float pz = z + 0.5F + rayTraceResult.sideHit.offsetZ * 0.5F;
                    robot.setPosition(px, py, pz);
                    station.takeAsMain(robot);
                    robot.dock(robot.getLinkedStation());
                    world.spawnEntityInWorld(robot);
                    if (!player.capabilities.isCreativeMode) {
                        player.getCurrentEquippedItem().stackSize--;
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) DockingStation(buildcraft.api.robots.DockingStation) EntityRobot(buildcraft.robotics.EntityRobot) BlockGenericPipe(buildcraft.transport.BlockGenericPipe) RedstoneBoardRobotNBT(buildcraft.api.boards.RedstoneBoardRobotNBT) ItemRobot(buildcraft.robotics.ItemRobot) RobotEvent(buildcraft.api.events.RobotEvent)

Example 3 with RobotStationPluggable

use of buildcraft.robotics.RobotStationPluggable in project LogisticsPipes by RS485.

the class LPRobotConnectionControl method checkAll.

public void checkAll(World world) {
    if (!globalAvailableRobots.containsKey(world)) {
        return;
    }
    for (Pair<DoubleCoordinates, ForgeDirection> canidatePos : globalAvailableRobots.get(world)) {
        TileEntity connectedPipeTile = canidatePos.getValue1().getTileEntity(world);
        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;
        }
        LogisticsRoutingBoardRobot lpBoard = ((LogisticsRoutingBoardRobot) connectedRobot.getBoard());
        if (isModified(lpBoard)) {
            connectedPipe.getRoutingPipe().triggerConnectionCheck();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) RobotStationPluggable(buildcraft.robotics.RobotStationPluggable) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) TileGenericPipe(buildcraft.transport.TileGenericPipe) DockingStation(buildcraft.api.robots.DockingStation) LogisticsRoutingBoardRobot(logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) EntityRobotBase(buildcraft.api.robots.EntityRobotBase) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 4 with RobotStationPluggable

use of buildcraft.robotics.RobotStationPluggable 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 5 with RobotStationPluggable

use of buildcraft.robotics.RobotStationPluggable 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)

Aggregations

RobotStationPluggable (buildcraft.robotics.RobotStationPluggable)6 DockingStation (buildcraft.api.robots.DockingStation)5 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)5 EntityRobotBase (buildcraft.api.robots.EntityRobotBase)4 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)4 LogisticsRoutingBoardRobot (logisticspipes.proxy.buildcraft.robots.boards.LogisticsRoutingBoardRobot)4 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)4 TileGenericPipe (buildcraft.transport.TileGenericPipe)3 TileEntity (net.minecraft.tileentity.TileEntity)3 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)2 RedstoneBoardRobotNBT (buildcraft.api.boards.RedstoneBoardRobotNBT)1 RobotEvent (buildcraft.api.events.RobotEvent)1 EntityRobot (buildcraft.robotics.EntityRobot)1 ItemRobot (buildcraft.robotics.ItemRobot)1 BlockGenericPipe (buildcraft.transport.BlockGenericPipe)1 GatePluggable (buildcraft.transport.gates.GatePluggable)1 ArrayList (java.util.ArrayList)1 LogisticsPowerJunctionTileEntity (logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity)1 ConnectionInformation (logisticspipes.proxy.specialconnection.SpecialPipeConnection.ConnectionInformation)1