diff --git a/src/main/java/appeng/crafting/execution/CraftingCpuHelper.java b/src/main/java/appeng/crafting/execution/CraftingCpuHelper.java index a8e074721d0..fba7169f844 100644 --- a/src/main/java/appeng/crafting/execution/CraftingCpuHelper.java +++ b/src/main/java/appeng/crafting/execution/CraftingCpuHelper.java @@ -102,11 +102,11 @@ public static KeyCounter[] extractPatternInputs( IPatternDetails details, ICraftingInventory sourceInv, Level level, - KeyCounter expectedOutputs) { + KeyCounter expectedOutputs, + KeyCounter expectedContainerItems) { // Extract inputs into the container. var inputs = details.getInputs(); - @SuppressWarnings("unchecked") KeyCounter[] inputHolder = new KeyCounter[inputs.length]; boolean found = true; @@ -120,7 +120,7 @@ public static KeyCounter[] extractPatternInputs( // Container items! var containerItem = inputs[x].getRemainingKey(template.key()); if (containerItem != null) { - expectedOutputs.add(containerItem, extracted); + expectedContainerItems.add(containerItem, extracted); } remainingMultiplier -= extracted; diff --git a/src/main/java/appeng/crafting/execution/CraftingCpuLogic.java b/src/main/java/appeng/crafting/execution/CraftingCpuLogic.java index 028e37a154b..e21d280677c 100644 --- a/src/main/java/appeng/crafting/execution/CraftingCpuLogic.java +++ b/src/main/java/appeng/crafting/execution/CraftingCpuLogic.java @@ -190,10 +190,11 @@ public int executeCrafting(int maxPatterns, CraftingService craftingService, IEn var details = task.getKey(); var expectedOutputs = new KeyCounter(); + var expectedContainerItems = new KeyCounter(); // Contains the inputs for the pattern. @Nullable var craftingContainer = CraftingCpuHelper.extractPatternInputs( - details, inventory, level, expectedOutputs); + details, inventory, level, expectedOutputs, expectedContainerItems); // Try to push to each provider. for (var provider : craftingService.getProviders(details)) { @@ -216,6 +217,11 @@ public int executeCrafting(int maxPatterns, CraftingService craftingService, IEn job.waitingFor.insert(expectedOutput.getKey(), expectedOutput.getLongValue(), Actionable.MODULATE); } + for (var expectedContainerItem : expectedContainerItems) { + job.waitingFor.insert(expectedContainerItem.getKey(), expectedContainerItem.getLongValue(), + Actionable.MODULATE); + job.timeTracker.addMaxItems(expectedContainerItem.getLongValue()); + } cluster.markDirty(); @@ -231,8 +237,9 @@ public int executeCrafting(int maxPatterns, CraftingService craftingService, IEn // Prepare next inputs. expectedOutputs.reset(); + expectedContainerItems.reset(); craftingContainer = CraftingCpuHelper.extractPatternInputs(details, inventory, - level, expectedOutputs); + level, expectedOutputs, expectedContainerItems); } } diff --git a/src/main/java/appeng/crafting/execution/ElapsedTimeTracker.java b/src/main/java/appeng/crafting/execution/ElapsedTimeTracker.java index 0e27a48b368..f81e323abb2 100644 --- a/src/main/java/appeng/crafting/execution/ElapsedTimeTracker.java +++ b/src/main/java/appeng/crafting/execution/ElapsedTimeTracker.java @@ -27,7 +27,9 @@ public class ElapsedTimeTracker { private long lastTime = System.nanoTime(); private long elapsedTime = 0; - private final long startItemCount; + // TODO 1.21 rename: "start item count" is not a good name: + // this item count can increase when container items are scheduled. + private long startItemCount; private long remainingItemCount; public ElapsedTimeTracker(long startItemCount) { @@ -49,13 +51,23 @@ public CompoundTag writeToNBT() { return data; } - void decrementItems(long itemDiff) { + private void updateTime() { long currentTime = System.nanoTime(); this.elapsedTime = this.elapsedTime + (currentTime - this.lastTime); this.lastTime = currentTime; + } + + void decrementItems(long itemDiff) { + updateTime(); this.remainingItemCount -= itemDiff; } + void addMaxItems(long itemDiff) { + updateTime(); + this.startItemCount += itemDiff; + this.remainingItemCount += itemDiff; + } + public long getElapsedTime() { if (remainingItemCount > 0) { return this.elapsedTime + (System.nanoTime() - this.lastTime);