Skip to content

Commit

Permalink
Improve JEI/REI/EMI performance, CyclopsMC/IntegratedTerminals#139
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Nov 27, 2024
1 parent a7c056e commit ab5ee06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +74,7 @@ public static <T extends RecipeInputSlot> Optional<RecipeTransferResult<T>> getM
}

public static <T extends RecipeInputSlot> Optional<RecipeTransferResult<T>> getMissingItemsUncached(ContainerTerminalStorageBase<?> container, Iterable<T> recipeInputSlots, Player player, TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting, Function<ItemStack, Integer> itemStackToMatchCondition, Consumer<Integer> onChangeId) {
TerminalStorageTabIngredientComponentClient tabClient = (TerminalStorageTabIngredientComponentClient)
TerminalStorageTabIngredientComponentClient<ItemStack, Integer> tabClient = (TerminalStorageTabIngredientComponentClient<ItemStack, Integer>)
container.getTabClient(container.getSelectedTab());

// Check in the player inventory and local client view if the required recipe ingredients are available
Expand All @@ -92,20 +90,16 @@ public static <T extends RecipeInputSlot> Optional<RecipeTransferResult<T>> getM
hayStackPlayer.addAll(player.getInventory().items);

// Build local client view of storage
List<TerminalStorageTabIngredientComponentClient.InstanceWithMetadata<ItemStack>> unfilteredIngredients = tabClient
.getUnfilteredIngredientsView(container.getSelectedChannel());
IIngredientCollectionMutable<ItemStack, Integer> hayStack = IngredientCollectionHelpers.createCollapsedCollection(IngredientComponent.ITEMSTACK);
IIngredientCollectionMutable<ItemStack, Integer> 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<HandlerWrappedTerminalCraftingOption<ItemStack>> craftingOptions = tabClient.getCraftingOptions(container.getSelectedChannel());
if (craftingOptions != null) {
hayStackCraftable.addAll(craftingOptions
.stream()
.flatMap(option -> tabClient.getUniqueCraftingOptionOutputs(option.getCraftingOption()).stream())
.toList());
}

List<T> slotsMissingItems = Lists.newArrayList();
List<T> slotsMissingCraftableItems = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,11 +39,9 @@ public EmiPlayerInventory getInventory(AbstractContainerScreen<T> screen) {
T container = screen.getMenu();
return RecipeTransferHelpers.getTabs(container)
.map(tabs -> {
List<TerminalStorageTabIngredientComponentClient.InstanceWithMetadata<ItemStack>> 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()));
})
Expand Down

0 comments on commit ab5ee06

Please sign in to comment.