Search in sources :

Example 41 with DoubleCoordinates

use of network.rs485.logisticspipes.world.DoubleCoordinates 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 42 with DoubleCoordinates

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

the class LogisticsBlockGenericPipe method removePipe.

public static void removePipe(CoreUnroutedPipe pipe) {
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return;
    }
    if (pipe.canBeDestroyed() || pipe.destroyByPlayer()) {
        pipe.onBlockRemoval();
    } else if (pipe.preventRemove()) {
        LogisticsBlockGenericPipe.cacheTileToPreventRemoval(pipe);
    }
    World world = pipe.container.getWorldObj();
    if (pipe.isMultiBlock()) {
        if (pipe.preventRemove()) {
            throw new UnsupportedOperationException("A multi block can't be protected against removal.");
        }
        LPPositionSet<DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare>> list = ((CoreMultiBlockPipe) pipe).getRotatedSubBlocks();
        list.stream().forEach(pos -> pos.add(new DoubleCoordinates(pipe)));
        for (DoubleCoordinates pos : pipe.container.subMultiBlock) {
            TileEntity tile = pos.getTileEntity(world);
            if (tile instanceof LogisticsTileGenericSubMultiBlock) {
                DoubleCoordinatesType<CoreMultiBlockPipe.SubBlockTypeForShare> equ = list.findClosest(pos);
                if (equ != null) {
                    ((LogisticsTileGenericSubMultiBlock) tile).removeSubType(equ.getType());
                }
                if (((LogisticsTileGenericSubMultiBlock) tile).removeMainPipe(new DoubleCoordinates(pipe))) {
                    pos.setBlockToAir(world);
                } else {
                    MainProxy.sendPacketToAllWatchingChunk(tile, ((LogisticsTileGenericSubMultiBlock) tile).getLPDescriptionPacket());
                }
            }
        }
    }
    if (world == null) {
        return;
    }
    int x = pipe.container.xCoord;
    int y = pipe.container.yCoord;
    int z = pipe.container.zCoord;
    if (LogisticsBlockGenericPipe.lastRemovedDate != world.getTotalWorldTime()) {
        LogisticsBlockGenericPipe.lastRemovedDate = world.getTotalWorldTime();
        LogisticsBlockGenericPipe.pipeRemoved.clear();
    }
    LogisticsBlockGenericPipe.pipeRemoved.put(new DoubleCoordinates(x, y, z), pipe);
    world.removeTileEntity(x, y, z);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) DoubleCoordinatesType(network.rs485.logisticspipes.world.DoubleCoordinatesType) World(net.minecraft.world.World) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 43 with DoubleCoordinates

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

the class LogisticsBlockGenericPipe method getDrops.

@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
    if (world.isRemote) {
        return null;
    }
    ArrayList<ItemStack> list = new ArrayList<>();
    int count = quantityDropped(metadata, fortune, world.rand);
    for (int i = 0; i < count; i++) {
        CoreUnroutedPipe pipe = LogisticsBlockGenericPipe.getPipe(world, x, y, z);
        if (pipe == null) {
            pipe = LogisticsBlockGenericPipe.pipeRemoved.get(new DoubleCoordinates(x, y, z));
        }
        if (pipe != null) {
            if (pipe.item != null && (pipe.canBeDestroyed() || pipe.destroyByPlayer())) {
                list.addAll(pipe.dropContents());
                list.add(new ItemStack(pipe.item, 1, damageDropped(metadata)));
            } else if (pipe.item != null) {
                LogisticsBlockGenericPipe.cacheTileToPreventRemoval(pipe);
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 44 with DoubleCoordinates

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

the class LogisticsBlockGenericSubMultiBlock method addCollisionBoxesToList.

@SuppressWarnings("rawtypes")
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List arraylist, Entity entity) {
    DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
    TileEntity tile = pos.getTileEntity(world);
    if (tile instanceof LogisticsTileGenericSubMultiBlock) {
        List<LogisticsTileGenericPipe> mainPipeList = ((LogisticsTileGenericSubMultiBlock) tile).getMainPipe();
        mainPipeList.stream().filter(mainPipe -> mainPipe != null && mainPipe.pipe != null && mainPipe.pipe.isMultiBlock()).forEach(mainPipe -> LogisticsPipes.LogisticsPipeBlock.addCollisionBoxesToList(world, mainPipe.xCoord, mainPipe.yCoord, mainPipe.zCoord, axisalignedbb, arraylist, entity));
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LogisticsPipes(logisticspipes.LogisticsPipes) Random(java.util.Random) MainProxy(logisticspipes.proxy.MainProxy) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Block(net.minecraft.block.Block) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Minecraft(net.minecraft.client.Minecraft) LPConstants(logisticspipes.LPConstants) IBlockAccess(net.minecraft.world.IBlockAccess) Vec3(net.minecraft.util.Vec3) Entity(net.minecraft.entity.Entity) BlockContainer(net.minecraft.block.BlockContainer) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) EffectRenderer(net.minecraft.client.particle.EffectRenderer) World(net.minecraft.world.World) EntityDiggingFX(net.minecraft.client.particle.EntityDiggingFX) AxisAlignedBB(net.minecraft.util.AxisAlignedBB) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) IIcon(net.minecraft.util.IIcon) List(java.util.List) Material(net.minecraft.block.material.Material) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 45 with DoubleCoordinates

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

the class LogisticsBlockGenericSubMultiBlock method addDestroyEffects.

@Override
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
    DoubleCoordinates pos = new DoubleCoordinates(x, y, z);
    TileEntity tile = pos.getTileEntity(world);
    if (tile instanceof LogisticsTileGenericSubMultiBlock) {
        List<LogisticsTileGenericPipe> mainPipeList = ((LogisticsTileGenericSubMultiBlock) tile).getMainPipe();
        for (LogisticsTileGenericPipe mainPipe : mainPipeList) {
            if (mainPipe != null && mainPipe.pipe != null && mainPipe.pipe.isMultiBlock()) {
                if (LogisticsPipes.LogisticsPipeBlock.doRayTrace(world, mainPipe.xCoord, mainPipe.yCoord, mainPipe.zCoord, Minecraft.getMinecraft().thePlayer) != null) {
                    return LogisticsPipes.LogisticsPipeBlock.addDestroyEffects(world, mainPipe.xCoord, mainPipe.yCoord, mainPipe.zCoord, meta, effectRenderer);
                }
            }
        }
    }
    return super.addDestroyEffects(world, x, y, z, meta, effectRenderer);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) 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