Search in sources :

Example 91 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class TileEntityAssemblyIOUnit method getItemFromCurrentDirection.

private boolean getItemFromCurrentDirection() {
    TileEntity tile = getTileEntityForCurrentDirection();
    boolean extracted = false;
    if (isImportUnit()) {
        if (searchedItemStack == null) {
            // we don't know what we're supposed to pick up
            reset();
        } else if (tile instanceof IInventory) {
            IInventory inv = (IInventory) tile;
            int oldStackSize = inventory[0] == null ? 0 : inventory[0].stackSize;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                if (inv.getStackInSlot(i) != null) {
                    if (inventory[0] == null) {
                        if (inv.getStackInSlot(i).isItemEqual(searchedItemStack)) {
                            inventory[0] = inv.decrStackSize(i, 1);
                        }
                    } else if (inv.getStackInSlot(i).isItemEqual(inventory[0])) {
                        inv.decrStackSize(i, 1);
                        inventory[0].stackSize++;
                    }
                    // we might need to pickup more than 1 item
                    extracted = (inventory[0] == null ? 0 : inventory[0].stackSize) == searchedItemStack.stackSize;
                    if (extracted)
                        break;
                }
            }
            if (// nothing picked up, search for different inventory
            oldStackSize == (inventory[0] == null ? 0 : inventory[0].stackSize))
                state = STATE_SEARCH_SRC;
        } else
            // inventory gone
            state = STATE_SEARCH_SRC;
    } else {
        if (tile instanceof TileEntityAssemblyPlatform) {
            TileEntityAssemblyPlatform plat = (TileEntityAssemblyPlatform) tile;
            if (plat.openClaw()) {
                inventory[0] = plat.getHeldStack();
                plat.setHeldStack(null);
                extracted = inventory[0] != null;
                if (// something went wrong - either the platform is gone altogether, or the item is not there anymore
                !extracted)
                    state = STATE_SEARCH_SRC;
            }
        }
    }
    return extracted;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory)

Example 92 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class IOHelper method dropInventory.

public static void dropInventory(World world, int x, int y, int z) {
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (!(tileEntity instanceof IInventory)) {
        return;
    }
    IInventory inventory = (IInventory) tileEntity;
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        ItemStack itemStack = inventory.getStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            spawnItemInWorld(world, itemStack, x, y, z);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 93 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class IOHelper method insert.

/**
     * Inserts on all sides
     * @param tile
     * @param itemStack
     * @param simulate
     * @return
     */
public static ItemStack insert(TileEntity tile, ItemStack itemStack, boolean simulate) {
    IInventory inv = getInventoryForTE(tile);
    ItemStack insertingStack = itemStack.copy();
    for (int i = 0; i < 6; i++) {
        insertingStack = insert(inv, insertingStack, i, simulate);
        if (insertingStack == null || insertingStack.stackSize != itemStack.stackSize)
            return insertingStack;
    }
    return insertingStack;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 94 with IInventory

use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.

the class IOHelper method getInventoryForTE.

public static IInventory getInventoryForTE(TileEntity te) {
    if (te instanceof IInventory) {
        IInventory inv = (IInventory) te;
        Block block = te.getBlockType();
        if (block instanceof BlockChest) {
            inv = ((BlockChest) block).func_149951_m(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
        }
        return inv;
    } else {
        return null;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) BlockChest(net.minecraft.block.BlockChest) Block(net.minecraft.block.Block)

Example 95 with IInventory

use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.

the class PipeItemsBasicLogistics method getPointedInventory.

@Override
public IInventoryUtil getPointedInventory(boolean forExtraction) {
    IInventoryUtil inv = super.getPointedInventory(forExtraction);
    if (inv == null) {
        Optional<Pair<IInventory, ForgeDirection>> first = new WorldCoordinatesWrapper(container).getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacentInventory -> new Pair<>(InventoryHelper.getInventory((IInventory) adjacentInventory.tileEntity), adjacentInventory.direction)).filter(inventoryDirectionPair -> inventoryDirectionPair.getValue1() != null).findFirst();
        if (first.isPresent()) {
            Pair<IInventory, ForgeDirection> p = first.get();
            inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(p.getValue1(), p.getValue2().getOpposite());
        }
    }
    return inv;
}
Also used : OrientationsUtil(logisticspipes.utils.OrientationsUtil) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) TreeSet(java.util.TreeSet) LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) LogisticsSecurityTileEntity(logisticspipes.blocks.LogisticsSecurityTileEntity) InventoryHelper(logisticspipes.utils.InventoryHelper) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Set(java.util.Set) TextureType(logisticspipes.textures.Textures.TextureType) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) PipeTransportLogistics(logisticspipes.transport.PipeTransportLogistics) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ModuleItemSink(logisticspipes.modules.ModuleItemSink) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Aggregations

IInventory (net.minecraft.inventory.IInventory)129 ItemStack (net.minecraft.item.ItemStack)80 TileEntity (net.minecraft.tileentity.TileEntity)59 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)21 ArrayList (java.util.ArrayList)18 ISidedInventory (net.minecraft.inventory.ISidedInventory)13 EntityItem (net.minecraft.entity.item.EntityItem)12 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)10 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 WorldCoordinatesWrapper (network.rs485.logisticspipes.world.WorldCoordinatesWrapper)9 AMVector3 (am2.api.math.AMVector3)8 List (java.util.List)8 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)8 SinkReply (logisticspipes.utils.SinkReply)8 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)8 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)7