From 55fb26865a7c77a098b2be067afcf29c335df48c Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 13 Jan 2019 22:32:06 +0800 Subject: Guess this works --- .../java/me/shedaniel/rei/client/RecipeHelper.java | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/client/RecipeHelper.java') diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java index 70dad4c7c..d23d3d69d 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelper.java @@ -4,9 +4,11 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.IRecipeCategory; +import me.shedaniel.rei.api.IRecipeCategoryCraftable; import me.shedaniel.rei.api.IRecipeDisplay; import me.shedaniel.rei.api.IRecipePlugin; import me.shedaniel.rei.listeners.RecipeSync; +import net.minecraft.client.gui.Gui; import net.minecraft.item.ItemStack; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; @@ -19,10 +21,12 @@ public class RecipeHelper implements RecipeSync { private static Map> recipeCategoryListMap; private static List categories; private static RecipeManager recipeManager; + private static Map craftables; public RecipeHelper() { this.recipeCategoryListMap = Maps.newHashMap(); this.categories = Lists.newArrayList(); + this.craftables = Maps.newHashMap(); } public static List findCraftableByItems(List inventoryItems) { @@ -113,20 +117,39 @@ public class RecipeHelper implements RecipeSync { return recipeCategoryListMap; } + public static List getCategories() { + return categories; + } + + public static void registerCategoryCraftable(Class guiClass, IRecipeCategoryCraftable categoryCraftable) { + craftables.put(guiClass, categoryCraftable); + } + + public static void registerCategoryCraftable(Class[] guiClasses, IRecipeCategoryCraftable categoryCraftable) { + for(Class guiClass : guiClasses) craftables.put(guiClass, categoryCraftable); + } + + public static IRecipeCategoryCraftable getCategoryCraftable(IRecipeDisplay gui) { + if (!craftables.containsKey(gui.getClass())) + return null; + return craftables.get(gui.getClass()); + } + @Override public void recipesLoaded(RecipeManager recipeManager) { this.recipeManager = recipeManager; this.recipeCategoryListMap.clear(); this.categories.clear(); + this.craftables.clear(); RoughlyEnoughItemsCore.getListeners(IRecipePlugin.class).forEach(plugin -> { plugin.registerPluginCategories(); plugin.registerRecipes(); + plugin.registerAutoCraftingGui(); }); Collections.reverse(categories); - RoughlyEnoughItemsCore.LOGGER.info("Registered REI Categories: " + String.join(", ", categories.stream().map(category -> {return category.getCategoryName();}).collect(Collectors.toList()))); + RoughlyEnoughItemsCore.LOGGER.info("Registered REI Categories: " + String.join(", ", categories.stream().map(category -> { + return category.getCategoryName(); + }).collect(Collectors.toList()))); } - public static List getCategories() { - return categories; - } } -- cgit