Search in sources :

Example 1 with ConnectedType

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

Aggregations

IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 IInjectable (buildcraft.api.transport.IInjectable)1 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 ConnectedType (buildcraft.api.transport.pipe.IPipe.ConnectedType)1 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)1 PipeEventItem (buildcraft.api.transport.pipe.PipeEventItem)1 PipeFlow (buildcraft.api.transport.pipe.PipeFlow)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1