Skip to content

Commit

Permalink
Lazily construct GTRecipeWrappers in JEI recipe category
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Jan 11, 2025
1 parent 2472c9c commit 144fd03
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.api.machine.MachineDefinition;
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.api.recipe.category.GTRecipeCategory;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
Expand All @@ -25,12 +26,13 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Function;

public class GTRecipeJEICategory extends ModularUIRecipeCategory<GTRecipeWrapper> {
public class GTRecipeJEICategory extends ModularUIRecipeCategory<GTRecipe> {

public static final Function<GTRecipeCategory, RecipeType<GTRecipeWrapper>> TYPES = Util
.memoize(c -> new RecipeType<>(c.registryKey, GTRecipeWrapper.class));
public static final Function<GTRecipeCategory, RecipeType<GTRecipe>> TYPES = Util
.memoize(c -> new RecipeType<>(c.registryKey, GTRecipe.class));

private final GTRecipeCategory category;
@Getter
Expand All @@ -40,6 +42,7 @@ public class GTRecipeJEICategory extends ModularUIRecipeCategory<GTRecipeWrapper

public GTRecipeJEICategory(IJeiHelpers helpers,
@NotNull GTRecipeCategory category) {
super(GTRecipeWrapper::new);
this.category = category;
var recipeType = category.getRecipeType();
IGuiHelper guiHelper = helpers.getGuiHelper();
Expand All @@ -53,9 +56,7 @@ public static void registerRecipes(IRecipeRegistration registration) {
if (!category.shouldRegisterDisplays()) continue;
var type = category.getRecipeType();
if (category == type.getCategory()) type.buildRepresentativeRecipes();
var wrapped = type.getRecipesInCategory(category).stream()
.map(GTRecipeWrapper::new)
.toList();
var wrapped = List.copyOf(type.getRecipesInCategory(category));
registration.addRecipes(TYPES.apply(category), wrapped);
}
}
Expand All @@ -80,7 +81,7 @@ public static RecipeType<?> machineType(GTRecipeCategory category) {

@Override
@NotNull
public RecipeType<GTRecipeWrapper> getRecipeType() {
public RecipeType<GTRecipe> getRecipeType() {
return TYPES.apply(category);
}

Expand All @@ -91,7 +92,7 @@ public Component getTitle() {
}

@Override
public @Nullable ResourceLocation getRegistryName(@NotNull GTRecipeWrapper wrapper) {
return wrapper.recipe.id;
public @Nullable ResourceLocation getRegistryName(@NotNull GTRecipe recipe) {
return recipe.id;
}
}

0 comments on commit 144fd03

Please sign in to comment.