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;
});
}
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);
}
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;
}
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);
}
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);
}
Aggregations