Parallelize recipe handlers

This commit is contained in:
Balthild authored and Jason Mitchell committed 2020-05-25 13:54:38 -07:00
1 parent edcd410ee1
commit c2acfb7d8a
2 files changed
+14 -19

No files matched your search

@@ -6,6 +6,9 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class GuiCraftingRecipe extends GuiRecipe
{
@@ -13,15 +16,11 @@ public class GuiCraftingRecipe extends GuiRecipe
Minecraft mc = NEIClientUtils.mc();
GuiContainer prevscreen = mc.currentScreen instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
ArrayList<ICraftingHandler> handlers = new ArrayList<>();
for (ICraftingHandler craftinghandler : craftinghandlers) {
profiler.start(craftinghandler.getRecipeName());
ICraftingHandler handler = craftinghandler.getRecipeHandler(outputId, results);
if (handler.numRecipes() > 0)
handlers.add(handler);
}
profiler.end();
ArrayList<ICraftingHandler> handlers = craftinghandlers.parallelStream()
.map(h -> h.getRecipeHandler(outputId, results))
.filter(h -> h.numRecipes() > 0)
.collect(Collectors.toCollection(ArrayList::new));
if (handlers.isEmpty())
return false;
+6 -10
View File
@@ -1,11 +1,11 @@
package codechicken.nei.recipe;
import codechicken.core.TaskProfiler;
import codechicken.nei.NEIClientUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import java.util.ArrayList;
import java.util.stream.Collectors;
public class GuiUsageRecipe extends GuiRecipe
{
@@ -13,15 +13,11 @@ public class GuiUsageRecipe extends GuiRecipe
Minecraft mc = NEIClientUtils.mc();
GuiContainer prevscreen = mc.currentScreen instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
ArrayList<IUsageHandler> handlers = new ArrayList<>();
for (IUsageHandler usagehandler : usagehandlers) {
profiler.start(usagehandler.getRecipeName());
IUsageHandler handler = usagehandler.getUsageHandler(inputId, ingredients);
if (handler.numRecipes() > 0)
handlers.add(handler);
}
profiler.end();
ArrayList<IUsageHandler> handlers = usagehandlers.parallelStream()
.map(h -> h.getUsageHandler(inputId, ingredients))
.filter(h -> h.numRecipes() > 0)
.collect(Collectors.toCollection(ArrayList::new));
if (handlers.isEmpty())
return false;