Search in sources :

Example 1 with PipeBehaviour

use of buildcraft.api.transport.pipe.PipeBehaviour 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 2 with PipeBehaviour

use of buildcraft.api.transport.pipe.PipeBehaviour in project BuildCraft by BuildCraft.

the class ItemPluggablePulsar method onPlace.

@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
    IPipe pipe = holder.getPipe();
    if (pipe == null) {
        return null;
    }
    PipeBehaviour behaviour = pipe.getBehaviour();
    if (behaviour instanceof IMjRedstoneReceiver) {
        SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos());
        return new PluggablePulsar(BCTransportPlugs.pulsar, holder, side);
    } else {
        return null;
    }
}
Also used : PluggablePulsar(buildcraft.transport.plug.PluggablePulsar) IMjRedstoneReceiver(buildcraft.api.mj.IMjRedstoneReceiver) IPipe(buildcraft.api.transport.pipe.IPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Example 3 with PipeBehaviour

use of buildcraft.api.transport.pipe.PipeBehaviour in project BuildCraft by BuildCraft.

the class Pipe method updateConnections.

private void updateConnections() {
    if (holder.getPipeWorld().isRemote) {
        return;
    }
    updateMarked = false;
    EnumMap<EnumFacing, Float> old = connected.clone();
    connected.clear();
    types.clear();
    textures.clear();
    for (EnumFacing facing : EnumFacing.VALUES) {
        PipePluggable plug = getHolder().getPluggable(facing);
        if (plug != null && plug.isBlocking()) {
            continue;
        }
        TileEntity oTile = getHolder().getNeighbourTile(facing);
        if (oTile == null) {
            continue;
        }
        IPipe oPipe = getHolder().getNeighbourPipe(facing);
        if (oPipe != null) {
            PipeBehaviour oBehaviour = oPipe.getBehaviour();
            if (oBehaviour == null) {
                continue;
            }
            PipePluggable oPlug = oTile.getCapability(PipeApi.CAP_PLUG, facing.getOpposite());
            if (oPlug == null || !oPlug.isBlocking()) {
                if (canPipesConnect(facing, this, oPipe)) {
                    connected.put(facing, DEFAULT_CONNECTION_DISTANCE);
                    types.put(facing, ConnectedType.PIPE);
                    textures.put(facing, behaviour.getTextureIndex(facing));
                }
                continue;
            }
        }
        BlockPos nPos = holder.getPipePos().offset(facing);
        IBlockState neighbour = holder.getPipeWorld().getBlockState(nPos);
        ICustomPipeConnection cust = PipeConnectionAPI.getCustomConnection(neighbour.getBlock());
        if (cust == null) {
            cust = DefaultPipeConnection.INSTANCE;
        }
        float ext = DEFAULT_CONNECTION_DISTANCE + cust.getExtension(holder.getPipeWorld(), nPos, facing.getOpposite(), neighbour);
        if (behaviour.canConnect(facing, oTile) & flow.canConnect(facing, oTile)) {
            connected.put(facing, ext);
            types.put(facing, ConnectedType.TILE);
            textures.put(facing, behaviour.getTextureIndex(facing));
        }
    }
    if (!old.equals(connected)) {
        for (EnumFacing face : EnumFacing.VALUES) {
            boolean o = old.containsKey(face);
            boolean n = connected.containsKey(face);
            if (o != n) {
                IPipe oPipe = getHolder().getNeighbourPipe(face);
                if (oPipe != null) {
                    oPipe.markForUpdate();
                }
            }
        }
    }
    getHolder().scheduleNetworkUpdate(PipeMessageReceiver.BEHAVIOUR);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) BlockPos(net.minecraft.util.math.BlockPos) ICustomPipeConnection(buildcraft.api.transport.pipe.ICustomPipeConnection) IPipe(buildcraft.api.transport.pipe.IPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Aggregations

IPipe (buildcraft.api.transport.pipe.IPipe)3 PipeBehaviour (buildcraft.api.transport.pipe.PipeBehaviour)3 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 IMjRedstoneReceiver (buildcraft.api.mj.IMjRedstoneReceiver)1 ICustomPipeConnection (buildcraft.api.transport.pipe.ICustomPipeConnection)1 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)1 ContainerDiamondPipe (buildcraft.transport.container.ContainerDiamondPipe)1 ContainerDiamondWoodPipe (buildcraft.transport.container.ContainerDiamondWoodPipe)1 ContainerEmzuliPipe_BC8 (buildcraft.transport.container.ContainerEmzuliPipe_BC8)1 ContainerFilteredBuffer_BC8 (buildcraft.transport.container.ContainerFilteredBuffer_BC8)1 ContainerGate (buildcraft.transport.container.ContainerGate)1 PipeBehaviourDiamond (buildcraft.transport.pipe.behaviour.PipeBehaviourDiamond)1 PipeBehaviourEmzuli (buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli)1 PipeBehaviourWoodDiamond (buildcraft.transport.pipe.behaviour.PipeBehaviourWoodDiamond)1 PluggableGate (buildcraft.transport.plug.PluggableGate)1 PluggablePulsar (buildcraft.transport.plug.PluggablePulsar)1 TileFilteredBuffer (buildcraft.transport.tile.TileFilteredBuffer)1