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
*/
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.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import java.util.ArrayList;
@@ -165,6 +166,17 @@ public class CraftingPattern implements ICraftingPattern {
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
public String toString() {
return "CraftingPattern{" +

View File

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