Search in sources :

Example 11 with PipePluggable

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

the class TileGenericPipe method update.

@Override
public void update() {
    try {
        if (!worldObj.isRemote) {
            if (deletePipe) {
                worldObj.setBlockToAir(getPos());
            }
            if (pipe == null || coreState.pipeId == null) {
                return;
            }
            if (!initialized) {
                initialize(pipe);
            }
        }
        if (attachPluggables) {
            attachPluggables = false;
            // Attach callback
            for (int i = 0; i < EnumFacing.VALUES.length; i++) {
                if (sideProperties.pluggables[i] != null) {
                    pipe.eventBus.registerHandler(sideProperties.pluggables[i]);
                    sideProperties.pluggables[i].onAttachedPipe(this, EnumFacing.getFront(i));
                }
            }
            notifyBlockChanged();
        }
        if (!BlockGenericPipe.isValid(pipe)) {
            return;
        }
        pipe.updateEntity();
        for (EnumFacing direction : EnumFacing.VALUES) {
            PipePluggable p = getPipePluggable(direction);
            if (p != null) {
                p.update(this, direction);
            }
        }
        if (worldObj.isRemote) {
            if (resyncGateExpansions) {
                syncGateExpansions();
            }
            return;
        }
        if (blockNeighborChange) {
            for (int i = 0; i < 6; i++) {
                if ((blockNeighborChangedSides & (1 << i)) != 0) {
                    blockNeighborChangedSides ^= 1 << i;
                    computeConnection(EnumFacing.getFront(i));
                }
            }
            pipe.onNeighborBlockChange(0);
            blockNeighborChange = false;
            refreshRenderState = true;
        }
        if (refreshRenderState) {
            refreshRenderState();
            refreshRenderState = false;
        }
        if (sendClientUpdate) {
            sendClientUpdate = false;
            if (!worldObj.isRemote) {
                Packet updatePacket = getBCDescriptionPacket();
                BuildCraftCore.instance.sendToPlayersNear(updatePacket, this);
            }
        }
    } catch (Throwable t) {
        BCLog.logger.warn("CRASH! OH NO!", t);
        Throwables.propagate(t);
    }
}
Also used : Packet(buildcraft.core.lib.network.base.Packet) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable)

Example 12 with PipePluggable

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

the class ItemRobot method onItemUse.

@Override
public boolean onItemUse(ItemStack currentItem, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        Block b = world.getBlockState(pos).getBlock();
        if (!(b instanceof BlockGenericPipe)) {
            return false;
        }
        Pipe<?> pipe = BlockGenericPipe.getPipe(world, pos);
        if (pipe == null) {
            return false;
        }
        // BlockGenericPipe pipeBlock = (BlockGenericPipe) b;
        // BlockGenericPipe.RaytraceResult rayTraceResult = pipeBlock.doRayTrace(world, pos, player);
        PipePluggable pluggable = pipe.container.getPipePluggable(side);
        if (pluggable instanceof RobotStationPluggable) {
            RobotStationPluggable robotPluggable = (RobotStationPluggable) pluggable;
            DockingStation station = robotPluggable.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);
                MinecraftForge.EVENT_BUS.post(robotEvent);
                if (robotEvent.isCanceled()) {
                    return true;
                }
                if (robot != null && robot.getRegistry() != null) {
                    robot.setUniqueRobotId(robot.getRegistry().getNextRobotId());
                    float px = pos.getX() + 0.5F + side.getFrontOffsetX() * 0.5F;
                    float py = pos.getY() + 0.5F + side.getFrontOffsetY() * 0.5F;
                    float pz = pos.getZ() + 0.5F + side.getFrontOffsetZ() * 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 : DockingStation(buildcraft.api.robots.DockingStation) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) BlockGenericPipe(buildcraft.transport.BlockGenericPipe) Block(net.minecraft.block.Block) RedstoneBoardRobotNBT(buildcraft.api.boards.RedstoneBoardRobotNBT) RobotEvent(buildcraft.api.events.RobotEvent)

Example 13 with PipePluggable

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

the class LensFilterHandler method eventHandler.

@PipeEventPriority(priority = -100)
public void eventHandler(PipeEventItem.FindDest event) {
    IPipeTile container = event.pipe.getTile();
    List<EnumSet<EnumFacing>> newDestinations = new ArrayList<>(event.destinations.size() * 2);
    for (EnumSet<EnumFacing> dirs : event.destinations) {
        EnumSet<EnumFacing> correctColored = EnumSet.noneOf(EnumFacing.class);
        EnumSet<EnumFacing> notColored = EnumSet.noneOf(EnumFacing.class);
        EnumDyeColor myColor = event.item.color;
        for (EnumFacing dir : dirs) {
            boolean hasFilter = false;
            boolean hasLens = false;
            EnumDyeColor sideColor = null;
            EnumDyeColor sideLensColor = null;
            // Get the side's color
            // (1/2) From this pipe's outpost
            PipePluggable pluggable = container.getPipePluggable(dir);
            if (pluggable != null && pluggable instanceof LensPluggable) {
                if (((LensPluggable) pluggable).isFilter) {
                    hasFilter = true;
                    sideColor = ((LensPluggable) pluggable).dyeColor;
                } else {
                    hasLens = true;
                    sideLensColor = ((LensPluggable) pluggable).dyeColor;
                }
            }
            // (2/2) From the other pipe's outpost
            IPipe otherPipe = container.getNeighborPipe(dir);
            if (otherPipe != null && otherPipe.getTile() != null) {
                IPipeTile otherContainer = otherPipe.getTile();
                pluggable = otherContainer.getPipePluggable(dir.getOpposite());
                if (pluggable != null && pluggable instanceof LensPluggable && ((LensPluggable) pluggable).isFilter) {
                    EnumDyeColor otherColor = ((LensPluggable) pluggable).dyeColor;
                    if (hasFilter && otherColor != sideColor) {
                        // Filter colors conflict - the side is unpassable
                        continue;
                    } else if (hasLens) {
                        // treated as colorless
                        if (sideLensColor == otherColor) {
                            hasFilter = false;
                            sideColor = null;
                        } else {
                            continue;
                        }
                    } else {
                        hasFilter = true;
                        sideColor = otherColor;
                    }
                }
            }
            if (hasFilter) {
                if (myColor == sideColor) {
                    correctColored.add(dir);
                }
            } else {
                notColored.add(dir);
            }
        }
        if (!correctColored.isEmpty()) {
            newDestinations.add(correctColored);
        }
        if (!notColored.isEmpty()) {
            newDestinations.add(notColored);
        }
    }
    event.destinations.clear();
    event.destinations.addAll(newDestinations);
}
Also used : IPipeTile(buildcraft.api.transport.IPipeTile) LensPluggable(buildcraft.transport.pluggable.LensPluggable) EnumSet(java.util.EnumSet) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) EnumDyeColor(net.minecraft.item.EnumDyeColor) IPipe(buildcraft.api.transport.IPipe) PipeEventPriority(buildcraft.transport.pipes.events.PipeEventPriority)

Example 14 with PipePluggable

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

the class BCTransportProxy method getServerGuiElement.

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
    BCTransportGuis gui = BCTransportGuis.get(id);
    if (gui == null)
        return null;
    TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
    switch(gui) {
        case FILTERED_BUFFER:
            {
                if (tile instanceof TileFilteredBuffer) {
                    TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
                    return new ContainerFilteredBuffer_BC8(player, filteredBuffer);
                }
                break;
            }
        case PIPE_DIAMOND:
            {
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    IPipe pipe = holder.getPipe();
                    if (pipe == null)
                        return null;
                    PipeBehaviour behaviour = pipe.getBehaviour();
                    if (behaviour instanceof PipeBehaviourDiamond) {
                        PipeBehaviourDiamond diaPipe = (PipeBehaviourDiamond) behaviour;
                        return new ContainerDiamondPipe(player, diaPipe);
                    }
                }
                break;
            }
        case PIPE_DIAMOND_WOOD:
            {
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    IPipe pipe = holder.getPipe();
                    if (pipe == null)
                        return null;
                    PipeBehaviour behaviour = pipe.getBehaviour();
                    if (behaviour instanceof PipeBehaviourWoodDiamond) {
                        PipeBehaviourWoodDiamond diaPipe = (PipeBehaviourWoodDiamond) behaviour;
                        return new ContainerDiamondWoodPipe(player, diaPipe);
                    }
                }
                break;
            }
        case PIPE_EMZULI:
            {
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    IPipe pipe = holder.getPipe();
                    if (pipe == null)
                        return null;
                    PipeBehaviour behaviour = pipe.getBehaviour();
                    if (behaviour instanceof PipeBehaviourEmzuli) {
                        PipeBehaviourEmzuli emPipe = (PipeBehaviourEmzuli) behaviour;
                        return new ContainerEmzuliPipe_BC8(player, emPipe);
                    }
                }
                break;
            }
        case GATE:
            {
                int ry = y >> 3;
                EnumFacing gateSide = EnumFacing.getFront(y & 0x7);
                tile = world.getTileEntity(new BlockPos(x, ry, z));
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    PipePluggable plug = holder.getPluggable(gateSide);
                    if (plug instanceof PluggableGate) {
                        return new ContainerGate(player, ((PluggableGate) plug).logic);
                    }
                }
                break;
            }
    }
    return null;
}
Also used : IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) PipeBehaviourEmzuli(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) PipeBehaviourWoodDiamond(buildcraft.transport.pipe.behaviour.PipeBehaviourWoodDiamond) PipeBehaviourDiamond(buildcraft.transport.pipe.behaviour.PipeBehaviourDiamond) TileEntity(net.minecraft.tileentity.TileEntity) ContainerFilteredBuffer_BC8(buildcraft.transport.container.ContainerFilteredBuffer_BC8) PluggableGate(buildcraft.transport.plug.PluggableGate) TileFilteredBuffer(buildcraft.transport.tile.TileFilteredBuffer) BlockPos(net.minecraft.util.math.BlockPos) ContainerEmzuliPipe_BC8(buildcraft.transport.container.ContainerEmzuliPipe_BC8) ContainerGate(buildcraft.transport.container.ContainerGate) ContainerDiamondPipe(buildcraft.transport.container.ContainerDiamondPipe) IPipe(buildcraft.api.transport.pipe.IPipe) ContainerDiamondWoodPipe(buildcraft.transport.container.ContainerDiamondWoodPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Example 15 with PipePluggable

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

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