Search in sources :

Example 6 with IInvSlot

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

the class InvTools method findMatchingItems.

/**
     * Returns all items from the inventory that match the
     * filter, but does not remove them.
     * The resulting set will be populated with a single instance of each item type.
     *
     * @param inv    the inventory    The inventory
     * @param filter EnumItemType to match against
     * @return A Set of ItemStacks
     */
@Nonnull
public static Set<StackKey> findMatchingItems(IInventoryComposite inv, Predicate<ItemStack> filter) {
    Set<StackKey> items = CollectionTools.createItemStackSet();
    for (IInventoryObject inventoryObject : inv) {
        for (IInvSlot slot : InventoryIterator.getRailcraft(inventoryObject)) {
            ItemStack stack = slot.getStack();
            if (!isEmpty(stack) && filter.test(stack)) {
                stack = stack.copy();
                stack.stackSize = 1;
                items.add(StackKey.make(stack));
            }
        }
    }
    return items;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) StackKey(mods.railcraft.common.util.collections.StackKey) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 7 with IInvSlot

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

the class CartDisassemblyRecipe method matches.

@Override
public boolean matches(InventoryCrafting grid, World worldIn) {
    int itemCount = 0;
    boolean foundCart = false;
    for (IInvSlot slot : InventoryIterator.getVanilla(grid)) {
        if (slot.hasStack()) {
            if (slot.containsItem(fullCart))
                foundCart = true;
            itemCount++;
        }
    }
    return itemCount == 1 && foundCart;
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot)

Example 8 with IInvSlot

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

the class TileRockCrusher method update.

@Override
public void update() {
    super.update();
    if (Game.isHost(getWorld())) {
        BlockPos pos = getPos();
        double x = pos.getX();
        double y = pos.getZ();
        double z = pos.getZ();
        if (isStructureValid()) {
            // TileEntityHopper.getItemsAroundAPointOrSomethingLikeThat
            for (EntityItem item : TileEntityHopper.getCaptureItems(getWorld(), x, y + 1, z)) {
                if (item != null && useMasterEnergy(SUCKING_POWER_COST, false)) {
                    ItemStack stack = item.getEntityItem().copy();
                    InventoryManipulator.get((IInventory) invInput).addStack(stack);
                    useMasterEnergy(SUCKING_POWER_COST, true);
                    item.setDead();
                }
            }
            EntityLivingBase entity = MiscTools.getEntityAt(worldObj, EntityLivingBase.class, getPos().up());
            if (entity != null && useMasterEnergy(KILLING_POWER_COST, false))
                if (entity.attackEntityFrom(RailcraftDamageSource.CRUSHER, 10))
                    useMasterEnergy(KILLING_POWER_COST, true);
        }
        if (isMaster()) {
            if (clock % 16 == 0)
                processActions();
            if (paused)
                return;
            ItemStack input = InvTools.emptyStack();
            ICrusherCraftingManager.ICrusherRecipe recipe = null;
            for (IInvSlot slot : InventoryIterator.getVanilla((IInventory) invInput)) {
                input = slot.getStack();
                if (!InvTools.isEmpty(input)) {
                    recipe = RailcraftCraftingManager.rockCrusher.getRecipe(input);
                    if (recipe == null)
                        recipe = RockCrusherCraftingManager.NULL_RECIPE;
                    break;
                }
            }
            if (recipe != null)
                if (processTime >= PROCESS_TIME) {
                    isWorking = false;
                    InventoryCopy tempInv = new InventoryCopy(invOutput);
                    boolean hasRoom = true;
                    List<ItemStack> outputs = recipe.getProcessedOutputs();
                    for (ItemStack output : outputs) {
                        output = InvTools.moveItemStack(output, tempInv);
                        if (!InvTools.isEmpty(output)) {
                            hasRoom = false;
                            break;
                        }
                    }
                    if (hasRoom) {
                        for (ItemStack output : outputs) {
                            InvTools.moveItemStack(output, invOutput);
                        }
                        InvTools.removeOneItem(invInput, input);
                        SoundHelper.playSound(worldObj, null, getPos(), SoundEvents.ENTITY_IRONGOLEM_DEATH, SoundCategory.BLOCKS, 1.0f, worldObj.rand.nextFloat() * 0.25F + 0.7F);
                        processTime = 0;
                    }
                } else {
                    isWorking = true;
                    if (energyStorage != null) {
                        int energy = energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, true);
                        if (energy >= CRUSHING_POWER_COST_PER_TICK) {
                            processTime++;
                            energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, false);
                        }
                    } else
                        processTime++;
                }
            else {
                processTime = 0;
                isWorking = false;
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) InventoryCopy(mods.railcraft.common.util.inventory.wrappers.InventoryCopy) ItemStack(net.minecraft.item.ItemStack) ICrusherCraftingManager(mods.railcraft.api.crafting.ICrusherCraftingManager) EntityItem(net.minecraft.entity.item.EntityItem)

Example 9 with IInvSlot

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

the class CartFilterRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
    ItemStack cartItem = InvTools.emptyStack();
    ItemStack filterItem = InvTools.emptyStack();
    FilterType filterType = null;
    int cartSlot = -1;
    int itemCount = 0;
    int filterCartCount = 0;
    for (IInvSlot slot : InventoryIterator.getVanilla(grid)) {
        ItemStack stack = slot.getStack();
        if (!InvTools.isEmpty(stack)) {
            itemCount++;
            FilterType type = FilterType.fromCartType(RailcraftCarts.getCartType(stack));
            if (type != null) {
                cartSlot = slot.getIndex();
                filterType = type;
                cartItem = stack.copy();
                filterCartCount++;
            }
        }
    }
    if (filterType == null || itemCount > 2 || filterCartCount > 1)
        return InvTools.emptyStack();
    for (IInvSlot slot : InventoryIterator.getVanilla(grid)) {
        if (slot.getIndex() == cartSlot)
            continue;
        ItemStack stack = slot.getStack();
        if (!InvTools.isEmpty(stack) && filterType.isAllowedFilterItem(stack)) {
            filterItem = stack.copy();
            break;
        }
    }
    if (InvTools.isEmpty(cartItem) || InvTools.isEmpty(filterItem))
        return InvTools.emptyStack();
    filterItem.stackSize = 1;
    return CartBaseFiltered.addFilterToCartItem(cartItem, filterItem);
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) ItemStack(net.minecraft.item.ItemStack)

Example 10 with IInvSlot

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

the class InventoryManipulator method moveItem.

@Nullable
public ItemStack moveItem(IInventoryObject dest, Predicate<ItemStack> filter) {
    InventoryManipulator imDest = InventoryManipulator.get(dest);
    for (IInvSlot slot : this) {
        ItemStack stack = slot.getStack();
        if (!isEmpty(stack) && slot.canTakeStackFromSlot(stack) && filter.test(stack)) {
            stack = stack.copy();
            stack.stackSize = 1;
            stack = imDest.addStack(stack);
            if (isEmpty(stack))
                return slot.decreaseStack();
        }
    }
    return emptyStack();
}
Also used : IInvSlot(mods.railcraft.common.util.inventory.iterators.IInvSlot) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

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