diff --git a/src/main/java/codechicken/nei/api/ShortcutInputHandler.java b/src/main/java/codechicken/nei/api/ShortcutInputHandler.java index 15d2e830..f0cc507c 100644 --- a/src/main/java/codechicken/nei/api/ShortcutInputHandler.java +++ b/src/main/java/codechicken/nei/api/ShortcutInputHandler.java @@ -165,11 +165,17 @@ public abstract class ShortcutInputHandler { RecipeChainMath math = null; if (slot == null) { - math = RecipeChainMath.of(Recipe.of(recipeId), slot != null ? slot.getMultiplier() : 1); + final Recipe recipe = Recipe.of(recipeId); + if (recipe != null) { + math = RecipeChainMath.of(recipe, 1); + } } else if (slot.getRecipeId() != null && !slot.isIngredient()) { if (slot.getGroup().crafting == null) { - math = RecipeChainMath.of(Recipe.of(slot.getRecipeId()), slot != null ? slot.getMultiplier() : 1); + final Recipe recipe = Recipe.of(slot.getRecipeId()); + if (recipe != null) { + math = RecipeChainMath.of(recipe, slot != null ? slot.getMultiplier() : 1); + } } else { math = ItemPanels.bookmarkPanel.getGrid() .createRecipeChainMath(slot.getGroupId(), slot.getRecipeId()); diff --git a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java index 5ca87bd7..d7fa799f 100644 --- a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java +++ b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java @@ -386,8 +386,8 @@ public class GuiContainerManager { public static void enableMatrixStackLogging() { if (!contextEnabled) { - modelviewDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH); GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + modelviewDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH); contextEnabled = true; } } diff --git a/src/main/java/codechicken/nei/recipe/Recipe.java b/src/main/java/codechicken/nei/recipe/Recipe.java index d6984eba..9832de85 100644 --- a/src/main/java/codechicken/nei/recipe/Recipe.java +++ b/src/main/java/codechicken/nei/recipe/Recipe.java @@ -2,7 +2,6 @@ package codechicken.nei.recipe; import java.util.ArrayList; import java.util.Arrays; -import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -16,7 +15,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; -import codechicken.nei.LRUCache; import codechicken.nei.NEIServerUtils; import codechicken.nei.PositionedStack; import codechicken.nei.api.ItemInfo; @@ -289,8 +287,6 @@ public class Recipe { } } - private static final LRUCache recipeCache = new LRUCache<>(200); - private final String handlerName; private final RecipeIngredient[] results; private final RecipeIngredient[] ingredients; @@ -298,14 +294,6 @@ public class Recipe { private Recipe(String handlerName, List ingredients, List results) { this.handlerName = handlerName; - - ingredients.sort( - Comparator.comparingInt((RecipeIngredient ingr) -> ingr.rely) - .thenComparingInt((RecipeIngredient ingr) -> ingr.relx)); - results.sort( - Comparator.comparingInt((RecipeIngredient ingr) -> ingr.rely) - .thenComparingInt((RecipeIngredient ingr) -> ingr.relx)); - this.ingredients = ingredients.toArray(new RecipeIngredient[ingredients.size()]); this.results = results.toArray(new RecipeIngredient[results.size()]); } @@ -343,17 +331,13 @@ public class Recipe { return null; } - final Recipe recipe = recipeCache.computeIfAbsent(recipeId, ri -> { - final RecipeHandlerRef handlerRef = RecipeHandlerRef.of(recipeId); + final RecipeHandlerRef handlerRef = RecipeHandlerRef.of(recipeId); - if (handlerRef != null) { - return Recipe.of(handlerRef); - } + if (handlerRef != null) { + return Recipe.of(handlerRef); + } - return null; - }); - - return recipe != null ? recipe.copy() : null; + return null; } protected static List extractItems(List items) { diff --git a/src/main/java/codechicken/nei/recipe/RecipeHandlerRef.java b/src/main/java/codechicken/nei/recipe/RecipeHandlerRef.java index 4fcdafb9..3255f7a0 100644 --- a/src/main/java/codechicken/nei/recipe/RecipeHandlerRef.java +++ b/src/main/java/codechicken/nei/recipe/RecipeHandlerRef.java @@ -5,6 +5,7 @@ import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; +import codechicken.nei.LRUCache; import codechicken.nei.LayoutManager; import codechicken.nei.api.IOverlayHandler; import codechicken.nei.api.IRecipeOverlayRenderer; @@ -13,6 +14,7 @@ import codechicken.nei.recipe.Recipe.RecipeId; public class RecipeHandlerRef { + private static final LRUCache recipeRefCache = new LRUCache<>(200); public final IRecipeHandler handler; public final int recipeIndex; @@ -28,19 +30,22 @@ public class RecipeHandlerRef { public static RecipeHandlerRef of(RecipeId recipeId) { if (recipeId.getResult() != null && !recipeId.getIngredients().isEmpty()) { - final List handlers = GuiCraftingRecipe - .getCraftingHandlers("recipeId", recipeId.getResult(), recipeId); + return recipeRefCache.computeIfAbsent(recipeId, ri -> { + final List handlers = GuiCraftingRecipe + .getCraftingHandlers("recipeId", recipeId.getResult(), recipeId); - for (ICraftingHandler handler : handlers) { - int refIndex = SearchRecipeHandler.findFirst( - handler, - recipeIndex -> recipeId.equalsIngredients(handler.getIngredientStacks(recipeIndex))); + for (ICraftingHandler handler : handlers) { + int refIndex = SearchRecipeHandler.findFirst( + handler, + recipeIndex -> recipeId.equalsIngredients(handler.getIngredientStacks(recipeIndex))); - if (refIndex >= 0) { - return new RecipeHandlerRef(handler, refIndex); + if (refIndex >= 0) { + return new RecipeHandlerRef(handler, refIndex); + } } - } + return null; + }); } return null;