From 5acfc6ae3c5527865a4d92e86d2d50af7d6157b6 Mon Sep 17 00:00:00 2001 From: Silverminer007 <66484505+Silverminer007@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:22:00 +0200 Subject: [PATCH] [1.19] Fix data-gen output path of custom data-pack registries (#8724) --- .../WorldgenRegistryDumpReport.java.patch | 11 ++++++++ .../RegistryResourceAccess.java.patch | 8 +++--- .../net/minecraft/tags/TagManager.java.patch | 5 ++-- .../net/minecraftforge/common/ForgeHooks.java | 25 +++++++++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 patches/minecraft/net/minecraft/data/info/WorldgenRegistryDumpReport.java.patch diff --git a/patches/minecraft/net/minecraft/data/info/WorldgenRegistryDumpReport.java.patch b/patches/minecraft/net/minecraft/data/info/WorldgenRegistryDumpReport.java.patch new file mode 100644 index 0000000000..d6a88ff9f9 --- /dev/null +++ b/patches/minecraft/net/minecraft/data/info/WorldgenRegistryDumpReport.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/data/info/WorldgenRegistryDumpReport.java ++++ b/net/minecraft/data/info/WorldgenRegistryDumpReport.java +@@ -37,7 +_,7 @@ + private void m_236204_(CachedOutput p_236205_, RegistryAccess p_236206_, DynamicOps p_236207_, RegistryAccess.RegistryData p_236208_) { + ResourceKey> resourcekey = p_236208_.f_123101_(); + Registry registry = p_236206_.m_206191_(resourcekey); +- DataGenerator.PathProvider datagenerator$pathprovider = this.f_194676_.m_236036_(DataGenerator.Target.REPORTS, resourcekey.m_135782_().m_135815_()); ++ DataGenerator.PathProvider datagenerator$pathprovider = this.f_194676_.m_236036_(DataGenerator.Target.REPORTS, net.minecraftforge.common.ForgeHooks.prefixNamespace(resourcekey.m_135782_())); // FORGE: Custom data-pack registries are prefixed with their namespace + + for(Map.Entry, T> entry : registry.m_6579_()) { + m_236209_(datagenerator$pathprovider.m_236048_(entry.getKey().m_135782_()), p_236205_, p_236207_, p_236208_.f_123102_(), entry.getValue()); diff --git a/patches/minecraft/net/minecraft/resources/RegistryResourceAccess.java.patch b/patches/minecraft/net/minecraft/resources/RegistryResourceAccess.java.patch index a613167346..b88c6ecbf4 100644 --- a/patches/minecraft/net/minecraft/resources/RegistryResourceAccess.java.patch +++ b/patches/minecraft/net/minecraft/resources/RegistryResourceAccess.java.patch @@ -18,7 +18,7 @@ } catch (Throwable throwable1) { if (reader != null) { try { -@@ -107,12 +_,15 @@ +@@ -107,13 +_,14 @@ }); } @@ -30,8 +30,8 @@ } private static String m_214239_(ResourceLocation p_214240_) { -+ if (net.minecraftforge.registries.RegistryManager.FROZEN.getRegistry(p_214240_) != null && !(p_214240_.m_135827_().equals("minecraft"))) -+ return p_214240_.m_135827_() + "/" + p_214240_.m_135815_(); // FORGE: add non-vanilla registry namespace to loader directory, same format as tag directory (see net.minecraft.tags.TagManager#getTagDir(ResourceKey)) - return p_214240_.m_135815_(); +- return p_214240_.m_135815_(); ++ return net.minecraftforge.common.ForgeHooks.prefixNamespace(p_214240_); // FORGE: add non-vanilla registry namespace to loader directory, same format as tag directory (see net.minecraft.tags.TagManager#getTagDir(ResourceKey)) } + private static ResourceLocation m_214268_(ResourceKey p_214269_) { diff --git a/patches/minecraft/net/minecraft/tags/TagManager.java.patch b/patches/minecraft/net/minecraft/tags/TagManager.java.patch index 61d83ec267..1cf108c357 100644 --- a/patches/minecraft/net/minecraft/tags/TagManager.java.patch +++ b/patches/minecraft/net/minecraft/tags/TagManager.java.patch @@ -1,12 +1,11 @@ --- a/net/minecraft/tags/TagManager.java +++ b/net/minecraft/tags/TagManager.java -@@ -30,7 +_,8 @@ +@@ -30,7 +_,7 @@ public static String m_203918_(ResourceKey> p_203919_) { String s = f_203902_.get(p_203919_); - return s != null ? s : "tags/" + p_203919_.m_135782_().m_135815_(); -+ ResourceLocation registryName = p_203919_.m_135782_(); -+ return s != null ? s : "tags/" + (registryName.m_135827_().equals("minecraft") ? "" : registryName.m_135827_() + "/") + registryName.m_135815_(); ++ return s != null ? s : "tags/" + net.minecraftforge.common.ForgeHooks.prefixNamespace(p_203919_.m_135782_()); } public CompletableFuture m_5540_(PreparableReloadListener.PreparationBarrier p_13482_, ResourceManager p_13483_, ProfilerFiller p_13484_, ProfilerFiller p_13485_, Executor p_13486_, Executor p_13487_) { diff --git a/src/main/java/net/minecraftforge/common/ForgeHooks.java b/src/main/java/net/minecraftforge/common/ForgeHooks.java index 88a4f8d942..84ad5f35e1 100644 --- a/src/main/java/net/minecraftforge/common/ForgeHooks.java +++ b/src/main/java/net/minecraftforge/common/ForgeHooks.java @@ -1419,4 +1419,29 @@ public class ForgeHooks return map.buildOrThrow(); } + + /** + *

+ * This method is used to prefix the path, where elements of the associated registry are stored, with their namespace, if it is not minecraft + *

+ *

+ * This rules conflicts with equal paths out. If for example the mod {@code fancy_cheese} adds a registry named {@code cheeses}, + * but the mod {@code awesome_cheese} also adds a registry called {@code cheeses}, + * they are going to have the same path {@code cheeses}, just with different namespaces. + * If {@code additional_cheese} wants to add additional cheese to {@code awesome_cheese}, but not {@code fancy_cheese}, + * it can not differentiate both. Both paths will look like {@code data/additional_cheese/cheeses}. + *

+ *

+ * The fix, which is applied here prefixes the path of the registry with the namespace, + * so {@code fancy_cheese}'s registry stores its elements in {@code data//fancy_cheese/cheeses} + * and {@code awesome_cheese}'s registry stores its elements in {@code data/namespace/awesome_cheese/cheeses} + *

+ * + * @param registryKey key of the registry + * @return path of the registry key. Prefixed with the namespace if it is not "minecraft" + */ + public static String prefixNamespace(ResourceLocation registryKey) + { + return registryKey.getNamespace().equals("minecraft") ? registryKey.getPath() : registryKey.getNamespace() + "/" + registryKey.getPath(); + } }