From 71a520e8a99e8780d153b0ace59d2d056a694130 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:02:36 +0800 Subject: [PATCH 1/3] fix MinecraftForge#5092 and enable coding register --- .../common/crafting/CraftingHelper.java | 10 ++++- .../event/CraftingFactoriesRegisterEvent.java | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java diff --git a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java index fcee74edf..cd544bf22 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)); } @@ -633,6 +639,8 @@ else if (revertFrozen) Loader.instance().getActiveModList().forEach(CraftingHelper::loadRecipes); Loader.instance().setActiveModContainer(null); + MinecraftForge.EVENT_BUS.post(new CraftingFactoriesRegisterEvent(conditions, ingredients, recipes)); + GameData.fireRegistryEvents(rl -> rl.equals(GameData.RECIPES)); //reg.freeze(); 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..964c64b36 --- /dev/null +++ b/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java @@ -0,0 +1,43 @@ +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; + +/** + * @Project Cleanroom + * @Author Hileb + * @Date 2024/2/24 15:54 + **/ +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); + } +} From eed9f3e5ad0de9303928d29d3971099c79a60829 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:29:07 +0800 Subject: [PATCH 2/3] Update CraftingFactoriesRegisterEvent.java, Fix the error auto-head I forget to delete. --- .../minecraftforge/event/CraftingFactoriesRegisterEvent.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java b/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java index 964c64b36..77df56bcb 100644 --- a/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java +++ b/src/main/java/net/minecraftforge/event/CraftingFactoriesRegisterEvent.java @@ -8,11 +8,6 @@ import java.util.Map; -/** - * @Project Cleanroom - * @Author Hileb - * @Date 2024/2/24 15:54 - **/ public class CraftingFactoriesRegisterEvent extends Event { public CraftingFactoriesRegisterEvent(Map m1, Map m2, Map m3){ conditions=m1; From 3cac1ad288658397fcf7f7ac9dba83dd6de3c9c2 Mon Sep 17 00:00:00 2001 From: Hileb <107909747+Ecdcaeb@users.noreply.github.com> Date: Sat, 24 Feb 2024 16:30:44 +0800 Subject: [PATCH 3/3] Update CraftingHelper.java --- .../net/minecraftforge/common/crafting/CraftingHelper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java index cd544bf22..ded977335 100644 --- a/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java +++ b/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java @@ -636,11 +636,10 @@ 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); - MinecraftForge.EVENT_BUS.post(new CraftingFactoriesRegisterEvent(conditions, ingredients, recipes)); - GameData.fireRegistryEvents(rl -> rl.equals(GameData.RECIPES)); //reg.freeze();