From 8bdcf652501646b076d51282070804db088bb0b7 Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Tue, 13 Apr 2021 18:00:31 -0700 Subject: [PATCH] Add the ability to force recipe/usage handlers to run in serial. Should fix the BM CME. --- README.md | 4 ++-- build.properties | 2 +- .../nei/recipe/GuiCraftingRecipe.java | 22 +++++++++++++----- src/codechicken/nei/recipe/GuiRecipe.java | 4 ++++ .../nei/recipe/GuiUsageRecipe.java | 23 +++++++++++++------ 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4816182e..91d7912d 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ We've tested this against all of the mods included in GTNH, as well as a limited * ItemList is no longer regenerated from the ItemRegistry on every inventory load * JEI (Or Creative) Style tabs [Optional] Note: Requires explicit support to be added for an ItemStack to render, otherwise falls back to the first two letters of the handler name. * Tabs/Handlers are loaded from a CSV config in the JAR (or optionally from the config folder). NBT IMCEvents `registerHandlerInfo` and `removeHandlerInfo` are available for mod authors to add handler information, using the same fields as the CSV file -* `@[Mod]->[item]` searching. ex: `@Gregtech->iron ingot` +* `@[Mod]->[item]` searching. ex: `@Mod.gregtech->iron ingot` * Cycle between Recipe, Utility, and Cheat mode by ctrl clicking on the Wrench Icon -* GT5u Tools/Items should now properly work with the Overlay Recipe Transfer +* GT5u Tools/Items and GT6 tools should now properly work with the Overlay Recipe Transfer ## Other items of note: diff --git a/build.properties b/build.properties index da01d48f..4bcd4595 100644 --- a/build.properties +++ b/build.properties @@ -2,4 +2,4 @@ mc_version=1.7.10 forge_version=10.13.4.1614-1.7.10 ccl_version=1.1.3.138 ccc_version=1.0.7.+ -mod_version=2.1.0-GTNH +mod_version=2.1.1-GTNH diff --git a/src/codechicken/nei/recipe/GuiCraftingRecipe.java b/src/codechicken/nei/recipe/GuiCraftingRecipe.java index 5d261e4f..85ece919 100644 --- a/src/codechicken/nei/recipe/GuiCraftingRecipe.java +++ b/src/codechicken/nei/recipe/GuiCraftingRecipe.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import java.util.ArrayList; +import java.util.Arrays; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -24,10 +25,14 @@ public class GuiCraftingRecipe extends GuiRecipe FuelRecipeHandler.findFuelsOnceParallel(); try { - handlers = ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream() + handlers = serialCraftingHandlers.stream().map(h -> h.getRecipeHandler(outputId, results)) + .filter(h -> h.numRecipes() > 0) + .collect(Collectors.toCollection(ArrayList::new)); + + handlers.addAll(ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream() .map(h -> h.getRecipeHandler(outputId, results)) .filter(h -> h.numRecipes() > 0) - .collect(Collectors.toCollection(ArrayList::new))).get(); + .collect(Collectors.toCollection(ArrayList::new))).get()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); return false; @@ -48,11 +53,15 @@ public class GuiCraftingRecipe extends GuiRecipe } public static void registerRecipeHandler(ICraftingHandler handler) { - for (ICraftingHandler handler1 : craftinghandlers) - if (handler1.getClass() == handler.getClass()) - return; + final Class handlerClass = handler.getClass(); + if(craftinghandlers.stream().anyMatch(h -> h.getClass() == handlerClass) || serialCraftingHandlers.stream().anyMatch(h -> h.getClass() == handlerClass)) + return; - craftinghandlers.add(handler); + final String handlerClassStr = handlerClass.getName(); + if(Arrays.asList(serialHandlers).contains(handlerClassStr)) + serialCraftingHandlers.add(handler); + else + craftinghandlers.add(handler); } public ArrayList getCurrentRecipeHandlers() { @@ -62,4 +71,5 @@ public class GuiCraftingRecipe extends GuiRecipe public ArrayList currenthandlers; public static ArrayList craftinghandlers = new ArrayList<>(); + public static ArrayList serialCraftingHandlers = new ArrayList<>(); } diff --git a/src/codechicken/nei/recipe/GuiRecipe.java b/src/codechicken/nei/recipe/GuiRecipe.java index 52a06056..9d992655 100644 --- a/src/codechicken/nei/recipe/GuiRecipe.java +++ b/src/codechicken/nei/recipe/GuiRecipe.java @@ -36,6 +36,10 @@ import java.util.Collections; import java.util.List; public abstract class GuiRecipe extends GuiContainer implements IGuiContainerOverlay, IGuiClientSide, IGuiHandleMouseWheel, IContainerTooltipHandler, INEIGuiHandler { + // List of handlers that need to be run in serial + protected static final String[] serialHandlers = { + "WayofTime.alchemicalWizardry.client.nei.NEIAlchemyRecipeHandler" + }; // Background image calculations private static final int BG_TOP_HEIGHT = 6; private static final int BG_MIDDLE_HEIGHT = 154; diff --git a/src/codechicken/nei/recipe/GuiUsageRecipe.java b/src/codechicken/nei/recipe/GuiUsageRecipe.java index ed86c0da..7db48a26 100644 --- a/src/codechicken/nei/recipe/GuiUsageRecipe.java +++ b/src/codechicken/nei/recipe/GuiUsageRecipe.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiContainer; import java.util.ArrayList; +import java.util.Arrays; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -24,10 +25,14 @@ public class GuiUsageRecipe extends GuiRecipe profiler.start("recipe.concurrent.usage"); try { - handlers = ItemList.forkJoinPool.submit(() -> usagehandlers.parallelStream() + handlers = serialUsageHandlers.stream().map(h -> h.getUsageHandler(inputId, ingredients)) + .filter(h -> h.numRecipes() > 0) + .collect(Collectors.toCollection(ArrayList::new)); + + handlers.addAll(ItemList.forkJoinPool.submit(() -> usagehandlers.parallelStream() .map(h -> h.getUsageHandler(inputId, ingredients)) .filter(h -> h.numRecipes() > 0) - .collect(Collectors.toCollection(ArrayList::new))).get(); + .collect(Collectors.toCollection(ArrayList::new))).get()); } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); return false; @@ -48,12 +53,15 @@ public class GuiUsageRecipe extends GuiRecipe } public static void registerUsageHandler(IUsageHandler handler) { - for (IUsageHandler handler1 : usagehandlers) { - if (handler1.getClass() == handler.getClass()) - return; - } + final Class handlerClass = handler.getClass(); + if(usagehandlers.stream().anyMatch(h -> h.getClass() == handlerClass) || serialUsageHandlers.stream().anyMatch(h -> h.getClass() == handlerClass)) + return; - usagehandlers.add(handler); + final String handlerClassStr = handlerClass.getName(); + if(Arrays.asList(serialHandlers).contains(handlerClassStr)) + serialUsageHandlers.add(handler); + else + usagehandlers.add(handler); } public ArrayList getCurrentRecipeHandlers() { @@ -63,4 +71,5 @@ public class GuiUsageRecipe extends GuiRecipe public ArrayList currenthandlers; public static ArrayList usagehandlers = new ArrayList<>(); + public static ArrayList serialUsageHandlers = new ArrayList<>(); }