Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily construct GTRecipeWrappers in JEI recipe category #2714

Open
wants to merge 1 commit into
base: 1.20.1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading