Give back correct items on oredict craft

This commit is contained in:
Raoul Van den Berge
2016-10-11 22:11:06 +02:00
parent cd3bd045c3
commit 5ccd3dfe2e
3 changed files with 50 additions and 4 deletions

View File

@@ -43,6 +43,12 @@ public interface ICraftingPattern {
*/
List<ItemStack> getOutputs();
/**
* @param took the items took
* @return the outputs based on the items took
*/
List<ItemStack> getByproducts(ItemStack[] took);
/**
* @return the byproducts
*/

View File

@@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.List;
public class CraftingPattern implements ICraftingPattern {
private World world;
private ICraftingPatternContainer container;
private ItemStack stack;
private List<ItemStack> inputs = new ArrayList<>();
@@ -24,6 +25,7 @@ public class CraftingPattern implements ICraftingPattern {
private List<ItemStack> byproducts = new ArrayList<>();
public CraftingPattern(World world, ICraftingPatternContainer container, ItemStack stack) {
this.world = world;
this.container = container;
this.stack = stack;
@@ -98,6 +100,30 @@ public class CraftingPattern implements ICraftingPattern {
return outputs;
}
@Override
public List<ItemStack> getByproducts(ItemStack[] took) {
List<ItemStack> byproducts = new ArrayList<>();
InventoryCrafting inv = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer player) {
return false;
}
}, 3, 3);
for (int i = 0; i < 9; ++i) {
inv.setInventorySlotContents(i, took[i]);
}
for (ItemStack remaining : CraftingManager.getInstance().getRemainingItems(inv, world)) {
if (remaining != null) {
byproducts.add(remaining.copy());
}
}
return byproducts;
}
@Override
public List<ItemStack> getByproducts() {
return byproducts;

View File

@@ -65,11 +65,13 @@ public class CraftingTask implements ICraftingTask {
}
for (ItemStack extra : extras.getStacks()) {
toInsert.add(extra.copy());
toInsert.add(extra);
}
}
private void calculate(IItemStackList list, ICraftingPattern pattern, boolean basePattern) {
ItemStack[] took = new ItemStack[9];
if (pattern.isProcessing()) {
toProcess.add(new Processable(pattern));
}
@@ -78,13 +80,19 @@ public class CraftingTask implements ICraftingTask {
addExtras(pattern);
}
for (ItemStack input : pattern.getInputs()) {
for (int i = 0; i < pattern.getInputs().size(); ++i) {
ItemStack input = pattern.getInputs().get(i);
ItemStack inputInNetwork = list.get(input, compare);
if (inputInNetwork == null || inputInNetwork.stackSize == 0) {
ItemStack extra = extras.get(input, compare);
if (extra != null) {
if (!pattern.isProcessing()) {
took[i] = ItemHandlerHelper.copyStackWithSize(extra, 1);
}
decrOrRemoveExtras(extra);
} else {
ICraftingPattern inputPattern = network.getPattern(input, compare);
@@ -126,14 +134,18 @@ public class CraftingTask implements ICraftingTask {
}
} else {
if (!pattern.isProcessing()) {
toTake.add(input);
ItemStack take = ItemHandlerHelper.copyStackWithSize(inputInNetwork, 1);
toTake.add(take);
took[i] = take;
}
list.remove(inputInNetwork, 1, true);
}
}
for (ItemStack byproduct : pattern.getByproducts()) {
for (ItemStack byproduct : (pattern.isOredict() ? pattern.getByproducts(took) : pattern.getByproducts())) {
extras.add(byproduct.copy());
}
}
@@ -149,6 +161,8 @@ public class CraftingTask implements ICraftingTask {
"\n, toTakeFluids=" + toTakeFluids +
"\n, toCraft=" + toCraft +
"\n, toProcess=" + toProcess +
"\n, extras=" + extras +
"\n, toInsert=" + toInsert +
"\n, missing=" + missing +
'}';
}