Search in sources :

Example 6 with IPipe

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

the class PipeFlowItems method onItemReachEnd.

private void onItemReachEnd(TravellingItem item) {
    IPipeHolder holder = pipe.getHolder();
    PipeEventItem.ReachEnd reachEnd = new PipeEventItem.ReachEnd(holder, this, item.colour, item.stack, item.side);
    holder.fireEvent(reachEnd);
    item.colour = reachEnd.colour;
    item.stack = reachEnd.getStack();
    ItemStack excess = item.stack;
    if (excess.isEmpty()) {
        return;
    }
    if (pipe.isConnected(item.side)) {
        ConnectedType type = pipe.getConnectedType(item.side);
        EnumFacing oppositeSide = item.side.getOpposite();
        switch(type) {
            case PIPE:
                {
                    IPipe oPipe = pipe.getConnectedPipe(item.side);
                    if (oPipe == null) {
                        break;
                    }
                    PipeFlow flow = oPipe.getFlow();
                    if (flow instanceof IFlowItems) {
                        IFlowItems oFlow = (IFlowItems) flow;
                        ItemStack before = excess;
                        excess = oFlow.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
                        if (!excess.isEmpty()) {
                            before.shrink(excess.getCount());
                        }
                        excess = fireEventEjectIntoPipe(oFlow, item.side, before, excess);
                    }
                    break;
                }
            case TILE:
                {
                    TileEntity tile = pipe.getConnectedTile(item.side);
                    IInjectable injectable = ItemTransactorHelper.getInjectable(tile, oppositeSide);
                    ItemStack before = excess;
                    excess = injectable.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
                    if (!excess.isEmpty()) {
                        IItemTransactor transactor = ItemTransactorHelper.getTransactor(tile, oppositeSide);
                        excess = transactor.insert(excess, false, false);
                    }
                    excess = fireEventEjectIntoTile(tile, item.side, before, excess);
                    break;
                }
        }
    }
    if (excess.isEmpty()) {
        return;
    }
    item.tried.add(item.side);
    item.toCenter = true;
    item.stack = excess;
    item.genTimings(holder.getPipeWorld().getTotalWorldTime(), getPipeLength(item.side));
    items.add(item.timeToDest, item);
    sendItemDataToClient(item);
}
Also used : IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) EnumFacing(net.minecraft.util.EnumFacing) PipeFlow(buildcraft.api.transport.pipe.PipeFlow) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ConnectedType(buildcraft.api.transport.pipe.IPipe.ConnectedType) TileEntity(net.minecraft.tileentity.TileEntity) IItemTransactor(buildcraft.api.inventory.IItemTransactor) IInjectable(buildcraft.api.transport.IInjectable) PipeEventItem(buildcraft.api.transport.pipe.PipeEventItem) ItemStack(net.minecraft.item.ItemStack) IPipe(buildcraft.api.transport.pipe.IPipe)

Example 7 with IPipe

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

the class FilterEventHandler method sideCheck.

@PipeEventHandler
public static void sideCheck(PipeEventItem.SideCheck event) {
    for (EnumFacing side : EnumFacing.VALUES) {
        if (!event.isAllowed(side)) {
            continue;
        }
        IPipe neighbour = event.holder.getNeighbourPipe(side);
        if (neighbour == null) {
            continue;
        }
        PipePluggable neighbourPlug = neighbour.getHolder().getPluggable(side.getOpposite());
        PipePluggable atPlug = event.holder.getPluggable(side);
        if (neighbourPlug instanceof PluggableLens) {
            EnumDyeColor colourAt = event.colour;
            if (atPlug instanceof PluggableLens) {
                PluggableLens lens = (PluggableLens) atPlug;
                if (!lens.isFilter) {
                    colourAt = lens.colour;
                }
            }
            PluggableLens lens = (PluggableLens) neighbourPlug;
            if (lens.isFilter) {
                if (colourAt == lens.colour) {
                    event.increasePriority(side);
                } else if (colourAt == null) {
                    event.decreasePriority(side);
                }
            }
        }
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) IPipe(buildcraft.api.transport.pipe.IPipe) EnumDyeColor(net.minecraft.item.EnumDyeColor) PipeEventHandler(buildcraft.api.transport.pipe.PipeEventHandler)

Example 8 with IPipe

use of buildcraft.api.transport.pipe.IPipe 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)

Example 9 with IPipe

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

the class WireSystem method canWireConnect.

/**
 * Checks to see if the given holder could connect a wire across the specified side even if a matching wire wasn't
 * there.
 */
public static boolean canWireConnect(IPipeHolder holder, EnumFacing side) {
    // TODO: Expand to pipeless wires (8.1.x)
    IPipe pipe = holder.getPipe();
    if (pipe == null) {
        return false;
    }
    IPipe oPipe = holder.getNeighbourPipe(side);
    if (oPipe == null) {
        return false;
    }
    if (pipe.isConnected(side)) {
        return true;
    }
    if (// 
    (holder.getPluggable(side) != null && holder.getPluggable(side).isBlocking()) || (oPipe.getHolder().getPluggable(side.getOpposite()) != null && oPipe.getHolder().getPluggable(side.getOpposite()).isBlocking())) {
        return false;
    }
    if (pipe.getDefinition().flowType == PipeApi.flowStructure || oPipe.getDefinition().flowType == PipeApi.flowStructure) {
        return pipe.getColour() == null || oPipe.getColour() == null || pipe.getColour() == oPipe.getColour();
    }
    return false;
}
Also used : IPipe(buildcraft.api.transport.pipe.IPipe)

Aggregations

IPipe (buildcraft.api.transport.pipe.IPipe)9 EnumFacing (net.minecraft.util.EnumFacing)6 TileEntity (net.minecraft.tileentity.TileEntity)4 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)3 PipeBehaviour (buildcraft.api.transport.pipe.PipeBehaviour)3 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)3 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)2 BlockPos (net.minecraft.util.math.BlockPos)2 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 IMjReceiver (buildcraft.api.mj.IMjReceiver)1 IMjRedstoneReceiver (buildcraft.api.mj.IMjRedstoneReceiver)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IInjectable (buildcraft.api.transport.IInjectable)1 IWireManager (buildcraft.api.transport.IWireManager)1 ICustomPipeConnection (buildcraft.api.transport.pipe.ICustomPipeConnection)1 ConnectedType (buildcraft.api.transport.pipe.IPipe.ConnectedType)1 PipeEventHandler (buildcraft.api.transport.pipe.PipeEventHandler)1 PipeEventItem (buildcraft.api.transport.pipe.PipeEventItem)1 PipeFlow (buildcraft.api.transport.pipe.PipeFlow)1 PluggableDefinition (buildcraft.api.transport.pluggable.PluggableDefinition)1