Search in sources :

Example 1 with ItemStackKey

use of buildcraft.lib.misc.ItemStackKey in project BuildCraft by BuildCraft.

the class WorkbenchCrafting method hasExactStacks.

private boolean hasExactStacks() {
    TObjectIntMap<ItemStackKey> required = new TObjectIntHashMap<>(getSizeInventory());
    for (int s = 0; s < getSizeInventory(); s++) {
        ItemStack req = invBlueprint.getStackInSlot(s);
        if (!req.isEmpty()) {
            int count = req.getCount();
            if (count != 1) {
                req = req.copy();
                req.setCount(1);
            }
            ItemStackKey key = new ItemStackKey(req);
            required.adjustOrPutValue(key, count, count);
        }
    }
    return required.forEachEntry((stack, count) -> {
        ArrayStackFilter filter = new ArrayStackFilter(stack.baseStack);
        ItemStack inInventory = invMaterials.extract(filter, count, count, true);
        return !inInventory.isEmpty() && inInventory.getCount() == count;
    });
}
Also used : ArrayStackFilter(buildcraft.lib.inventory.filter.ArrayStackFilter) TObjectIntHashMap(gnu.trove.map.hash.TObjectIntHashMap) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(buildcraft.lib.misc.ItemStackKey)

Example 2 with ItemStackKey

use of buildcraft.lib.misc.ItemStackKey in project BuildCraft by BuildCraft.

the class FacadeAssemblyRecipes method getOutputs.

@Override
public Set<ItemStack> getOutputs(NonNullList<ItemStack> inputs) {
    if (!StackUtil.contains(new ItemStack(BCTransportItems.pipeStructure, 3), inputs)) {
        return Collections.emptySet();
    }
    ArrayList<ItemStack> stacks = new ArrayList<>();
    for (ItemStack stack : inputs) {
        stack = stack.copy();
        stack.setCount(1);
        List<FacadeBlockStateInfo> infos = FacadeStateManager.stackFacades.get(new ItemStackKey(stack));
        if (infos == null || infos.isEmpty()) {
            continue;
        }
        for (FacadeBlockStateInfo info : infos) {
            stacks.add(createFacadeStack(info, false));
            stacks.add(createFacadeStack(info, true));
        }
    }
    return ImmutableSet.copyOf(stacks);
}
Also used : FacadeBlockStateInfo(buildcraft.transport.plug.FacadeBlockStateInfo) ArrayList(java.util.ArrayList) ChangingItemStack(buildcraft.lib.recipe.ChangingItemStack) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(buildcraft.lib.misc.ItemStackKey)

Example 3 with ItemStackKey

use of buildcraft.lib.misc.ItemStackKey in project BuildCraft by BuildCraft.

the class EntryTypeItem method matches.

@Override
public boolean matches(ItemStackValueFilter target, Object value) {
    if (value instanceof ItemStackKey) {
        value = ((ItemStackKey) value).baseStack;
    }
    if (value instanceof ItemStack) {
        ItemStack base = target.stack.baseStack;
        ItemStack test = (ItemStack) value;
        if (base.isEmpty() || test.isEmpty()) {
            return false;
        }
        if (base.getItem() != test.getItem()) {
            return false;
        }
        if (target.matchMeta) {
            if (base.getMetadata() != test.getMetadata()) {
                return false;
            }
        }
        if (target.matchNbt) {
            if (!ItemStack.areItemStackTagsEqual(base, test)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackKey(buildcraft.lib.misc.ItemStackKey)

Example 4 with ItemStackKey

use of buildcraft.lib.misc.ItemStackKey in project BuildCraft by BuildCraft.

the class EntryTypeItem method deserialise.

@Override
@Nullable
public ItemStackValueFilter deserialise(String source) {
    final ItemStack stack;
    final boolean matchMeta;
    final boolean matchNbt;
    if (source.startsWith("{") && source.endsWith("}")) {
        stack = MarkdownPageLoader.loadComplexItemStack(source.substring(1, source.length() - 1));
        stack.setCount(1);
        matchMeta = true;
        matchNbt = stack.hasTagCompound();
    } else {
        if (source.startsWith("(") && source.endsWith(")")) {
            source = source.substring(1, source.length() - 1);
        }
        Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(source));
        if (item == null) {
            return null;
        }
        stack = new ItemStack(item);
        matchMeta = false;
        matchNbt = false;
    }
    if (stack.isEmpty()) {
        return null;
    }
    return new ItemStackValueFilter(new ItemStackKey(stack), matchMeta, matchNbt);
}
Also used : Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(buildcraft.lib.misc.ItemStackKey) Nullable(javax.annotation.Nullable)

Example 5 with ItemStackKey

use of buildcraft.lib.misc.ItemStackKey in project BuildCraft by BuildCraft.

the class NetworkedItemStackCache method getCanonical.

@Override
protected ItemStackKey getCanonical(ItemStackKey obj) {
    if (obj.baseStack.isEmpty()) {
        return ItemStackKey.EMPTY;
    }
    ItemStack stack = obj.baseStack.copy();
    stack.setCount(1);
    if (stack.hasTagCompound()) {
        stack.setTagCompound(StackUtil.stripNonFunctionNbt(stack));
    }
    return new ItemStackKey(stack);
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackKey(buildcraft.lib.misc.ItemStackKey)

Aggregations

ItemStackKey (buildcraft.lib.misc.ItemStackKey)5 ItemStack (net.minecraft.item.ItemStack)5 ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 ChangingItemStack (buildcraft.lib.recipe.ChangingItemStack)1 FacadeBlockStateInfo (buildcraft.transport.plug.FacadeBlockStateInfo)1 TObjectIntHashMap (gnu.trove.map.hash.TObjectIntHashMap)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1 Item (net.minecraft.item.Item)1 ResourceLocation (net.minecraft.util.ResourceLocation)1