Skip to content

Commit

Permalink
fix: rare autocrafting crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkere committed Nov 5, 2023
1 parent ea71488 commit ca4199c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,20 @@ public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<Ite

if (interval == 0 || ticks % interval == 0) {
for (int i = 0; i < container.getMaximumSuccessfulCraftingUpdates(); i++) {
if (IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(true), internalStorage, Action.SIMULATE) != null) {
IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(false), internalStorage, Action.PERFORM);

var simulatedRequirements = requirements.getSingleItemRequirementSet(true);
if(simulatedRequirements == null) {
return;
}

if (IoUtil.extractFromInternalItemStorage(simulatedRequirements, internalStorage, Action.SIMULATE) != null) {

var actualRequirements = requirements.getSingleItemRequirementSet(false);
if(actualRequirements == null) {
return;
}

IoUtil.extractFromInternalItemStorage(actualRequirements, internalStorage, Action.PERFORM);

ItemStack output = getPattern().getOutput(recipe, network.getLevel().registryAccess());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<ItemStack> getSingleItemRequirementSet(boolean simulate) {
}
}
} else {
throw new IllegalStateException("Bad!");
return null;
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public List<FluidStack> getSingleFluidRequirementSet(boolean simulate) {
}
}
} else {
throw new IllegalStateException("Bad!");
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,20 @@ public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<Ite

boolean hasAllRequirements = false;

List<ItemStack> extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(true), internalStorage, Action.SIMULATE);
var simulatedRequirements = requirements.getSingleItemRequirementSet(true);
if(simulatedRequirements == null) {
return;
}

List<ItemStack> extractedItems = IoUtil.extractFromInternalItemStorage(simulatedRequirements, internalStorage, Action.SIMULATE);
List<FluidStack> extractedFluids = null;
if (extractedItems != null) {
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(true), internalFluidStorage, Action.SIMULATE);
var simulatedFluidRequirements = requirements.getSingleFluidRequirementSet(true);
if(simulatedFluidRequirements == null) {
return;
}

extractedFluids = IoUtil.extractFromInternalFluidStorage(simulatedFluidRequirements, internalFluidStorage, Action.SIMULATE);
if (extractedFluids != null) {
hasAllRequirements = true;
}
Expand All @@ -151,9 +161,17 @@ public void update(INetwork network, int ticks, NodeList nodes, IStorageDisk<Ite
}

this.state = ProcessingState.READY;
var actualRequirements = requirements.getSingleItemRequirementSet(false);
if(actualRequirements == null) {
return;
}
extractedItems = IoUtil.extractFromInternalItemStorage(actualRequirements, internalStorage, Action.PERFORM);

extractedItems = IoUtil.extractFromInternalItemStorage(requirements.getSingleItemRequirementSet(false), internalStorage, Action.PERFORM);
extractedFluids = IoUtil.extractFromInternalFluidStorage(requirements.getSingleFluidRequirementSet(false), internalFluidStorage, Action.PERFORM);
var actualFluidRequirements = requirements.getSingleFluidRequirementSet(false);
if(actualFluidRequirements == null) {
return;
}
extractedFluids = IoUtil.extractFromInternalFluidStorage(actualFluidRequirements, internalFluidStorage, Action.PERFORM);

container.insertItemsIntoInventory(extractedItems, Action.PERFORM);
container.insertFluidsIntoInventory(extractedFluids, Action.PERFORM);
Expand Down

0 comments on commit ca4199c

Please sign in to comment.