Search in sources :

Example 1 with PipeFlow

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

the class PipeBehaviourObsidian method trySuckEntity.

/**
 * @return The left over power
 */
protected long trySuckEntity(Entity entity, EnumFacing faceFrom, long power, boolean simulate) {
    if (entity.isDead || entity instanceof EntityLivingBase) {
        return power;
    }
    Long tickPickupObj = entityDropTime.get(entity);
    if (tickPickupObj != null) {
        long tickPickup = tickPickupObj;
        long tickNow = pipe.getHolder().getPipeWorld().getTotalWorldTime();
        if (tickNow < tickPickup) {
            return power;
        } else {
            entityDropTime.remove(entity);
        }
    }
    PipeFlow flow = pipe.getFlow();
    IFlowItems flowItem = flow instanceof IFlowItems ? (IFlowItems) flow : null;
    IFlowFluid flowFluid = flow instanceof IFlowFluid ? (IFlowFluid) flow : null;
    IItemTransactor transactor = ItemTransactorHelper.getTransactorForEntity(entity, faceFrom.getOpposite());
    if (flowItem != null) {
        double distance = Math.sqrt(entity.getDistanceSqToCenter(pipe.getHolder().getPipePos()));
        long powerReqPerItem = (long) (distance * POWER_PER_METRE + POWER_PER_ITEM);
        int max = power == 0 ? 1 : (int) (power / powerReqPerItem);
        ItemStack extracted = transactor.extract(StackFilter.ALL, 1, max, simulate);
        if (!extracted.isEmpty()) {
            if (!simulate) {
                flowItem.insertItemsForce(extracted, faceFrom, null, INSERT_SPEED);
            }
            return power - powerReqPerItem * extracted.getCount();
        }
    }
    if (flowFluid != null) {
    // TODO: Fluid extraction!
    }
    return power;
}
Also used : IItemTransactor(buildcraft.api.inventory.IItemTransactor) PipeFlow(buildcraft.api.transport.pipe.PipeFlow) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ItemStack(net.minecraft.item.ItemStack)

Example 2 with PipeFlow

use of buildcraft.api.transport.pipe.PipeFlow 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)2 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)2 PipeFlow (buildcraft.api.transport.pipe.PipeFlow)2 ItemStack (net.minecraft.item.ItemStack)2 IInjectable (buildcraft.api.transport.IInjectable)1 IFlowFluid (buildcraft.api.transport.pipe.IFlowFluid)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 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1