use of buildcraft.api.core.StackKey in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method recomputeNeededItems.
private void recomputeNeededItems() {
neededItems.clear();
HashMap<StackKey, Integer> computeStacks = new HashMap<>();
for (List<BuildingSlotBlock> lb : buildList.values()) {
for (BuildingSlotBlock slot : lb) {
if (slot == null) {
continue;
}
List<ItemStack> stacks = new ArrayList<>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
}
for (BuildingSlotEntity slot : entityList) {
LinkedList<ItemStack> stacks = new LinkedList<>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
for (Entry<StackKey, Integer> e : computeStacks.entrySet()) {
neededItems.add(new RequirementItemStack(e.getKey().stack.copy(), e.getValue()));
}
sortNeededItems();
}
use of buildcraft.api.core.StackKey in project BuildCraft by BuildCraft.
the class BptBuilderBlueprint method onRemoveBuildingSlotBlock.
protected void onRemoveBuildingSlotBlock(BuildingSlotBlock slot) {
buildStageOccurences[slot.buildStage]--;
List<ItemStack> stacks = new ArrayList<>();
try {
stacks = slot.getRequirements(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
BCLog.logger.throwing(t);
}
HashMap<StackKey, Integer> computeStacks = new HashMap<>();
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
for (RequirementItemStack ris : neededItems) {
StackKey stackKey = new StackKey(ris.stack);
if (computeStacks.containsKey(stackKey)) {
Integer num = computeStacks.get(stackKey);
if (ris.size <= num) {
recomputeNeededItems();
return;
} else {
neededItems.set(neededItems.indexOf(ris), new RequirementItemStack(ris.stack, ris.size - num));
}
}
}
sortNeededItems();
}
Aggregations