diff --git a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java index fcee74edf..ded977335 100644 --- a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java +++ b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java @@ -44,6 +44,8 @@ import javax.annotation.Nonnull; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.CraftingFactoriesRegisterEvent; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -589,7 +591,11 @@ private static void loadFactory(JsonObject json, JsonContext context, Factor { for (Entry entry : JsonUtils.getJsonObject(json, loader.name).entrySet()) { - ResourceLocation key = new ResourceLocation(context.getModId(), entry.getKey()); + ResourceLocation key; + if (entry.getKey().contains(":")){ + key = new ResourceLocation(entry.getKey()); + }else key = new ResourceLocation(context.getModId(), entry.getKey()); + String clsName = JsonUtils.getString(entry.getValue(), loader.name + "[" + entry.getValue() + "]"); loader.consumer.accept(key, getClassInstance(clsName, loader.type)); } @@ -630,6 +636,7 @@ else if (revertFrozen) //ModContainer old = Loader.instance().activeModContainer(); Loader.instance().setActiveModContainer(null); Loader.instance().getActiveModList().forEach(CraftingHelper::loadFactories); + MinecraftForge.EVENT_BUS.post(new CraftingFactoriesRegisterEvent(conditions, ingredients, recipes)); Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes); Loader.instance().setActiveModContainer(null); diff --git a/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java b/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java new file mode 100644 index 000000000..77df56bcb --- /dev/null +++ b/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java @@ -0,0 +1,38 @@ +package net.minecraftforge.event; + +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.crafting.IConditionFactory; +import net.minecraftforge.common.crafting.IIngredientFactory; +import net.minecraftforge.common.crafting.IRecipeFactory; +import net.minecraftforge.fml.common.eventhandler.Event; + +import java.util.Map; + +public class CraftingFactoriesRegisterEvent extends Event { + public CraftingFactoriesRegisterEvent(Map m1, Map m2, Map m3){ + conditions=m1; + ingredients=m2; + recipes=m3; + } + private final Map conditions; + private final Map ingredients; + private final Map recipes; + public void register(ResourceLocation name, IConditionFactory fac) { + conditions.put(name, fac); + } + public IConditionFactory unregisterC(ResourceLocation name) { + return conditions.remove(name); + } + public void register(ResourceLocation name, IRecipeFactory fac) { + recipes.put(name, fac); + } + public IRecipeFactory unregisterR(ResourceLocation name) { + return recipes.remove(name); + } + public void register(ResourceLocation name, IIngredientFactory fac) { + ingredients.put(name, fac); + } + public IIngredientFactory unregisterI(ResourceLocation name) { + return ingredients.remove(name); + } +}