mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Changed generic signature of GameRegistry.register methods to work around the type inference bug; updated all example mods to the new block/item registration method.
This commit is contained in:
1 parent
fc57d5e6c6
commit
77772ac3f5
12 files changed
+99
-44
No files matched your search
@@ -210,32 +210,38 @@ public class GameData
|
||||
{
|
||||
return (BiMap<Block,Item>)getMain().iItemRegistry.getSlaveMap(BLOCK_TO_ITEM, BiMap.class);
|
||||
}
|
||||
static <K extends IForgeRegistryEntry<K>> K register(K object, ResourceLocation location)
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static <K extends IForgeRegistryEntry<K>> K register_impl(Object object, ResourceLocation location)
|
||||
{
|
||||
if (object == null)
|
||||
{
|
||||
FMLLog.getLogger().log(Level.ERROR, "Attempt to register a null object");
|
||||
throw new NullPointerException("Attempt to register a null object");
|
||||
}
|
||||
object.setRegistryName(location);
|
||||
return register(object);
|
||||
((K)object).setRegistryName(location);
|
||||
// explicit type is needed for some reason
|
||||
return GameData.<K>register_impl(object);
|
||||
}
|
||||
|
||||
static <K extends IForgeRegistryEntry<K>> K register(K object)
|
||||
// argument is Object due to incorrect inferrence of the type if source level = 6, probably related to https://bugs.openjdk.java.net/browse/JDK-8026527
|
||||
@SuppressWarnings("unchecked")
|
||||
static <K extends IForgeRegistryEntry<K>> K register_impl(Object object)
|
||||
{
|
||||
K castedObj = (K)object;
|
||||
if (object == null)
|
||||
{
|
||||
FMLLog.getLogger().log(Level.ERROR, "Attempt to register a null object");
|
||||
throw new NullPointerException("Attempt to register a null object");
|
||||
}
|
||||
if (object.getRegistryName() == null)
|
||||
if (castedObj.getRegistryName() == null)
|
||||
{
|
||||
FMLLog.getLogger().log(Level.ERROR, "Attempt to register object without having set a registry name {} (type {})", object, object.getClass().getName());
|
||||
throw new IllegalArgumentException(String.format("No registry name set for object %s (%s)", object, object.getClass().getName()));
|
||||
}
|
||||
final IForgeRegistry<K> registry = PersistentRegistryManager.findRegistry(object);
|
||||
registry.register(object);
|
||||
return object;
|
||||
final IForgeRegistry<K> registry = PersistentRegistryManager.findRegistry(castedObj);
|
||||
registry.register(castedObj);
|
||||
return castedObj;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -140,9 +140,10 @@ public class GameRegistry
|
||||
* @throws IllegalArgumentException if the object is not yet named (use {@link #register(IForgeRegistryEntry, ResourceLocation)} instead)
|
||||
* @return The object
|
||||
*/
|
||||
public static <K extends IForgeRegistryEntry<K>> K register(K object)
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <K extends IForgeRegistryEntry<?>> K register(K object)
|
||||
{
|
||||
return GameData.register(object);
|
||||
return (K)GameData.register_impl(object);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,9 +160,10 @@ public class GameRegistry
|
||||
* @throws IllegalStateException if the object already has an existing name (use {@link #register(IForgeRegistryEntry)} instead)
|
||||
* @return The object
|
||||
*/
|
||||
public static <K extends IForgeRegistryEntry<K>> K register(K object, ResourceLocation name)
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <K extends IForgeRegistryEntry<?>> K register(K object, ResourceLocation name)
|
||||
{
|
||||
return GameData.register(object, name);
|
||||
return (K)GameData.register_impl(object, name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user