Search in sources :

Example 1 with ITransactor

use of buildcraft.core.lib.inventory.ITransactor in project BuildCraft by BuildCraft.

the class PipeItemsObsidian method suckItem.

private boolean suckItem(int distance) {
    EnumFacing openOrientation = getOpenOrientation();
    if (openOrientation == null) {
        return false;
    }
    AxisAlignedBB box = getSuckingBox(openOrientation, distance);
    if (box == null) {
        return false;
    }
    List<Entity> discoveredEntities = container.getWorld().getEntitiesWithinAABB(Entity.class, box);
    for (Entity entity : discoveredEntities) {
        if (canSuck(entity, distance)) {
            pullItemIntoPipe(entity, distance);
            return true;
        }
        if (distance == 1 && entity instanceof EntityMinecart && entity instanceof IInventory) {
            EntityMinecart cart = (EntityMinecart) entity;
            if (!cart.isDead) {
                ITransactor trans = Transactor.getTransactorFor(cart, openOrientation);
                ItemStack stack = trans.remove(StackFilter.ALL, false);
                if (stack != null && battery.useEnergy(10, 10, false) > 0) {
                    stack = trans.remove(StackFilter.ALL, true);
                    if (stack != null) {
                        TravelingItem item = TravelingItem.make(0.5f, stack);
                        return transport.injectItem(item, openOrientation.getOpposite(), true);
                    }
                }
            }
        }
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IInventory(net.minecraft.inventory.IInventory) Entity(net.minecraft.entity.Entity) EnumFacing(net.minecraft.util.EnumFacing) TravelingItem(buildcraft.transport.TravelingItem) ItemStack(net.minecraft.item.ItemStack) EntityMinecart(net.minecraft.entity.item.EntityMinecart) ITransactor(buildcraft.core.lib.inventory.ITransactor)

Example 2 with ITransactor

use of buildcraft.core.lib.inventory.ITransactor in project BuildCraft by BuildCraft.

the class TileChute method update.

@Override
public void update() {
    super.update();
    if (worldObj.isRemote || isEmpty || worldObj.getTotalWorldTime() % 2 != 0) {
        return;
    }
    TileEntity outputTile = getTile(EnumFacing.DOWN);
    ITransactor transactor = Transactor.getTransactorFor(outputTile, EnumFacing.UP);
    if (transactor == null) {
        if (outputTile instanceof IInjectable && getBattery().getEnergyStored() >= 10) {
            ItemStack stackToOutput = null;
            int internalSlot = 0;
            getBattery().useEnergy(10, 10, false);
            for (; internalSlot < inventory.getSizeInventory(); internalSlot++) {
                ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
                if (stackInSlot == null || stackInSlot.stackSize == 0) {
                    continue;
                }
                stackToOutput = stackInSlot.copy();
                stackToOutput.stackSize = 1;
                break;
            }
            if (stackToOutput != null) {
                int used = ((IInjectable) outputTile).injectItem(stackToOutput, true, EnumFacing.UP, null);
                if (used > 0) {
                    decrStackSize(internalSlot, 1);
                }
            }
        }
        return;
    }
    for (int internalSlot = 0; internalSlot < inventory.getSizeInventory(); internalSlot++) {
        ItemStack stackInSlot = inventory.getStackInSlot(internalSlot);
        if (stackInSlot == null || stackInSlot.stackSize == 0) {
            continue;
        }
        ItemStack clonedStack = stackInSlot.copy().splitStack(1);
        if (transactor.addNew(clonedStack, true).stackSize > 0) {
            inventory.decrStackSize(internalSlot, 1);
            return;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInjectable(buildcraft.api.transport.IInjectable) ItemStack(net.minecraft.item.ItemStack) ITransactor(buildcraft.core.lib.inventory.ITransactor)

Example 3 with ITransactor

use of buildcraft.core.lib.inventory.ITransactor in project BuildCraft by BuildCraft.

the class AIRobotLoad method load.

public static boolean load(EntityRobotBase robot, DockingStation station, IStackFilter filter, int quantity, boolean doLoad) {
    if (station == null) {
        return false;
    }
    int loaded = 0;
    IInventory tileInventory = station.getItemInput();
    if (tileInventory == null) {
        return false;
    }
    for (IInvSlot slot : InventoryIterator.getIterable(tileInventory, station.getItemInputSide().face)) {
        ItemStack stack = slot.getStackInSlot();
        if (// 
        stack == null || // 
        !slot.canTakeStackFromSlot(stack) || // 
        !filter.matches(stack) || // 
        !ActionStationProvideItems.canExtractItem(station, stack) || !ActionRobotFilter.canInteractWithItem(station, filter, ActionStationProvideItems.class)) {
            continue;
        }
        ITransactor robotTransactor = Transactor.getTransactorFor(robot, null);
        if (quantity == ANY_QUANTITY) {
            ItemStack added = robotTransactor.addNew(slot.getStackInSlot(), doLoad);
            if (doLoad) {
                slot.decreaseStackInSlot(added.stackSize);
            }
            return added.stackSize > 0;
        } else {
            ItemStack toAdd = slot.getStackInSlot().copy();
            if (toAdd.stackSize > quantity - loaded) {
                toAdd.stackSize = quantity - loaded;
            }
            ItemStack added = robotTransactor.addNew(toAdd, doLoad);
            if (doLoad) {
                slot.decreaseStackInSlot(added.stackSize);
            }
            loaded += added.stackSize;
            if (quantity - loaded <= 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IInvSlot(buildcraft.api.core.IInvSlot) ItemStack(net.minecraft.item.ItemStack) ITransactor(buildcraft.core.lib.inventory.ITransactor)

Example 4 with ITransactor

use of buildcraft.core.lib.inventory.ITransactor in project BuildCraft by BuildCraft.

the class Utils method addToRandomInventoryAround.

/**
 * Tries to add the passed stack to any valid inventories around the given coordinates.
 *
 * @param stack
 * @param world
 * @param x
 * @param y
 * @param z
 * @return amount used
 */
public static int addToRandomInventoryAround(World world, BlockPos pos, ItemStack stack) {
    Collections.shuffle(directions);
    for (EnumFacing orientation : directions) {
        BlockPos newpos = pos.offset(orientation);
        TileEntity tile = world.getTileEntity(newpos);
        ITransactor transactor = Transactor.getTransactorFor(tile, orientation.getOpposite());
        if (transactor != null && !(tile instanceof IEngine) && transactor.insert(stack, false).stackSize > 0) {
            // UP!
            return transactor.insert(stack, true).stackSize;
        }
    }
    return 0;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IEngine(buildcraft.api.power.IEngine) ITransactor(buildcraft.core.lib.inventory.ITransactor)

Example 5 with ITransactor

use of buildcraft.core.lib.inventory.ITransactor in project BuildCraft by BuildCraft.

the class PipeTransportItems method handleTileReached.

private void handleTileReached(TravelingItem item, TileEntity tile) {
    if (passToNextPipe(item, tile)) {
    // NOOP
    } else {
        boolean handled = false;
        if (!container.getWorld().isRemote) {
            if (item.getInsertionHandler().canInsertItem(item, tile)) {
                ITransactor transactor = Transactor.getTransactorFor(tile, item.output.getOpposite());
                if (transactor != null) {
                    handled = true;
                    ItemStack added = transactor.addNew(item.getItemStack(), true);
                    item.getItemStack().stackSize -= added.stackSize;
                }
            }
            if (!handled) {
                dropItem(item);
            } else if (item.getItemStack().stackSize > 0) {
                reverseItem(item);
            }
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) ITransactor(buildcraft.core.lib.inventory.ITransactor)

Aggregations

ITransactor (buildcraft.core.lib.inventory.ITransactor)6 ItemStack (net.minecraft.item.ItemStack)5 IInventory (net.minecraft.inventory.IInventory)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 IInvSlot (buildcraft.api.core.IInvSlot)1 IEngine (buildcraft.api.power.IEngine)1 IInjectable (buildcraft.api.transport.IInjectable)1 TravelingItem (buildcraft.transport.TravelingItem)1 Entity (net.minecraft.entity.Entity)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1 EntityTNTPrimed (net.minecraft.entity.item.EntityTNTPrimed)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1