port over regresion fixes

This commit is contained in:
way2muchnoise
2016-12-31 16:59:20 +01:00
parent 556f2d8d67
commit a561a23b87
4 changed files with 61 additions and 56 deletions

View File

@@ -101,17 +101,17 @@ public class CraftingPattern implements ICraftingPattern {
} }
} else { } else {
outputs = ItemPattern.getOutputs(stack).stream().map(Comparer::stripTags).collect(Collectors.toList()); outputs = ItemPattern.getOutputs(stack).stream().map(Comparer::stripTags).collect(Collectors.toList());
}
if (isOredict()) { if (oreInputs.isEmpty()) {
for (ItemStack input : inputs) { for (ItemStack input : inputs) {
if (input == null) { if (input == null) {
oreInputs.add(Collections.emptyList()); oreInputs.add(Collections.emptyList());
} else { } else {
int[] ids = OreDictionary.getOreIDs(input); int[] ids = OreDictionary.getOreIDs(input);
if (ids == null || ids.length == 0) { if (ids == null || ids.length == 0) {
oreInputs.add(Collections.singletonList(Comparer.stripTags(input))); oreInputs.add(Collections.singletonList(Comparer.stripTags(input)));
} else { } else if (isOredict()) {
List<ItemStack> oredict = Arrays.stream(ids) List<ItemStack> oredict = Arrays.stream(ids)
.mapToObj(OreDictionary::getOreName) .mapToObj(OreDictionary::getOreName)
.map(OreDictionary::getOres) .map(OreDictionary::getOres)
@@ -126,22 +126,13 @@ public class CraftingPattern implements ICraftingPattern {
// Add original stack as first, should prevent some issues // Add original stack as first, should prevent some issues
oredict.add(0, Comparer.stripTags(input.copy())); oredict.add(0, Comparer.stripTags(input.copy()));
oreInputs.add(oredict); oreInputs.add(oredict);
}
}
}
}
}
if (oreInputs.isEmpty()) {
for (ItemStack input : inputs) {
if (input == null) {
oreInputs.add(Collections.emptyList());
} else { } else {
oreInputs.add(Collections.singletonList(Comparer.stripTags(input))); oreInputs.add(Collections.singletonList(Comparer.stripTags(input)));
} }
} }
} }
} }
}
@Override @Override
public ICraftingPatternContainer getContainer() { public ICraftingPatternContainer getContainer() {

View File

@@ -70,7 +70,7 @@ public class CraftingStepCraft extends CraftingStep {
IStackList<ItemStack> stackList = API.instance().createItemStackList(); IStackList<ItemStack> stackList = API.instance().createItemStackList();
actualInputs.forEach(stackList::add); 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(); List<ItemStack> outputs = pattern.isOredict() ? pattern.getOutputs(took) : pattern.getOutputs();
if (outputs == null) { if (outputs == null) {

View File

@@ -24,6 +24,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*; import java.util.*;
@@ -97,33 +98,20 @@ public class CraftingTask implements ICraftingTask {
int compare = DEFAULT_COMPARE; int compare = DEFAULT_COMPARE;
IStackList<ItemStack> inputs = API.instance().createItemStackList();
IStackList<ItemStack> actualInputs = API.instance().createItemStackList(); IStackList<ItemStack> actualInputs = API.instance().createItemStackList();
List<ItemStack> usedStacks = new LinkedList<>(); List<ItemStack> usedStacks = new LinkedList<>();
List<ICraftingStep> previousSteps = new LinkedList<>(); List<ICraftingStep> previousSteps = new LinkedList<>();
for (List<ItemStack> oreInputs : pattern.getOreInputs()) { for (List<ItemStack> inputs : pattern.getOreInputs()) {
boolean added = false; if (inputs == null || inputs.isEmpty()) {
for (ItemStack input : oreInputs) { usedStacks.add(null);
int oreCompare = IComparer.COMPARE_NBT | IComparer.COMPARE_STRIP_NBT | (input.isItemStackDamageable() ? 0 : IComparer.COMPARE_DAMAGE); continue;
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 (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 // This will be a tool, like a hammer
if (input.isItemStackDamageable()) { if (input.isItemStackDamageable()) {
compare &= ~IComparer.COMPARE_DAMAGE; compare &= ~IComparer.COMPARE_DAMAGE;
@@ -131,20 +119,33 @@ public class CraftingTask implements ICraftingTask {
compare |= IComparer.COMPARE_DAMAGE; compare |= IComparer.COMPARE_DAMAGE;
} }
ItemStack extraStack = toInsert.get(input, compare); extraStack = toInsert.get(input, compare);
ItemStack networkStack = networkList.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 // This handles recipes that use the output as input for the sub recipe
final int lambdaCompare = compare; final int lambdaCompare = compare;
final ItemStack lambdaInput = input;
ICraftingPattern inputPattern = null; ICraftingPattern inputPattern = null;
int available = (extraStack == null ? 0 : extraStack.getCount()) + (networkStack == null ? 0 : networkStack.getCount()); int available = (extraStack == null ? 0 : extraStack.getCount()) + (networkStack == null ? 0 : networkStack.getCount());
if (available < input.getCount()) { if (available < input.getCount()) {
inputPattern = network.getCraftingManager().getPattern(input, compare); inputPattern = network.getCraftingManager().getPattern(input, compare);
if (inputPattern != null) { 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); 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) // 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 { do {
previousSteps.add(calculate(networkList, networkFluidList, inputPattern, toInsert)); previousSteps.add(calculate(networkList, networkFluidList, inputPattern, toInsert));
toCraft.add(ItemHandlerHelper.copyStackWithSize(input, craftQuantity)); toCraft.add(ItemHandlerHelper.copyStackWithSize(input, craftQuantity));
@@ -165,7 +166,10 @@ public class CraftingTask implements ICraftingTask {
} }
toInsert.remove(inputStack); toInsert.remove(inputStack);
if (input.getCount() > 0) { 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) { } else if (networkStack != null && networkStack.getCount() > 0) {
int takeQuantity = Math.min(networkStack.getCount(), input.getCount()); int takeQuantity = Math.min(networkStack.getCount(), input.getCount());
@@ -175,7 +179,10 @@ public class CraftingTask implements ICraftingTask {
input.shrink(takeQuantity); input.shrink(takeQuantity);
networkList.remove(inputStack); networkList.remove(inputStack);
if (input.getCount() > 0) { 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 { } else {
if (inputPattern == null) { 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 // When it isn't a fluid or just doesn't have the needed fluids
if (input.getCount() > 0) { 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); input.setCount(0);
} }
} }
@@ -217,7 +228,7 @@ public class CraftingTask implements ICraftingTask {
ItemStack[] took = null; ItemStack[] took = null;
if (missing.isEmpty()) { if (missing.isEmpty()) {
if (!pattern.isProcessing()) { if (!pattern.isProcessing()) {
took = StackListItem.toCraftingGrid(actualInputs, usedStacks, compare); took = StackListItem.toCraftingGrid(actualInputs, usedStacks, compare | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0));
} }
} }

View File

@@ -183,6 +183,9 @@ public class Comparer implements IComparer {
case "refinedstorage": case "refinedstorage":
stack.getTagCompound().removeTag(BlockNode.NBT_REFINED_STORAGE_DATA); stack.getTagCompound().removeTag(BlockNode.NBT_REFINED_STORAGE_DATA);
break; break;
case "storagedrawers":
stack.getTagCompound().removeTag("material");
break;
} }
} }