diff --git a/build.properties b/build.properties index a2547ef3..eea52d41 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.0.7-GTNH +mod_version=2.0.8-GTNH diff --git a/src/codechicken/nei/recipe/FurnaceRecipeHandler.java b/src/codechicken/nei/recipe/FurnaceRecipeHandler.java index 86cfd71f..86aec232 100644 --- a/src/codechicken/nei/recipe/FurnaceRecipeHandler.java +++ b/src/codechicken/nei/recipe/FurnaceRecipeHandler.java @@ -70,6 +70,8 @@ public class FurnaceRecipeHandler extends TemplateRecipeHandler @Override public TemplateRecipeHandler newInstance() { + // Use the non parallel version since we might already be using the forkJoinPool and might have no threads available + // This will ideally have been pre-cached elsewhere and will be a NOOP findFuelsOnce(); return super.newInstance(); } diff --git a/src/codechicken/nei/recipe/GuiCraftingRecipe.java b/src/codechicken/nei/recipe/GuiCraftingRecipe.java index 27ae5739..5d261e4f 100644 --- a/src/codechicken/nei/recipe/GuiCraftingRecipe.java +++ b/src/codechicken/nei/recipe/GuiCraftingRecipe.java @@ -21,7 +21,7 @@ public class GuiCraftingRecipe extends GuiRecipe profiler.start("recipe.concurrent.crafting"); // Pre-find the fuels so we're not fighting over it - FuelRecipeHandler.findFuelsOnce(); + FuelRecipeHandler.findFuelsOnceParallel(); try { handlers = ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream() diff --git a/src/codechicken/nei/recipe/GuiUsageRecipe.java b/src/codechicken/nei/recipe/GuiUsageRecipe.java index 3ecd63b8..ed86c0da 100644 --- a/src/codechicken/nei/recipe/GuiUsageRecipe.java +++ b/src/codechicken/nei/recipe/GuiUsageRecipe.java @@ -12,13 +12,16 @@ import java.util.stream.Collectors; public class GuiUsageRecipe extends GuiRecipe { - public static boolean openRecipeGui(String inputId, Object... ingredients) { + public static boolean openRecipeGui(String inputId, Object... ingredients) { Minecraft mc = NEIClientUtils.mc(); GuiContainer prevscreen = mc.currentScreen instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null; ArrayList handlers; TaskProfiler profiler = ProfilerRecipeHandler.getProfiler(); + // Pre-find the fuels so we're not fighting over it + FuelRecipeHandler.findFuelsOnceParallel(); + profiler.start("recipe.concurrent.usage"); try { handlers = ItemList.forkJoinPool.submit(() -> usagehandlers.parallelStream() diff --git a/src/codechicken/nei/recipe/TemplateRecipeHandler.java b/src/codechicken/nei/recipe/TemplateRecipeHandler.java index 50720ab4..93ba9310 100644 --- a/src/codechicken/nei/recipe/TemplateRecipeHandler.java +++ b/src/codechicken/nei/recipe/TemplateRecipeHandler.java @@ -69,15 +69,27 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH lock.lock(); try { if (afuels == null || afuels.isEmpty()) - findFuels(); + findFuels(false); } finally { lock.unlock(); } } + + public static void findFuelsOnceParallel() { + // Ensure we only find fuels once, even if threaded + lock.lock(); + try { + if (afuels == null || afuels.isEmpty()) + findFuels(true); + } finally { + lock.unlock(); + } + } + private static Set efuels; @SuppressWarnings("UnstableApiUsage") - private static void findFuels() { - Set efuels = new HashSet<>(); + private static void findFuels(boolean parallel) { + efuels = new HashSet<>(); efuels.add(Item.getItemFromBlock(Blocks.brown_mushroom)); efuels.add(Item.getItemFromBlock(Blocks.red_mushroom)); efuels.add(Item.getItemFromBlock(Blocks.standing_sign)); @@ -86,20 +98,26 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH efuels.add(Item.getItemFromBlock(Blocks.trapped_chest)); Stopwatch stopwatch = Stopwatch.createStarted(); - try { - afuels = ItemList.forkJoinPool.submit(() -> ItemList.items.parallelStream().map(itemStack -> { - if (efuels.contains(itemStack.getItem())) return null; - final int burnTime = TileEntityFurnace.getItemBurnTime(itemStack); - if (burnTime <= 0) return null; - return new TemplateFuelPair(itemStack.copy(), burnTime); - }).filter(Objects::nonNull).collect(Collectors.toList())).get(); - } catch (InterruptedException | ExecutionException e) { - afuels = new ArrayList<>(); - e.printStackTrace(); + if (parallel) { + try { + afuels = ItemList.forkJoinPool.submit(() -> ItemList.items.parallelStream().map(TemplateRecipeHandler::identifyFuel).filter(Objects::nonNull).collect(Collectors.toList())).get(); + } catch (InterruptedException | ExecutionException e) { + afuels = new ArrayList<>(); + e.printStackTrace(); + } + } else { + afuels = ItemList.items.stream().map(TemplateRecipeHandler::identifyFuel).filter(Objects::nonNull).collect(Collectors.toList()); } NEIClientConfig.logger.info("FindFuels took " + stopwatch.stop() ); } + + private static TemplateFuelPair identifyFuel(final ItemStack itemStack) { + if (efuels.contains(itemStack.getItem())) return null; + final int burnTime = TileEntityFurnace.getItemBurnTime(itemStack); + if (burnTime <= 0) return null; + return new TemplateFuelPair(itemStack.copy(), burnTime); + } /** * This Recipe Handler runs on this internal class @@ -523,7 +541,9 @@ public abstract class TemplateRecipeHandler implements ICraftingHandler, IUsageH public TemplateRecipeHandler newInstance() { try { - findFuelsOnce(); + // Use the non parallel version since we might already be using the forkJoinPool and might have no threads available + // This will ideally have been pre-cached elsewhere and will be a NOOP + findFuelsOnce(); return getClass().newInstance(); } catch (Exception e) { throw new RuntimeException(e);