port over regresion fixes
This commit is contained in:
@@ -101,17 +101,17 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
}
|
||||
} else {
|
||||
outputs = ItemPattern.getOutputs(stack).stream().map(Comparer::stripTags).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (isOredict()) {
|
||||
if (oreInputs.isEmpty()) {
|
||||
for (ItemStack input : inputs) {
|
||||
|
||||
if (input == null) {
|
||||
oreInputs.add(Collections.emptyList());
|
||||
} else {
|
||||
int[] ids = OreDictionary.getOreIDs(input);
|
||||
if (ids == null || ids.length == 0) {
|
||||
oreInputs.add(Collections.singletonList(Comparer.stripTags(input)));
|
||||
} else {
|
||||
} else if (isOredict()) {
|
||||
List<ItemStack> oredict = Arrays.stream(ids)
|
||||
.mapToObj(OreDictionary::getOreName)
|
||||
.map(OreDictionary::getOres)
|
||||
@@ -126,22 +126,13 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
// Add original stack as first, should prevent some issues
|
||||
oredict.add(0, Comparer.stripTags(input.copy()));
|
||||
oreInputs.add(oredict);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (oreInputs.isEmpty()) {
|
||||
for (ItemStack input : inputs) {
|
||||
if (input == null) {
|
||||
oreInputs.add(Collections.emptyList());
|
||||
} else {
|
||||
oreInputs.add(Collections.singletonList(Comparer.stripTags(input)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICraftingPatternContainer getContainer() {
|
||||
|
@@ -70,7 +70,7 @@ public class CraftingStepCraft extends CraftingStep {
|
||||
IStackList<ItemStack> stackList = API.instance().createItemStackList();
|
||||
actualInputs.forEach(stackList::add);
|
||||
|
||||
ItemStack[] took = StackListItem.toCraftingGrid(stackList, toInsert, CraftingTask.DEFAULT_COMPARE);
|
||||
ItemStack[] took = StackListItem.toCraftingGrid(stackList, toInsert, CraftingTask.DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0));
|
||||
|
||||
List<ItemStack> outputs = pattern.isOredict() ? pattern.getOutputs(took) : pattern.getOutputs();
|
||||
if (outputs == null) {
|
||||
|
@@ -24,6 +24,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
@@ -97,33 +98,20 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
int compare = DEFAULT_COMPARE;
|
||||
|
||||
IStackList<ItemStack> inputs = API.instance().createItemStackList();
|
||||
IStackList<ItemStack> actualInputs = API.instance().createItemStackList();
|
||||
List<ItemStack> usedStacks = new LinkedList<>();
|
||||
List<ICraftingStep> previousSteps = new LinkedList<>();
|
||||
|
||||
for (List<ItemStack> oreInputs : pattern.getOreInputs()) {
|
||||
boolean added = false;
|
||||
for (ItemStack input : oreInputs) {
|
||||
int oreCompare = IComparer.COMPARE_NBT | IComparer.COMPARE_STRIP_NBT | (input.isItemStackDamageable() ? 0 : IComparer.COMPARE_DAMAGE);
|
||||
if (network.getItemStorageCache().getList().get(input, oreCompare) != null) {
|
||||
usedStacks.add(input.copy());
|
||||
inputs.add(input.copy());
|
||||
added = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!added) {
|
||||
ItemStack choice = null;
|
||||
if (!oreInputs.isEmpty()) {
|
||||
choice = oreInputs.get(0);
|
||||
inputs.add(choice);
|
||||
}
|
||||
usedStacks.add(choice);
|
||||
}
|
||||
for (List<ItemStack> inputs : pattern.getOreInputs()) {
|
||||
if (inputs == null || inputs.isEmpty()) {
|
||||
usedStacks.add(null);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (ItemStack input : inputs.getStacks()) {
|
||||
int i = 0;
|
||||
ItemStack input, extraStack, networkStack;
|
||||
do {
|
||||
input = inputs.get(i).copy();
|
||||
// This will be a tool, like a hammer
|
||||
if (input.isItemStackDamageable()) {
|
||||
compare &= ~IComparer.COMPARE_DAMAGE;
|
||||
@@ -131,20 +119,33 @@ public class CraftingTask implements ICraftingTask {
|
||||
compare |= IComparer.COMPARE_DAMAGE;
|
||||
}
|
||||
|
||||
ItemStack extraStack = toInsert.get(input, compare);
|
||||
ItemStack networkStack = networkList.get(input, compare);
|
||||
extraStack = toInsert.get(input, compare);
|
||||
networkStack = networkList.get(input, compare);
|
||||
} while (extraStack == null && networkStack == null && ++i < inputs.size() && network.getCraftingManager().getPatterns(input, compare).isEmpty());
|
||||
if (i == inputs.size()) {
|
||||
input = inputs.get(0).copy();
|
||||
}
|
||||
usedStacks.add(input.copy());
|
||||
|
||||
// This will be a tool, like a hammer
|
||||
if (input.isItemStackDamageable()) {
|
||||
compare &= ~IComparer.COMPARE_DAMAGE;
|
||||
} else {
|
||||
compare |= IComparer.COMPARE_DAMAGE;
|
||||
}
|
||||
|
||||
// This handles recipes that use the output as input for the sub recipe
|
||||
final int lambdaCompare = compare;
|
||||
final ItemStack lambdaInput = input;
|
||||
ICraftingPattern inputPattern = null;
|
||||
int available = (extraStack == null ? 0 : extraStack.getCount()) + (networkStack == null ? 0 : networkStack.getCount());
|
||||
if (available < input.getCount()) {
|
||||
inputPattern = network.getCraftingManager().getPattern(input, compare);
|
||||
if (inputPattern != null) {
|
||||
if (inputPattern.getInputs().stream().anyMatch(s -> API.instance().getComparer().isEqual(s, input, lambdaCompare))) {
|
||||
if (inputPattern.getInputs().stream().anyMatch(s -> API.instance().getComparer().isEqual(s, lambdaInput, lambdaCompare))) {
|
||||
int craftQuantity = inputPattern.getQuantityPerRequest(input, compare);
|
||||
// The needed amount is the actual needed amount of extraStacks + the needed input (twice so you can keep repeating it)
|
||||
long needed = (networkStack == null ? 0 : -networkStack.getCount()) + input.getCount() + inputPattern.getInputs().stream().filter(s -> API.instance().getComparer().isEqual(s, input, lambdaCompare)).count() * 2;
|
||||
long needed = (networkStack == null ? 0 : -networkStack.getCount()) + input.getCount() + inputPattern.getInputs().stream().filter(s -> API.instance().getComparer().isEqual(s, lambdaInput, lambdaCompare)).count() * 2;
|
||||
do {
|
||||
previousSteps.add(calculate(networkList, networkFluidList, inputPattern, toInsert));
|
||||
toCraft.add(ItemHandlerHelper.copyStackWithSize(input, craftQuantity));
|
||||
@@ -165,7 +166,10 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
toInsert.remove(inputStack);
|
||||
if (input.getCount() > 0) {
|
||||
extraStack = toInsert.get(input, compare);
|
||||
i = 0;
|
||||
do {
|
||||
extraStack = toInsert.get(inputs.get(i), compare);
|
||||
} while ((extraStack == null || extraStack.getCount() == 0) && ++i < inputs.size());
|
||||
}
|
||||
} else if (networkStack != null && networkStack.getCount() > 0) {
|
||||
int takeQuantity = Math.min(networkStack.getCount(), input.getCount());
|
||||
@@ -175,7 +179,10 @@ public class CraftingTask implements ICraftingTask {
|
||||
input.shrink(takeQuantity);
|
||||
networkList.remove(inputStack);
|
||||
if (input.getCount() > 0) {
|
||||
networkStack = networkList.get(inputStack, compare);
|
||||
i = 0;
|
||||
do {
|
||||
networkStack = networkList.get(inputs.get(i), compare);
|
||||
} while ((extraStack == null || extraStack.getCount() == 0) && ++i < inputs.size());
|
||||
}
|
||||
} else {
|
||||
if (inputPattern == null) {
|
||||
@@ -206,7 +213,11 @@ public class CraftingTask implements ICraftingTask {
|
||||
|
||||
// When it isn't a fluid or just doesn't have the needed fluids
|
||||
if (input.getCount() > 0) {
|
||||
missing.add(input.copy());
|
||||
ItemStack copy = input.copy();
|
||||
if (copy.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
|
||||
copy.setItemDamage(0);
|
||||
}
|
||||
missing.add(copy);
|
||||
input.setCount(0);
|
||||
}
|
||||
}
|
||||
@@ -217,7 +228,7 @@ public class CraftingTask implements ICraftingTask {
|
||||
ItemStack[] took = null;
|
||||
if (missing.isEmpty()) {
|
||||
if (!pattern.isProcessing()) {
|
||||
took = StackListItem.toCraftingGrid(actualInputs, usedStacks, compare);
|
||||
took = StackListItem.toCraftingGrid(actualInputs, usedStacks, compare | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -183,6 +183,9 @@ public class Comparer implements IComparer {
|
||||
case "refinedstorage":
|
||||
stack.getTagCompound().removeTag(BlockNode.NBT_REFINED_STORAGE_DATA);
|
||||
break;
|
||||
case "storagedrawers":
|
||||
stack.getTagCompound().removeTag("material");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user