Search in sources :

Example 21 with ISidedInventory

use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.

the class TileRegulator method isSatisfied.

/**
     * Returns true if the supplying inventory has the items stated in the output filter.
     * 
     * @return
     */
private boolean isSatisfied() {
    IInventory inv = IOHelper.getInventoryForTE(getTileCache(getOutputDirection()));
    if (inv != null) {
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(getFacingDirection().ordinal());
        } else {
            accessibleSlots = new int[inv.getSizeInventory()];
            for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
        }
        boolean everythingNull = true;
        for (int i = 18; i < 27; i++) {
            if (inventory[i] != null) {
                everythingNull = false;
                int outputFilterItems = getItemsInSection(inventory[i], EnumSection.OUTPUT_FILTER);
                int supplyingInvCount = 0;
                for (int slot : accessibleSlots) {
                    ItemStack stackInSlot = inv.getStackInSlot(slot);
                    if (stackInSlot != null && ItemStackHelper.areStacksEqual(stackInSlot, inventory[i], fuzzySetting) && IOHelper.canInsertItemToInventory(inv, inventory[i], slot, getFacingDirection().ordinal())) {
                        supplyingInvCount += stackInSlot.stackSize;
                    }
                }
                if (supplyingInvCount < outputFilterItems)
                    return false;
            }
        }
        return !everythingNull;
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ISidedInventory (net.minecraft.inventory.ISidedInventory)21 ItemStack (net.minecraft.item.ItemStack)18 IInventory (net.minecraft.inventory.IInventory)13 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)3 SidedInventoryMinecraftAdapter (logisticspipes.utils.SidedInventoryMinecraftAdapter)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ISlotUpgradeManager (logisticspipes.interfaces.ISlotUpgradeManager)2 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 Side (cpw.mods.fml.relauncher.Side)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 IMetaTileEntity (gregtech.api.interfaces.metatileentity.IMetaTileEntity)1 IMetaTileEntityItemPipe (gregtech.api.interfaces.metatileentity.IMetaTileEntityItemPipe)1 ICoverable (gregtech.api.interfaces.tileentity.ICoverable)1 IGregTechTileEntity (gregtech.api.interfaces.tileentity.IGregTechTileEntity)1 WeakReference (java.lang.ref.WeakReference)1 Map (java.util.Map)1