Skip to content

Commit

Permalink
Fix #8020: Use up-to-date network contents for player-started craftin…
Browse files Browse the repository at this point in the history
…g simulations (#8097)

Fixes #8020 

This fixes the annoyance expressed in #8020 with a straightforward
solution. We want to make sure that the network state used by each
simulation corresponds to a snapshot taken AFTER the submission of the
previous job.
  • Loading branch information
Technici4n authored Aug 3, 2024
1 parent 1db2794 commit 8598ea6
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ public NetworkCraftingSimulationState(IStorageService storage, @Nullable IAction
return;
}

for (var stack : storage.getCachedInventory()) {
// We choose to re-query the available stacks every time a crafting simulation is started by a player.
// Using getCachedInventory causes issues with our "CTRL+click to craft" integration with EMI, which submits a
// job and then immediately starts a new simulation. We want that simulation to see the state of the network
// after the previous job was submitted in case of overlap between the recipes. More generally, having to replan
// is annoying, and we want to minimize the risk of that for player-started calculations.
// For non-player sources, it is fine to use the cached inventory: they will submit a new request eventually if
// this simulation or job fails.
var inventory = src.player().isEmpty() ? storage.getCachedInventory()
: storage.getInventory().getAvailableStacks();
for (var stack : inventory) {
long networkAmount = stack.getLongValue();
if (networkAmount > 0) {
this.list.add(stack.getKey(), networkAmount);
Expand Down

0 comments on commit 8598ea6

Please sign in to comment.