fixes some issues with extra outputs on processing patterns and some consitency in the preview
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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{" +
|
||||
|
@@ -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,23 +167,24 @@ public class CraftingTask implements ICraftingTask {
|
||||
}
|
||||
|
||||
if (missing.isEmpty()) {
|
||||
for (int i = 0; i < pattern.getInputs().size(); i++) {
|
||||
ItemStack input = pattern.getInputs().get(i);
|
||||
if (input != null) {
|
||||
ItemStack actualInput = actualInputs.get(input, compare);
|
||||
ItemStack taken = ItemHandlerHelper.copyStackWithSize(actualInput, input.stackSize);
|
||||
took[i] = taken;
|
||||
actualInputs.remove(taken, true);
|
||||
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) {
|
||||
ItemStack actualInput = actualInputs.get(input, compare);
|
||||
ItemStack taken = ItemHandlerHelper.copyStackWithSize(actualInput, input.stackSize);
|
||||
took[i] = taken;
|
||||
actualInputs.remove(taken, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user