fixes some issues with extra outputs on processing patterns and some consitency in the preview

This commit is contained in:
way2muchnoise
2016-11-02 16:49:09 +01:00
parent 4e43778277
commit a8093a299b
3 changed files with 39 additions and 16 deletions

View File

@@ -84,4 +84,13 @@ public interface ICraftingPattern {
* @return the quantity * @return the quantity
*/ */
int getQuantityPerRequest(ItemStack requested, int compare); int getQuantityPerRequest(ItemStack requested, int compare);
/**
* Returns the actual outputted {@link ItemStack}
*
* @param requested an item requested
* @param compare the {@link IComparer} flags
* @return the actual {@link ItemStack} with quantity
*/
ItemStack getActualOutput(ItemStack requested, int compare);
} }

View File

@@ -10,6 +10,7 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.ArrayList; import java.util.ArrayList;
@@ -165,6 +166,17 @@ public class CraftingPattern implements ICraftingPattern {
return quantity; return quantity;
} }
@Override
public ItemStack getActualOutput(ItemStack requested, int compare) {
for (ItemStack output : outputs) {
if (API.instance().getComparer().isEqual(requested, output, compare)) {
return output.copy();
}
}
return null;
}
@Override @Override
public String toString() { public String toString() {
return "CraftingPattern{" + return "CraftingPattern{" +

View File

@@ -96,7 +96,6 @@ public class CraftingTask implements ICraftingTask {
} }
int compare = DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0); int compare = DEFAULT_COMPARE | (pattern.isOredict() ? IComparer.COMPARE_OREDICT : 0);
ItemStack[] took = new ItemStack[9];
IItemStackList inputs = API.instance().createItemStackList(); IItemStackList inputs = API.instance().createItemStackList();
IItemStackList actualInputs = API.instance().createItemStackList(); IItemStackList actualInputs = API.instance().createItemStackList();
@@ -132,15 +131,17 @@ public class CraftingTask implements ICraftingTask {
ICraftingPattern inputPattern = network.getPattern(input, compare); ICraftingPattern inputPattern = network.getPattern(input, compare);
if (inputPattern != null) { if (inputPattern != null) {
ItemStack actualCraft = inputPattern.getActualOutput(input, compare);
int craftQuantity = Math.min(inputPattern.getQuantityPerRequest(input, compare), input.stackSize); int craftQuantity = Math.min(inputPattern.getQuantityPerRequest(input, compare), input.stackSize);
ItemStack inputCrafted = ItemHandlerHelper.copyStackWithSize(input, craftQuantity); ItemStack inputCrafted = ItemHandlerHelper.copyStackWithSize(actualCraft, craftQuantity);
toCraft.add(inputCrafted.copy()); toCraft.add(inputCrafted.copy());
actualInputs.add(inputCrafted.copy()); actualInputs.add(inputCrafted.copy());
calculate(networkList, networkFluidList, inputPattern, toInsert); calculate(networkList, networkFluidList, inputPattern, toInsert);
input.stackSize -= craftQuantity; input.stackSize -= craftQuantity;
// Calculate added all the crafted outputs toInsertItems // Calculate added all the crafted outputs toInsert
// So we remove the ones we use from toInsertItems // So we remove the ones we use from toInsert
toInsert.remove(inputCrafted, true); ItemStack inserted = toInsert.get(inputCrafted, compare);
toInsert.remove(inserted, craftQuantity, true);
} else { } else {
// Fluid checks are with a stack size of one // Fluid checks are with a stack size of one
ItemStack fluidCheck = ItemHandlerHelper.copyStackWithSize(input, 1); ItemStack fluidCheck = ItemHandlerHelper.copyStackWithSize(input, 1);
@@ -166,23 +167,24 @@ public class CraftingTask implements ICraftingTask {
} }
if (missing.isEmpty()) { if (missing.isEmpty()) {
for (int i = 0; i < pattern.getInputs().size(); i++) { ItemStack[] took = new ItemStack[9];
ItemStack input = pattern.getInputs().get(i); if (!pattern.isProcessing()) {
if (input != null) { for (int i = 0; i < pattern.getInputs().size(); i++) {
ItemStack actualInput = actualInputs.get(input, compare); ItemStack input = pattern.getInputs().get(i);
ItemStack taken = ItemHandlerHelper.copyStackWithSize(actualInput, input.stackSize); if (input != null) {
took[i] = taken; ItemStack actualInput = actualInputs.get(input, compare);
actualInputs.remove(taken, true); ItemStack taken = ItemHandlerHelper.copyStackWithSize(actualInput, input.stackSize);
took[i] = taken;
actualInputs.remove(taken, true);
}
} }
} }
}
if (!pattern.isProcessing()) { for (ItemStack byproduct : (!pattern.isProcessing() && pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
for (ItemStack byproduct : (pattern.isOredict() && missing.isEmpty() ? pattern.getByproducts(took) : pattern.getByproducts())) {
toInsert.add(byproduct.copy()); toInsert.add(byproduct.copy());
} }
for (ItemStack output : (pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs())) { for (ItemStack output : (!pattern.isProcessing() && pattern.isOredict() && missing.isEmpty() ? pattern.getOutputs(took) : pattern.getOutputs())) {
toInsert.add(output.copy()); toInsert.add(output.copy());
} }
} }