mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 10:34:49 +00:00
[1.18.2] Fix tags for custom forge registries. (#8495)
Tag-enabled registries must now be registered to vanilla's root registry. See RegistryBuilder#hasTags. Modded tag-enabled registries have to use the format `data/<namespace>/tags/<registrynamespace>/<registryname>/<tag>.json` This format is to prevent conflicts for registries with the same path but different namespaces EX: Registry name `examplemod:shoe`, tag name `blue_shoes` would be `data/<namespace>/tags/examplemod/shoe/blue_shoes.json` RegistryEvent.NewRegistry has been moved and renamed to NewRegistryEvent. RegistryBuilder#create has been made private. See NewRegistryEvent#create Created new ITagManager system for looking up Forge tags. See IForgeRegistry#tags. Add lookup methods for Holders from forge registries. See IForgeRegistry#getHolder.
This commit is contained in:
1 parent
30f3a7dbba
commit
ad75cb8644
51 files changed
+1621
-531
No files matched your search
@@ -5,6 +5,8 @@
|
||||
|
||||
package net.minecraftforge.registries;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -24,6 +26,10 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
@Nullable
|
||||
private T value;
|
||||
|
||||
/**
|
||||
* @deprecated The uniqueness of registry super types will not be guaranteed starting in 1.19. Use {@link #of(ResourceLocation, ResourceLocation, String)}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, Supplier<Class<? super T>> registryType) {
|
||||
return new RegistryObject<>(name, registryType);
|
||||
}
|
||||
@@ -32,10 +38,38 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
return new RegistryObject<>(name, registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated The uniqueness of registry super types will not be guaranteed starting in 1.19. Use {@link #of(ResourceLocation, ResourceLocation, String)}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, final Class<T> baseType, String modid) {
|
||||
return new RegistryObject<>(name, baseType, modid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory for a {@link RegistryObject} that stores the value of an object in a registry once it is ready.
|
||||
*
|
||||
* @param name The name of the object to look up in a forge registry
|
||||
* @param key The key of the forge registry to grab from {@link RegistryManager#ACTIVE}
|
||||
* @param modid The mod id calling context
|
||||
* @return A {@link RegistryObject} that stores the value of an object in a registry once it is ready
|
||||
*/
|
||||
public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, final ResourceKey<? extends Registry<T>> key, String modid) {
|
||||
return new RegistryObject<>(name, key.location(), modid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory for a {@link RegistryObject} that stores the value of an object in a registry once it is ready.
|
||||
*
|
||||
* @param name The name of the object to look up in a forge registry
|
||||
* @param registryName The name of the forge registry to grab from {@link RegistryManager#ACTIVE}
|
||||
* @param modid The mod id calling context
|
||||
* @return A {@link RegistryObject} that stores the value of an object in a registry once it is ready
|
||||
*/
|
||||
public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, final ResourceLocation registryName, String modid) {
|
||||
return new RegistryObject<>(name, registryName, modid);
|
||||
}
|
||||
|
||||
private static RegistryObject<?> EMPTY = new RegistryObject<>();
|
||||
|
||||
private static <T extends IForgeRegistryEntry<? super T>> RegistryObject<T> empty() {
|
||||
@@ -48,6 +82,7 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
this.name = null;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
private <V extends IForgeRegistryEntry<V>> RegistryObject(ResourceLocation name, Supplier<Class<? super V>> registryType)
|
||||
{
|
||||
this(name, RegistryManager.ACTIVE.<V>getRegistry(registryType.get()));
|
||||
@@ -68,6 +103,7 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
private <V extends IForgeRegistryEntry<V>> RegistryObject(final ResourceLocation name, final Class<V> baseType, final String modid)
|
||||
{
|
||||
this.name = name;
|
||||
@@ -83,7 +119,7 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
{
|
||||
this.registry = RegistryManager.ACTIVE.getRegistry(baseType);
|
||||
if (registry == null)
|
||||
throw new IllegalStateException("Unable to find registry for type " + baseType.getName() + " for mod \"" + modid + "\". Check the 'caused by' to see futher stack.", callerStack);
|
||||
throw new IllegalStateException("Unable to find registry for type " + baseType.getName() + " for mod \"" + modid + "\". Check the 'caused by' to see further stack.", callerStack);
|
||||
}
|
||||
if (pred.test(registry.getRegistryName()))
|
||||
RegistryObject.this.updateReference((IForgeRegistry<? extends T>) registry);
|
||||
@@ -97,6 +133,36 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <V extends IForgeRegistryEntry<V>> RegistryObject(final ResourceLocation name, final ResourceLocation registryName, final String modid)
|
||||
{
|
||||
this.name = name;
|
||||
final Throwable callerStack = new Throwable("Calling Site from mod: " + modid);
|
||||
ObjectHolderRegistry.addHandler(new Consumer<>()
|
||||
{
|
||||
private IForgeRegistry<V> registry;
|
||||
|
||||
@Override
|
||||
public void accept(Predicate<ResourceLocation> pred)
|
||||
{
|
||||
if (registry == null)
|
||||
{
|
||||
this.registry = RegistryManager.ACTIVE.getRegistry(registryName);
|
||||
if (registry == null)
|
||||
throw new IllegalStateException("Unable to find registry with key " + registryName + " for mod \"" + modid + "\". Check the 'caused by' to see further stack.", callerStack);
|
||||
}
|
||||
if (pred.test(registry.getRegistryName()))
|
||||
RegistryObject.this.updateReference((IForgeRegistry<? extends T>) registry);
|
||||
}
|
||||
});
|
||||
IForgeRegistry<V> registry = RegistryManager.ACTIVE.getRegistry(registryName);
|
||||
// allow registry to be null, this might be for a custom registry that does not exist yet
|
||||
if (registry != null)
|
||||
{
|
||||
this.updateReference(((IForgeRegistry<? extends T>) registry));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly retrieves the wrapped Registry Object. This value will automatically be updated when the backing registry is updated.
|
||||
* Will throw NPE if the value is null, use isPresent to check first. Or use any of the other guarded functions.
|
||||
|
||||
Reference in new issue
Block a user