Skip to content

Commit

Permalink
Fix JEI/EMI/REI cache not invalidating when player inv changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Nov 27, 2024
1 parent c4c8d32 commit 3d1bceb
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ public static Optional<Pair<TerminalStorageTabIngredientComponentItemStackCrafti
return Optional.empty();
}

public static int getCurrentChangeId(TerminalStorageTabIngredientComponentClient<?, ?> tabClient, Player player) {
return tabClient.getLastChangeId() + player.getInventory().getTimesChanged();
}

public static <T extends RecipeInputSlot> Optional<RecipeTransferResult<T>> getMissingItems(Object cacheKey, ContainerTerminalStorageBase<?> container, Iterable<T> recipeInputSlots, Player player, TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting, TerminalStorageTabIngredientComponentClient<?, ?> tabClient, Function<ItemStack, Integer> itemStackToMatchCondition, Supplier<Integer> getId, Consumer<Integer> onChangeId) {
Callable<Optional<RecipeTransferResult<T>>> missingItemsSupplier =
() -> getMissingItemsUncached(container, recipeInputSlots, player, tabCommonCrafting, itemStackToMatchCondition, onChangeId);
if (getId.get() != tabClient.getLastChangeId()) {
if (getId.get() != getCurrentChangeId(tabClient, player)) {
// Clear cache when storage contents changed
recipeErrorCache.invalidateAll();
}
Expand Down Expand Up @@ -147,7 +151,7 @@ public static <T extends RecipeInputSlot> Optional<RecipeTransferResult<T>> getM
}
}

onChangeId.accept(tabClient.getLastChangeId());
onChangeId.accept(getCurrentChangeId(tabClient, player));
if (!slotsMissingItems.isEmpty() || !slotsMissingCraftableItems.isEmpty()) {
return Optional.of(new RecipeTransferResult<T>(slotsMissingItems, slotsMissingCraftableItems));
}
Expand Down

0 comments on commit 3d1bceb

Please sign in to comment.