[1.18.x] Allow Modders to add custom data-pack registries through RegistryBuilder (#8630)

Co-authored-by: Silverminer007 <[email protected]>
Co-authored-by: Curle <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-06-05 15:27:30 +01:00
1 parent 15bd5f0d30
commit 997d8e0aa2
21 files changed
+525 -10

No files matched your search

@@ -22,6 +22,7 @@ import com.google.common.collect.Sets.SetView;
import com.mojang.serialization.Lifecycle;
import net.minecraft.core.WritableRegistry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
@@ -161,10 +162,20 @@ public class RegistryManager
return getRegistry(name);
}
@SuppressWarnings("unchecked")
static <V extends IForgeRegistryEntry<V>> void registerToRootRegistry(ForgeRegistry<V> forgeReg)
{
WritableRegistry<Registry<V>> registry = (WritableRegistry<Registry<V>>) Registry.REGISTRY;
injectForgeRegistry(forgeReg, Registry.REGISTRY);
}
static <V extends IForgeRegistryEntry<V>> void registerToBuiltinRegistry(ForgeRegistry<V> forgeReg)
{
injectForgeRegistry(forgeReg, BuiltinRegistries.REGISTRY);
}
@SuppressWarnings("unchecked")
private static <V extends IForgeRegistryEntry<V>> void injectForgeRegistry(ForgeRegistry<V> forgeReg, Registry<? extends Registry<?>> rootRegistry)
{
WritableRegistry<Registry<V>> registry = (WritableRegistry<Registry<V>>) rootRegistry;
Registry<V> wrapper = forgeReg.getWrapper();
if (wrapper != null)
registry.register(forgeReg.getRegistryKey(), wrapper, Lifecycle.experimental());