Fix more bugs with regular recipes.
This commit is contained in:
@@ -16,13 +16,13 @@ public class CraftingInserter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void insert(ItemStack stack) {
|
public void insert(ItemStack stack) {
|
||||||
items.push(new CraftingInserterItem(stack, CraftingInserterItemStatus.WAITING));
|
items.addLast(new CraftingInserterItem(stack, CraftingInserterItemStatus.WAITING));
|
||||||
|
|
||||||
network.getCraftingManager().sendCraftingMonitorUpdate();
|
network.getCraftingManager().sendCraftingMonitorUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertSingle() {
|
public void insertSingle() {
|
||||||
CraftingInserterItem item = items.peek();
|
CraftingInserterItem item = items.peekFirst();
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
if (network.insertItem(item.getStack(), item.getStack().getCount(), true) == null) {
|
if (network.insertItem(item.getStack(), item.getStack().getCount(), true) == null) {
|
||||||
|
|||||||
@@ -73,46 +73,61 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
took.add(possibleInput);
|
took.add(possibleInput);
|
||||||
|
|
||||||
int toExtract = possibleInput.getCount();
|
|
||||||
|
|
||||||
ItemStack fromSelf = results.get(possibleInput);
|
ItemStack fromSelf = results.get(possibleInput);
|
||||||
if (fromSelf != null) {
|
|
||||||
int toExtractFromSelf = Math.min(possibleInput.getCount(), fromSelf.getCount());
|
|
||||||
|
|
||||||
results.remove(possibleInput, toExtractFromSelf);
|
|
||||||
|
|
||||||
toExtract -= toExtractFromSelf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toExtract > 0) {
|
|
||||||
ItemStack fromNetwork = mutatedStorage.get(possibleInput);
|
ItemStack fromNetwork = mutatedStorage.get(possibleInput);
|
||||||
|
|
||||||
int fromNetworkCount = fromNetwork == null ? 0 : Math.min(toExtract, fromNetwork.getCount());
|
int available = (fromNetwork == null ? 0 : fromNetwork.getCount()) + (fromSelf == null ? 0 : fromSelf.getCount());
|
||||||
|
|
||||||
itemsToExtract.add(possibleInput, toExtract);
|
|
||||||
|
|
||||||
if (fromNetworkCount > 0) {
|
|
||||||
this.toTake.add(possibleInput, fromNetworkCount);
|
|
||||||
|
|
||||||
mutatedStorage.remove(possibleInput, fromNetworkCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fromNetworkCount < toExtract) {
|
|
||||||
int missing = toExtract - fromNetworkCount;
|
|
||||||
|
|
||||||
|
if (available < possibleInput.getCount()) {
|
||||||
ICraftingPattern subPattern = network.getCraftingManager().getPattern(possibleInput, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT);
|
ICraftingPattern subPattern = network.getCraftingManager().getPattern(possibleInput, IComparer.COMPARE_DAMAGE | IComparer.COMPARE_NBT);
|
||||||
|
|
||||||
if (subPattern == null) {
|
int needed = possibleInput.getCount() - available;
|
||||||
this.missing.add(possibleInput, missing);
|
|
||||||
|
if (subPattern != null) {
|
||||||
|
while ((fromSelf == null ? 0 : fromSelf.getCount()) < needed) {
|
||||||
|
this.steps.add(calculateInternal(mutatedStorage, results, subPattern));
|
||||||
|
|
||||||
|
fromSelf = results.get(possibleInput);
|
||||||
|
if (fromSelf == null) {
|
||||||
|
throw new IllegalStateException("Recursive calculation didn't yield anything");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fromNetwork = mutatedStorage.get(possibleInput);
|
||||||
|
|
||||||
|
int remaining = possibleInput.getCount();
|
||||||
|
|
||||||
|
while (remaining > 0) {
|
||||||
|
if (fromSelf != null) {
|
||||||
|
int toTake = Math.min(remaining, fromSelf.getCount());
|
||||||
|
|
||||||
|
this.toCraft.add(possibleInput, toTake);
|
||||||
|
|
||||||
|
itemsToExtract.add(possibleInput, toTake);
|
||||||
|
|
||||||
|
results.remove(possibleInput, toTake);
|
||||||
|
|
||||||
|
remaining -= toTake;
|
||||||
|
|
||||||
|
fromSelf = results.get(possibleInput);
|
||||||
|
} else if (fromNetwork != null) {
|
||||||
|
int toTake = Math.min(remaining, fromNetwork.getCount());
|
||||||
|
|
||||||
|
this.toTake.add(possibleInput, toTake);
|
||||||
|
|
||||||
|
itemsToExtract.add(possibleInput, toTake);
|
||||||
|
|
||||||
|
mutatedStorage.remove(possibleInput, toTake);
|
||||||
|
|
||||||
|
remaining -= toTake;
|
||||||
|
|
||||||
|
fromNetwork = mutatedStorage.get(possibleInput);
|
||||||
} else {
|
} else {
|
||||||
this.toCraft.add(possibleInput, missing);
|
this.missing.add(possibleInput, remaining);
|
||||||
|
|
||||||
while (missing > 0) {
|
remaining = 0;
|
||||||
this.steps.add(calculateInternal(mutatedStorage, results, subPattern)); // TODO: eating from itself?
|
|
||||||
|
|
||||||
missing -= getQuantityPerCraft(subPattern, possibleInput);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +212,7 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
elements.directAdd(new CraftingMonitorElementItemRender(
|
elements.directAdd(new CraftingMonitorElementItemRender(
|
||||||
network.getCraftingManager().getTasks().indexOf(this),
|
network.getCraftingManager().getTasks().indexOf(this),
|
||||||
requested != null ? requested : pattern.getOutputs().get(0),
|
requested,
|
||||||
quantity,
|
quantity,
|
||||||
0
|
0
|
||||||
));
|
));
|
||||||
@@ -337,16 +352,16 @@ public class CraftingTask implements ICraftingTask {
|
|||||||
private int getTickInterval(int speedUpgrades) {
|
private int getTickInterval(int speedUpgrades) {
|
||||||
switch (speedUpgrades) {
|
switch (speedUpgrades) {
|
||||||
case 1:
|
case 1:
|
||||||
return 8;
|
return 10;
|
||||||
case 2:
|
case 2:
|
||||||
return 6;
|
return 8;
|
||||||
case 3:
|
case 3:
|
||||||
return 4;
|
return 6;
|
||||||
case 4:
|
case 4:
|
||||||
return 2;
|
return 4;
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
return 10;
|
return 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ public class StackListFluid implements IStackList<FluidStack> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(@Nonnull FluidStack stack, int size) {
|
public void add(@Nonnull FluidStack stack, int size) {
|
||||||
|
if (stack == null || size < 0) {
|
||||||
|
throw new IllegalArgumentException("Cannot accept empty stack");
|
||||||
|
}
|
||||||
|
|
||||||
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
for (FluidStack otherStack : stacks.get(stack.getFluid())) {
|
||||||
if (stack.isFluidEqual(otherStack)) {
|
if (stack.isFluidEqual(otherStack)) {
|
||||||
otherStack.amount += size;
|
otherStack.amount += size;
|
||||||
|
|||||||
Reference in New Issue
Block a user