Search in sources :

Example 1 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject 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 IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class InvTools method findMatchingItem.

/**
     * Returns a single item from the inventory that matches the
     * filter, but does not remove it.
     *
     * @param inv    the inventory    The inventory
     * @param filter the filter to match against
     * @return An ItemStack
     */
@Nullable
public static ItemStack findMatchingItem(IInventoryComposite inv, Predicate<ItemStack> filter) {
    for (IInventoryObject inventoryObject : inv) {
        InventoryManipulator im = InventoryManipulator.get(inventoryObject);
        ItemStack removed = im.tryRemoveItem(filter);
        if (!isEmpty(removed))
            return removed;
    }
    return emptyStack();
}
Also used : IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) InventoryManipulator(mods.railcraft.common.util.inventory.manipulators.InventoryManipulator) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 3 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class InvTools method moveItemStack.

/**
     * Places an ItemStack in a destination Inventory. Will attempt to move as
     * much of the stack as possible, returning any remainder.
     *
     * @param stack The ItemStack to put in the inventory.
     * @param dest  The destination IInventories.
     * @return Null if itemStack was completely moved, a new itemStack with
     * remaining stackSize if part or none of the stack was moved.
     */
@SuppressWarnings("unused")
@Nullable
public static ItemStack moveItemStack(ItemStack stack, IInventoryComposite dest) {
    for (IInventoryObject inv : dest) {
        InventoryManipulator im = InventoryManipulator.get(inv);
        stack = im.addStack(stack);
        if (isEmpty(stack))
            return emptyStack();
    }
    return stack;
}
Also used : IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) InventoryManipulator(mods.railcraft.common.util.inventory.manipulators.InventoryManipulator) Nullable(javax.annotation.Nullable)

Example 4 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject 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 5 with IInventoryObject

use of mods.railcraft.common.util.inventory.wrappers.IInventoryObject in project Railcraft by Railcraft.

the class InvTools method moveOneItem.

/**
     * Attempts to move a single item from one inventory to another.
     *
     * @param source the source inventory
     * @param dest   the destination inventory
     * @param filter Predicate to match against
     * @return null if nothing was moved, the stack moved otherwise
     */
@Nullable
public static ItemStack moveOneItem(IInventoryComposite source, IInventoryComposite dest, Predicate<ItemStack> filter) {
    for (IInventoryObject src : source) {
        for (IInventoryObject dst : dest) {
            InventoryManipulator imSource = InventoryManipulator.get(src);
            ItemStack moved = imSource.moveItem(dst, filter);
            if (!isEmpty(moved))
                return moved;
        }
    }
    return emptyStack();
}
Also used : IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) InventoryManipulator(mods.railcraft.common.util.inventory.manipulators.InventoryManipulator) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

IInventoryObject (mods.railcraft.common.util.inventory.wrappers.IInventoryObject)9 ItemStack (net.minecraft.item.ItemStack)7 Nullable (javax.annotation.Nullable)4 InventoryManipulator (mods.railcraft.common.util.inventory.manipulators.InventoryManipulator)4 IInvSlot (mods.railcraft.common.util.inventory.iterators.IInvSlot)3 Nonnull (javax.annotation.Nonnull)1 StackKey (mods.railcraft.common.util.collections.StackKey)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 IInventory (net.minecraft.inventory.IInventory)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Contract (org.jetbrains.annotations.Contract)1