Search in sources :

Example 1 with IInvSlot

use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.

the class FirestoneTickHandler method tick.

@SubscribeEvent
public void tick(LivingEvent.LivingUpdateEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    if (Game.isClient(entity.worldObj))
        return;
    clock++;
    if (clock % 4 != 0)
        return;
    if (entity instanceof EntityPlayer && ((EntityPlayer) entity).openContainer != ((EntityPlayer) entity).inventoryContainer)
        return;
    IInventoryObject inv = InventoryFactory.get(entity);
    if (inv != null) {
        for (IInvSlot slot : InventoryIterator.getRailcraft(inv)) {
            ItemStack stack = slot.getStack();
            FirestoneTools.trySpawnFire(entity.worldObj, entity.getPosition(), stack);
        }
    }
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IInvSlot

use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.

the class InvTools method acceptsItemStack.

/**
     * Checks if inventory will accept the ItemStack.
     *
     * @param stack The ItemStack
     * @param dest  The IInventory
     * @return true if room for stack
     */
@Contract("null,_ -> false;")
public static boolean acceptsItemStack(@Nullable ItemStack stack, IInventoryComposite dest) {
    if (isEmpty(stack))
        return false;
    ItemStack newStack = stack.copy();
    newStack.stackSize = 1;
    for (IInventoryObject inv : dest) {
        for (IInvSlot slot : InventoryIterator.getRailcraft(inv)) {
            if (slot.canPutStackInSlot(stack))
                return true;
        }
    }
    return false;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) ItemStack(net.minecraft.item.ItemStack) Contract(org.jetbrains.annotations.Contract)

Example 3 with IInvSlot

use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.

the class ItemHandlerInventoryManipulator method removeItem.

@Nonnull
@Override
protected List<ItemStack> removeItem(Predicate<ItemStack> filter, int maxAmount, boolean doRemove) {
    int amountNeeded = maxAmount;
    List<ItemStack> outputList = new ArrayList<ItemStack>();
    for (IInvSlot slot : this) {
        if (amountNeeded <= 0)
            break;
        ItemStack stack = slot.getStack();
        if (!isEmpty(stack) && slot.canTakeStackFromSlot(stack) && filter.test(stack)) {
            ItemStack removed = inv.extractItem(slot.getIndex(), amountNeeded, !doRemove);
            if (!isEmpty(removed)) {
                amountNeeded -= removed.stackSize;
                outputList.add(removed);
            }
        }
    }
    return outputList;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with IInvSlot

use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.

the class ItemHandlerInventoryManipulator method addStack.

@Override
protected ItemStack addStack(ItemStack stack, boolean doAdd) {
    if (isEmpty(stack))
        return emptyStack();
    stack = stack.copy();
    List<IInvSlot> filledSlots = new ArrayList<IInvSlot>(inv.getSlots());
    List<IInvSlot> emptySlots = new ArrayList<IInvSlot>(inv.getSlots());
    for (IInvSlot slot : InventoryIterator.getForge(inv)) {
        if (slot.canPutStackInSlot(stack)) {
            if (isEmpty(slot.getStack()))
                emptySlots.add(slot);
            else
                filledSlots.add(slot);
        }
    }
    int injected = 0;
    injected = tryPut(filledSlots, stack, injected, doAdd);
    injected = tryPut(emptySlots, stack, injected, doAdd);
    stack.stackSize -= injected;
    if (stack.stackSize <= 0)
        return emptyStack();
    return stack;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) ArrayList(java.util.ArrayList)

Example 5 with IInvSlot

use of mods.railcraft.common.util.inventory.iterators.IInvSlot in project Railcraft by Railcraft.

the class ItemHandlerInventoryManipulator method tryPut.

private int tryPut(List<IInvSlot> slots, ItemStack stack, int injected, boolean doAdd) {
    if (injected >= stack.stackSize)
        return injected;
    for (IInvSlot slot : slots) {
        ItemStack stackToInsert = stack.copy();
        int amountToInsert = stack.stackSize - injected;
        stackToInsert.stackSize = amountToInsert;
        ItemStack remainder = inv.insertItem(slot.getIndex(), stackToInsert, !doAdd);
        if (remainder == null)
            return stack.stackSize;
        injected += amountToInsert - remainder.stackSize;
        if (injected >= stack.stackSize)
            return injected;
    }
    return injected;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IInvSlot (mods.railcraft.common.util.inventory.iterators.IInvSlot)11 ItemStack (net.minecraft.item.ItemStack)9 IInventoryObject (mods.railcraft.common.util.inventory.wrappers.IInventoryObject)3 ArrayList (java.util.ArrayList)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ICrusherCraftingManager (mods.railcraft.api.crafting.ICrusherCraftingManager)1 StackKey (mods.railcraft.common.util.collections.StackKey)1 InventoryCopy (mods.railcraft.common.util.inventory.wrappers.InventoryCopy)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 BlockPos (net.minecraft.util.math.BlockPos)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Contract (org.jetbrains.annotations.Contract)1