From 1c58e661e7b0b2f4a336c46ec576a1785f3c72f5 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Mon, 30 Dec 2024 09:00:56 +0200 Subject: [PATCH] initial --- .../appeng/crafting/MECraftingInventory.java | 36 +++++++++++++++++-- .../v2/resolvers/CraftableItemResolver.java | 15 ++++++-- .../v2/resolvers/ExtractItemResolver.java | 14 +++++++- .../implementations/CraftingCPUCluster.java | 17 +++++++-- 4 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/main/java/appeng/crafting/MECraftingInventory.java b/src/main/java/appeng/crafting/MECraftingInventory.java index b9d5641eaca..6d727e7fccc 100644 --- a/src/main/java/appeng/crafting/MECraftingInventory.java +++ b/src/main/java/appeng/crafting/MECraftingInventory.java @@ -47,6 +47,10 @@ public class MECraftingInventory implements IMEInventory { private final boolean logMissing; private final IItemList missingCache; + private final IItemList failedToExtract = AEApi.instance().storage().createItemList(); + private MECraftingInventory cpuinv; + private boolean isMissingMode; + public MECraftingInventory() { this.localCache = AEApi.instance().storage().createItemList(); this.extractedCache = null; @@ -233,6 +237,18 @@ public StorageChannel getChannel() { return StorageChannel.ITEMS; } + public IItemList getExtractFailedList() { + return failedToExtract; + } + + public void setMissingMode(boolean b) { + this.isMissingMode = b; + } + + public void setCpuInventory(MECraftingInventory cp) { + this.cpuinv = cp; + } + public IItemList getItemList() { return this.localCache; } @@ -240,6 +256,7 @@ public IItemList getItemList() { public boolean commit(final BaseActionSource src) { final IItemList added = AEApi.instance().storage().createItemList(); final IItemList pulled = AEApi.instance().storage().createItemList(); + failedToExtract.resetStatus(); boolean failed = false; if (this.logInjections) { @@ -268,9 +285,22 @@ public boolean commit(final BaseActionSource src) { pulled.add(result = this.target.extractItems(extra, Actionable.MODULATE, src)); if (result == null || result.getStackSize() != extra.getStackSize()) { - failed = true; - handleCraftExtractFailure(extra, result, src); - break; + if (isMissingMode) { + if (result == null) { + failedToExtract.add(extra.copy()); + cpuinv.localCache.findPrecise(extra).setStackSize(0); + extra.setStackSize(0); + } else if (result.getStackSize() != extra.getStackSize()) { + failedToExtract + .add(extra.copy().setStackSize(extra.getStackSize() - result.getStackSize())); + cpuinv.localCache.findPrecise(extra).setStackSize(result.getStackSize()); + extra.setStackSize(result.getStackSize()); + } + } else { + failed = true; + handleCraftExtractFailure(extra, result, src); + break; + } } } } diff --git a/src/main/java/appeng/crafting/v2/resolvers/CraftableItemResolver.java b/src/main/java/appeng/crafting/v2/resolvers/CraftableItemResolver.java index 35081a97a0f..a21454ee29d 100644 --- a/src/main/java/appeng/crafting/v2/resolvers/CraftableItemResolver.java +++ b/src/main/java/appeng/crafting/v2/resolvers/CraftableItemResolver.java @@ -20,6 +20,7 @@ import org.apache.logging.log4j.Level; import appeng.api.config.Actionable; +import appeng.api.config.CraftingMode; import appeng.api.config.FuzzyMode; import appeng.api.networking.crafting.ICraftingPatternDetails; import appeng.api.storage.data.IAEItemStack; @@ -659,13 +660,23 @@ public List provideCraftingRequestResolvers(@Nonnull CraftingReque if (context.isPatternComplex(pattern)) { logComplexPattrn(pattern, request.remainingToProcess); for (int i = 0; i < request.remainingToProcess; i++) { - CraftFromPatternTask task = new CraftFromPatternTask(request, pattern, priority, false, true); + CraftFromPatternTask task = new CraftFromPatternTask( + request, + pattern, + priority, + request.craftingMode == CraftingMode.IGNORE_MISSING, + true); if (task.getState() != State.FAILURE) { tasks.add(task); } } } else { - CraftFromPatternTask task = new CraftFromPatternTask(request, pattern, priority, false, false); + CraftFromPatternTask task = new CraftFromPatternTask( + request, + pattern, + priority, + request.craftingMode == CraftingMode.IGNORE_MISSING, + false); if (task.getState() != State.FAILURE) { tasks.add(task); } diff --git a/src/main/java/appeng/crafting/v2/resolvers/ExtractItemResolver.java b/src/main/java/appeng/crafting/v2/resolvers/ExtractItemResolver.java index baa9ffb4b9d..88d56bdc802 100644 --- a/src/main/java/appeng/crafting/v2/resolvers/ExtractItemResolver.java +++ b/src/main/java/appeng/crafting/v2/resolvers/ExtractItemResolver.java @@ -173,7 +173,19 @@ public void startOnCpu(CraftingContext context, CraftingCPUCluster cpuCluster, if (stack.getStackSize() > 0) { IAEItemStack extracted = craftingInv.extractItems(stack, Actionable.MODULATE, context.actionSource); if (extracted == null || extracted.getStackSize() != stack.getStackSize()) { - throw new CraftBranchFailure(stack, stack.getStackSize()); + if (cpuCluster.isMissingMode()) { + if (extracted == null) { + cpuCluster.addEmitable(stack.copy()); + stack.setStackSize(0); + continue; + } else if (extracted.getStackSize() != stack.getStackSize()) { + cpuCluster.addEmitable( + stack.copy().setStackSize(stack.getStackSize() - extracted.getStackSize())); + stack.setStackSize(extracted.getStackSize()); + } + } else { + throw new CraftBranchFailure(stack, stack.getStackSize()); + } } cpuCluster.addStorage(extracted); } diff --git a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java index f3890acc0d7..f5094a691af 100644 --- a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java @@ -923,6 +923,10 @@ private void storeItems() { this.markDirty(); } + public boolean isMissingMode() { + return this.isMissingMode; + } + public ICraftingLink submitJob(final IGrid g, final ICraftingJob job, final BaseActionSource src, final ICraftingRequester requestingMachine) { if (this.myLastLink != null && this.isBusy() @@ -946,6 +950,9 @@ public ICraftingLink submitJob(final IGrid g, final ICraftingJob job, final Base final IStorageGrid sg = g.getCache(IStorageGrid.class); final IMEInventory storage = sg.getItemInventory(); final MECraftingInventory ci = new MECraftingInventory(storage, true, false, false); + this.isMissingMode = job.getCraftingMode() == CraftingMode.IGNORE_MISSING; + ci.setMissingMode(this.isMissingMode); + ci.setCpuInventory(this.inventory); try { this.waitingFor.resetStatus(); @@ -967,7 +974,12 @@ public ICraftingLink submitJob(final IGrid g, final ICraftingJob job, final Base this.isComplete = false; this.usedStorage = job.getByteTotal(); this.numsOfOutput = job.getOutput().getStackSize(); - this.isMissingMode = job.getCraftingMode() == CraftingMode.IGNORE_MISSING; + for (IAEItemStack fte : ci.getExtractFailedList()) { + this.waitingForMissing.add(fte); + } + for (IAEItemStack wfm : this.waitingForMissing) { + this.waitingFor.add(wfm); + } this.markDirty(); this.updateCPU(); @@ -1000,6 +1012,7 @@ public ICraftingLink submitJob(final IGrid g, final ICraftingJob job, final Base return whatLink; } } else { + this.waitingForMissing.resetStatus(); this.tasks.clear(); this.providers.clear(); this.inventory.getItemList().resetStatus(); @@ -1191,9 +1204,7 @@ public void addStorage(final IAEItemStack extractItems) { } public void addEmitable(final IAEItemStack i) { - this.waitingFor.add(i); this.waitingForMissing.add(i); - this.postCraftingStatusChange(i); } public void addCrafting(final ICraftingPatternDetails details, final long crafts) {