From ab5ee063f74e1d80c9ba4acbd8d485d4478d5eb7 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Wed, 27 Nov 2024 09:05:47 +0100 Subject: [PATCH] Improve JEI/REI/EMI performance, CyclopsMC/IntegratedTerminals#139 --- .../common/RecipeTransferHelpers.java | 28 ++++++++----------- .../TerminalStorageEmiRecipeHandler.java | 10 ++----- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/cyclops/integratedterminalscompat/modcompat/common/RecipeTransferHelpers.java b/src/main/java/org/cyclops/integratedterminalscompat/modcompat/common/RecipeTransferHelpers.java index e910a39..f6ef6f5 100644 --- a/src/main/java/org/cyclops/integratedterminalscompat/modcompat/common/RecipeTransferHelpers.java +++ b/src/main/java/org/cyclops/integratedterminalscompat/modcompat/common/RecipeTransferHelpers.java @@ -20,14 +20,12 @@ import org.cyclops.integratedterminals.core.terminalstorage.TerminalStorageTabIngredientComponentClient; import org.cyclops.integratedterminals.core.terminalstorage.TerminalStorageTabIngredientComponentItemStackCrafting; import org.cyclops.integratedterminals.core.terminalstorage.TerminalStorageTabIngredientComponentItemStackCraftingCommon; +import org.cyclops.integratedterminals.core.terminalstorage.crafting.HandlerWrappedTerminalCraftingOption; import org.cyclops.integratedterminals.inventory.container.ContainerTerminalStorageBase; import org.cyclops.integratedterminalscompat.IntegratedTerminalsCompat; import org.cyclops.integratedterminalscompat.network.packet.TerminalStorageIngredientItemStackCraftingGridSetRecipe; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -76,7 +74,7 @@ public static Optional> getM } public static Optional> getMissingItemsUncached(ContainerTerminalStorageBase container, Iterable recipeInputSlots, Player player, TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting, Function itemStackToMatchCondition, Consumer onChangeId) { - TerminalStorageTabIngredientComponentClient tabClient = (TerminalStorageTabIngredientComponentClient) + TerminalStorageTabIngredientComponentClient tabClient = (TerminalStorageTabIngredientComponentClient) container.getTabClient(container.getSelectedTab()); // Check in the player inventory and local client view if the required recipe ingredients are available @@ -92,20 +90,16 @@ public static Optional> getM hayStackPlayer.addAll(player.getInventory().items); // Build local client view of storage - List> unfilteredIngredients = tabClient - .getUnfilteredIngredientsView(container.getSelectedChannel()); IIngredientCollectionMutable hayStack = IngredientCollectionHelpers.createCollapsedCollection(IngredientComponent.ITEMSTACK); IIngredientCollectionMutable hayStackCraftable = IngredientCollectionHelpers.createCollapsedCollection(IngredientComponent.ITEMSTACK); - hayStack.addAll(unfilteredIngredients - .stream() - .filter(i -> i.getCraftingOption() == null) - .map(TerminalStorageTabIngredientComponentClient.InstanceWithMetadata::getInstance) - .collect(Collectors.toList())); - hayStackCraftable.addAll(unfilteredIngredients - .stream() - .filter(i -> i.getCraftingOption() != null) - .map(TerminalStorageTabIngredientComponentClient.InstanceWithMetadata::getInstance) - .collect(Collectors.toList())); + hayStack.addAll(tabClient.getRawUnfilteredIngredientsView(container.getSelectedChannel())); + Collection> craftingOptions = tabClient.getCraftingOptions(container.getSelectedChannel()); + if (craftingOptions != null) { + hayStackCraftable.addAll(craftingOptions + .stream() + .flatMap(option -> tabClient.getUniqueCraftingOptionOutputs(option.getCraftingOption()).stream()) + .toList()); + } List slotsMissingItems = Lists.newArrayList(); List slotsMissingCraftableItems = Lists.newArrayList(); diff --git a/src/main/java/org/cyclops/integratedterminalscompat/modcompat/emi/terminalstorage/TerminalStorageEmiRecipeHandler.java b/src/main/java/org/cyclops/integratedterminalscompat/modcompat/emi/terminalstorage/TerminalStorageEmiRecipeHandler.java index 5d69943..a8ea0c1 100644 --- a/src/main/java/org/cyclops/integratedterminalscompat/modcompat/emi/terminalstorage/TerminalStorageEmiRecipeHandler.java +++ b/src/main/java/org/cyclops/integratedterminalscompat/modcompat/emi/terminalstorage/TerminalStorageEmiRecipeHandler.java @@ -16,10 +16,8 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; -import net.minecraft.world.item.ItemStack; import org.apache.commons.lang3.tuple.Pair; import org.cyclops.cyclopscore.datastructure.Wrapper; -import org.cyclops.integratedterminals.core.terminalstorage.TerminalStorageTabIngredientComponentClient; import org.cyclops.integratedterminals.inventory.container.ContainerTerminalStorageBase; import org.cyclops.integratedterminalscompat.modcompat.common.RecipeTransferHelpers; import org.cyclops.integratedterminalscompat.modcompat.common.RecipeTransferResult; @@ -41,11 +39,9 @@ public EmiPlayerInventory getInventory(AbstractContainerScreen screen) { T container = screen.getMenu(); return RecipeTransferHelpers.getTabs(container) .map(tabs -> { - List> unfilteredIngredients = tabs.getValue() - .getUnfilteredIngredientsView(container.getSelectedChannel()); - return new EmiPlayerInventory(unfilteredIngredients.stream() - .filter(ingredient -> ingredient.getCraftingOption() == null) - .map(TerminalStorageTabIngredientComponentClient.InstanceWithMetadata::getInstance) + return new EmiPlayerInventory(tabs.getValue() + .getRawUnfilteredIngredientsView(container.getSelectedChannel()) + .stream() .map(EmiStack::of) .collect(Collectors.toList())); })