mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-19 11:59:17 +00:00
Introduces a `findFuelsOnceParallel` that is called before the parallel recipe/usage handlers are run (which now call the non parallel version of findFuels())
66 lines
2.2 KiB
Java
66 lines
2.2 KiB
Java
package codechicken.nei.recipe;
|
|
|
|
import codechicken.core.TaskProfiler;
|
|
import codechicken.nei.ItemList;
|
|
import codechicken.nei.NEIClientUtils;
|
|
import net.minecraft.client.Minecraft;
|
|
import net.minecraft.client.gui.GuiScreen;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.stream.Collectors;
|
|
|
|
public class GuiCraftingRecipe extends GuiRecipe
|
|
{
|
|
public static boolean openRecipeGui(String outputId, Object... results) {
|
|
Minecraft mc = NEIClientUtils.mc();
|
|
GuiScreen prevscreen = mc.currentScreen;// instanceof GuiContainer ? (GuiContainer) mc.currentScreen : null;
|
|
|
|
ArrayList<ICraftingHandler> handlers;
|
|
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
|
|
profiler.start("recipe.concurrent.crafting");
|
|
|
|
// Pre-find the fuels so we're not fighting over it
|
|
FuelRecipeHandler.findFuelsOnceParallel();
|
|
|
|
try {
|
|
handlers = ItemList.forkJoinPool.submit(() -> craftinghandlers.parallelStream()
|
|
.map(h -> h.getRecipeHandler(outputId, results))
|
|
.filter(h -> h.numRecipes() > 0)
|
|
.collect(Collectors.toCollection(ArrayList::new))).get();
|
|
} catch (InterruptedException | ExecutionException e) {
|
|
e.printStackTrace();
|
|
return false;
|
|
} finally {
|
|
profiler.end();
|
|
}
|
|
|
|
if (handlers.isEmpty())
|
|
return false;
|
|
|
|
mc.displayGuiScreen(new GuiCraftingRecipe(prevscreen, handlers));
|
|
return true;
|
|
}
|
|
|
|
private GuiCraftingRecipe(GuiScreen prevgui, ArrayList<ICraftingHandler> handlers) {
|
|
super(prevgui);
|
|
currenthandlers = handlers;
|
|
}
|
|
|
|
public static void registerRecipeHandler(ICraftingHandler handler) {
|
|
for (ICraftingHandler handler1 : craftinghandlers)
|
|
if (handler1.getClass() == handler.getClass())
|
|
return;
|
|
|
|
craftinghandlers.add(handler);
|
|
}
|
|
|
|
public ArrayList<? extends IRecipeHandler> getCurrentRecipeHandlers() {
|
|
return currenthandlers;
|
|
}
|
|
|
|
public ArrayList<ICraftingHandler> currenthandlers;
|
|
|
|
public static ArrayList<ICraftingHandler> craftinghandlers = new ArrayList<>();
|
|
}
|