mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
1 parent
22f7f4649b
commit
6e0e67b14d
2 files changed
+27
-30
No files matched your search
@@ -42,7 +42,7 @@ public abstract class ForgeRegistryEntry<V extends IForgeRegistryEntry<V>> imple
|
||||
if (getRegistryName() != null)
|
||||
throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());
|
||||
|
||||
this.registryName = GameData.checkPrefix(name, true);
|
||||
this.registryName = checkRegistryName(name);
|
||||
return (V)this;
|
||||
}
|
||||
|
||||
@@ -59,4 +59,28 @@ public abstract class ForgeRegistryEntry<V extends IForgeRegistryEntry<V>> imple
|
||||
}
|
||||
|
||||
public final Class<V> getRegistryType() { return (Class<V>)token.getRawType(); }
|
||||
|
||||
/**
|
||||
* This will assert that the registry name is valid and warn about potential registry overrides
|
||||
* It is important as it detects cases where modders unintentionally register objects with the "minecraft" namespace, leading to dangerous errors later.
|
||||
* @param name The registry name
|
||||
* @return A verified "correct" registry name
|
||||
*/
|
||||
ResourceLocation checkRegistryName(String name)
|
||||
{
|
||||
return GameData.checkPrefix(name, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This class exists for registry entries which are dynamic (e.g. loaded via data packs), and also exist in a forge registry prior to that.
|
||||
* Due to this, the registry name will be set via the codec not during initial registration, and as a result, we want to not warn about possible overrides as the registry name will be set outside of mod context.
|
||||
*/
|
||||
public abstract static class UncheckedRegistryEntry<V extends IForgeRegistryEntry<V>> extends ForgeRegistryEntry<V>
|
||||
{
|
||||
@Override
|
||||
ResourceLocation checkRegistryName(String name)
|
||||
{
|
||||
return new ResourceLocation(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user