Search in sources :

Example 21 with IInventory

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

the class SearchUpgradeHandler method checkInventoryForItems.

/**
     * This method will be called by the BlockTrackUpgradeHandler when it finds inventories while scanning blocks.
     * @param te TileEntity that already has been checked on if it implements IInventory, so it's save to cast it to IInventory.
     */
public void checkInventoryForItems(TileEntity te) {
    try {
        ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().thePlayer.getCurrentArmor(3));
        IInventory inventory = (IInventory) te;
        boolean hasFoundItem = false;
        if (searchStack != null) {
            for (int l = 0; l < inventory.getSizeInventory(); l++) {
                if (inventory.getStackInSlot(l) != null) {
                    int items = RenderSearchItemBlock.getSearchedItemCount(inventory.getStackInSlot(l), searchStack);
                    if (items > 0) {
                        hasFoundItem = true;
                        searchedItemCounter += items;
                    }
                }
            }
        }
        if (hasFoundItem) {
            boolean inList = false;
            for (RenderSearchItemBlock trackedBlock : searchedBlocks) {
                if (trackedBlock.isAlreadyTrackingCoord(te.xCoord, te.yCoord, te.zCoord)) {
                    inList = true;
                    break;
                }
            }
            if (!inList)
                searchedBlocks.add(new RenderSearchItemBlock(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord));
        }
    } catch (Throwable e) {
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 22 with IInventory

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

the class BlockTrackEntryInventory method addInformation.

@Override
public void addInformation(World world, int x, int y, int z, TileEntity te, List<String> infoList) {
    try {
        IInventory inventory = IOHelper.getInventoryForTE(te);
        if (inventory != null) {
            boolean empty = true;
            ItemStack[] inventoryStacks = new ItemStack[inventory.getSizeInventory()];
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack iStack = inventory.getStackInSlot(i);
                if (iStack != null)
                    empty = false;
                inventoryStacks[i] = iStack;
            }
            if (empty) {
                infoList.add("Contents: Empty");
            } else {
                infoList.add("Contents:");
                PneumaticCraftUtils.sortCombineItemStacksAndToString(infoList, inventoryStacks);
            }
        }
    } catch (Throwable e) {
        addTileEntityToBlackList(te, e);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack)

Example 23 with IInventory

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

the class LogisticsManager method getRequestedAmount.

public static int getRequestedAmount(SemiBlockLogistics requester, ItemStack providingStack) {
    TileEntity te = requester.getTileEntity();
    if (!(te instanceof IInventory))
        return 0;
    int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.stackSize;
    if (requestedAmount == 0)
        return 0;
    providingStack = providingStack.copy();
    providingStack.stackSize = requestedAmount;
    ItemStack remainder = providingStack.copy();
    remainder.stackSize += requester.getIncomingItems(providingStack);
    for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
        remainder = IOHelper.insert(te, remainder, d, true);
        if (remainder == null)
            break;
    }
    if (remainder != null)
        providingStack.stackSize -= remainder.stackSize;
    if (providingStack.stackSize <= 0)
        return 0;
    return providingStack.stackSize;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificRequester(pneumaticCraft.common.semiblock.ISpecificRequester) ItemStack(net.minecraft.item.ItemStack)

Example 24 with IInventory

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

the class LogisticsManager method tryProvide.

//curAI = new DroneAILiquidImport(drone, new FakeWidgetLogistics(provider.getPos(), providingStack));
// transportingFluid = new FluidStackWrapper(providingStack);
private void tryProvide(SemiBlockLogistics provider, SemiBlockLogistics requester, PriorityQueue<LogisticsTask> tasks) {
    IInventory providingInventory = IOHelper.getInventoryForTE(provider.getTileEntity());
    if (providingInventory != null) {
        if (requester instanceof IProvidingInventoryListener)
            ((IProvidingInventoryListener) requester).notify(provider.getTileEntity());
        for (int i = 0; i < providingInventory.getSizeInventory(); i++) {
            ItemStack providingStack = providingInventory.getStackInSlot(i);
            if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && IOHelper.canExtractItemFromInventory(providingInventory, providingStack, i, 0)) {
                int requestedAmount = getRequestedAmount(requester, providingStack);
                if (requestedAmount > 0) {
                    ItemStack stack = providingStack.copy();
                    stack.stackSize = requestedAmount;
                    tasks.add(new LogisticsTask(provider, requester, stack));
                }
            }
        }
    }
    if (provider.getTileEntity() instanceof IFluidHandler) {
        IFluidHandler providingTank = (IFluidHandler) provider.getTileEntity();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            FluidStack providingStack = providingTank.drain(d, 16000, false);
            if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && providingTank.canDrain(d, providingStack.getFluid())) {
                int requestedAmount = getRequestedAmount(requester, providingStack);
                if (requestedAmount > 0) {
                    FluidStack stack = providingStack.copy();
                    stack.amount = requestedAmount;
                    tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(stack)));
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidStack(net.minecraftforge.fluids.FluidStack) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ISpecificProvider(pneumaticCraft.common.semiblock.ISpecificProvider) IProvidingInventoryListener(pneumaticCraft.common.semiblock.IProvidingInventoryListener) FluidStackWrapper(pneumaticCraft.common.semiblock.SemiBlockLogistics.FluidStackWrapper) ItemStack(net.minecraft.item.ItemStack) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 25 with IInventory

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

the class BlockPneumaticCraft method dropInventory.

protected 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;
    Random rand = new Random();
    for (int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {
        ItemStack itemStack = inventory.getStackInSlot(i);
        if (itemStack != null && itemStack.stackSize > 0) {
            float dX = rand.nextFloat() * 0.8F + 0.1F;
            float dY = rand.nextFloat() * 0.8F + 0.1F;
            float dZ = rand.nextFloat() * 0.8F + 0.1F;
            EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
            if (itemStack.hasTagCompound()) {
                entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
            }
            float factor = 0.05F;
            entityItem.motionX = rand.nextGaussian() * factor;
            entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
            entityItem.motionZ = rand.nextGaussian() * factor;
            world.spawnEntityInWorld(entityItem);
            itemStack.stackSize = 0;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) Random(java.util.Random) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

IInventory (net.minecraft.inventory.IInventory)123 ItemStack (net.minecraft.item.ItemStack)78 TileEntity (net.minecraft.tileentity.TileEntity)53 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