Search in sources :

Example 1 with InventoryComposite

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

the class FilterSimpleRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting grid) {
    if (!matches(grid, null))
        return InvTools.emptyStack();
    InventoryComposite inv = InventoryComposite.of(grid);
    ItemStack filter = InvTools.findMatchingItem(inv, FILTER);
    if (InvTools.isEmpty(filter))
        return InvTools.emptyStack();
    ItemStack prototype = InvTools.findMatchingItem(inv, validPrototype(filter));
    if (!InvTools.isEmpty(prototype))
        return ItemFilterSimple.setPrototype(filter, prototype);
    return InvTools.emptyStack();
}
Also used : InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) ItemStack(net.minecraft.item.ItemStack)

Example 2 with InventoryComposite

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

the class FilterSimpleRecipe method matches.

@Override
public boolean matches(InventoryCrafting grid, World world) {
    InventoryComposite inv = InventoryComposite.of(grid);
    int filterStacks = InvTools.countStacks(inv, FILTER);
    if (filterStacks != 1)
        return false;
    ItemStack filter = InvTools.findMatchingItem(inv, FILTER);
    if (InvTools.isEmpty(filter))
        return false;
    int prototype = InvTools.countStacks(inv, validPrototype(filter));
    return prototype == 1;
}
Also used : InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) ItemStack(net.minecraft.item.ItemStack)

Example 3 with InventoryComposite

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

the class TileItemManipulator method processCart.

@Override
protected void processCart(EntityMinecart cart) {
    chests.clear();
    chests.add(invBuffer);
    chests.addAll(invCache.getAdjacentInventories());
    InventoryComposite cartInv = InventoryComposite.of(InventoryFactory.get(cart, getFacing().getOpposite()));
    if (cartInv.isEmpty()) {
        sendCart(cart);
        return;
    }
    this.cart = cartInv;
    switch(getMode()) {
        case TRANSFER:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                filterManifest.entrySet().stream().filter(entry -> transferredItems.count(entry.getElement()) < entry.getCount()).anyMatch(entry -> {
                    ItemStack moved = InvTools.moveOneItem(getSource(), getDestination(), StackFilters.matches(entry.getElement().get()));
                    if (!InvTools.isEmpty(moved)) {
                        setProcessing(true);
                        transferredItems.add(entry.getElement());
                        return true;
                    }
                    return false;
                });
                break;
            }
        case STOCK:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                Multiset<StackKey> destManifest = InvTools.createManifest(getDestination(), filterManifest.elementSet());
                moveItem(filterManifest.entrySet().stream().filter(entry -> destManifest.count(entry.getElement()) < entry.getCount()));
                break;
            }
        case EXCESS:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                Multiset<StackKey> sourceManifest = InvTools.createManifest(getSource(), filterManifest.elementSet());
                moveItem(filterManifest.entrySet().stream().filter(entry -> sourceManifest.count(entry.getElement()) > entry.getCount()));
                if (!isProcessing()) {
                    Predicate<ItemStack> keep = filterManifest.elementSet().stream().map(e -> StackFilters.matches(e.get())).reduce(StackFilters.none(), Predicate::or);
                    ItemStack moved = InvTools.moveOneItemExcept(getSource(), getDestination(), keep);
                    itemMoved(moved);
                }
                break;
            }
        case ALL:
            {
                Multiset<StackKey> filterManifest = InvTools.createManifest(getItemFilters());
                if (filterManifest.isEmpty()) {
                    ItemStack moved = InvTools.moveOneItem(getSource(), getDestination());
                    itemMoved(moved);
                } else {
                    moveItem(filterManifest.entrySet().stream());
                }
                break;
            }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IInventoryObject(mods.railcraft.common.util.inventory.wrappers.IInventoryObject) EnumMap(java.util.EnumMap) Multiset(com.google.common.collect.Multiset) Predicate(java.util.function.Predicate) EntityMinecart(net.minecraft.entity.item.EntityMinecart) IOException(java.io.IOException) RailcraftInputStream(mods.railcraft.common.util.network.RailcraftInputStream) StackFilters(mods.railcraft.common.util.inventory.filters.StackFilters) InventoryMapper(mods.railcraft.common.util.inventory.wrappers.InventoryMapper) RailcraftOutputStream(mods.railcraft.common.util.network.RailcraftOutputStream) ItemStack(net.minecraft.item.ItemStack) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) Stream(java.util.stream.Stream) HashMultiset(com.google.common.collect.HashMultiset) StackKey(mods.railcraft.common.util.collections.StackKey) MultiButtonController(mods.railcraft.common.gui.buttons.MultiButtonController) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Slot(net.minecraft.inventory.Slot) mods.railcraft.common.util.inventory(mods.railcraft.common.util.inventory) IInventoryComposite(mods.railcraft.common.util.inventory.wrappers.IInventoryComposite) Nullable(javax.annotation.Nullable) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) InventoryComposite(mods.railcraft.common.util.inventory.wrappers.InventoryComposite) IInventoryComposite(mods.railcraft.common.util.inventory.wrappers.IInventoryComposite) ItemStack(net.minecraft.item.ItemStack) Predicate(java.util.function.Predicate)

Aggregations

InventoryComposite (mods.railcraft.common.util.inventory.wrappers.InventoryComposite)3 ItemStack (net.minecraft.item.ItemStack)3 HashMultiset (com.google.common.collect.HashMultiset)1 Multiset (com.google.common.collect.Multiset)1 IOException (java.io.IOException)1 EnumMap (java.util.EnumMap)1 Predicate (java.util.function.Predicate)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 MultiButtonController (mods.railcraft.common.gui.buttons.MultiButtonController)1 StackKey (mods.railcraft.common.util.collections.StackKey)1 mods.railcraft.common.util.inventory (mods.railcraft.common.util.inventory)1 StackFilters (mods.railcraft.common.util.inventory.filters.StackFilters)1 IInventoryComposite (mods.railcraft.common.util.inventory.wrappers.IInventoryComposite)1 IInventoryObject (mods.railcraft.common.util.inventory.wrappers.IInventoryObject)1 InventoryMapper (mods.railcraft.common.util.inventory.wrappers.InventoryMapper)1 RailcraftInputStream (mods.railcraft.common.util.network.RailcraftInputStream)1 RailcraftOutputStream (mods.railcraft.common.util.network.RailcraftOutputStream)1 EntityMinecart (net.minecraft.entity.item.EntityMinecart)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1