Skip to content

Commit

Permalink
Merge remote-tracking branch 'lordIcocain/improve_missing_mode_new_ho…
Browse files Browse the repository at this point in the history
…rizon' into dev

# Conflicts:
#	src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java
  • Loading branch information
Dream-Master committed Dec 30, 2024
2 parents 394e08c + b0b3b2b commit 5393d84
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
36 changes: 33 additions & 3 deletions src/main/java/appeng/crafting/MECraftingInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack> {
private final boolean logMissing;
private final IItemList<IAEItemStack> missingCache;

private final IItemList<IAEItemStack> failedToExtract = AEApi.instance().storage().createItemList();
private MECraftingInventory cpuinv;
private boolean isMissingMode;

public MECraftingInventory() {
this.localCache = AEApi.instance().storage().createItemList();
this.extractedCache = null;
Expand Down Expand Up @@ -233,13 +237,26 @@ public StorageChannel getChannel() {
return StorageChannel.ITEMS;
}

public IItemList<IAEItemStack> getExtractFailedList() {
return failedToExtract;
}

public void setMissingMode(boolean b) {
this.isMissingMode = b;
}

public void setCpuInventory(MECraftingInventory cp) {
this.cpuinv = cp;
}

public IItemList<IAEItemStack> getItemList() {
return this.localCache;
}

public boolean commit(final BaseActionSource src) {
final IItemList<IAEItemStack> added = AEApi.instance().storage().createItemList();
final IItemList<IAEItemStack> pulled = AEApi.instance().storage().createItemList();
failedToExtract.resetStatus();
boolean failed = false;

if (this.logInjections) {
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -659,13 +660,23 @@ public List<CraftingTask> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -946,6 +950,9 @@ public ICraftingLink submitJob(final IGrid g, final ICraftingJob job, final Base
final IStorageGrid sg = g.getCache(IStorageGrid.class);
final IMEInventory<IAEItemStack> 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();
Expand All @@ -967,7 +974,9 @@ 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);
}
Expand Down Expand Up @@ -1196,7 +1205,6 @@ public void addStorage(final IAEItemStack extractItems) {

public void addEmitable(final IAEItemStack i) {
this.waitingForMissing.add(i);
this.postCraftingStatusChange(i);
}

public void addCrafting(final ICraftingPatternDetails details, final long crafts) {
Expand Down

0 comments on commit 5393d84

Please sign in to comment.