mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Added new get/setRegistryName functions to Item and Block.
And helper functions in GameRegistry to allow for registering using those names automatically. This is to simplify registration and get rid of the horrible hacks users are doing now with 'unlocalised names'.
This commit is contained in:
1 parent
fb54ea94c0
commit
1a31ff9f06
5 files changed
+182
-52
No files matched your search
@@ -117,36 +117,12 @@ public class GameData
|
||||
|
||||
int registerItem(Item item, String name) // from GameRegistry
|
||||
{
|
||||
int index = name.indexOf(':');
|
||||
if (index != -1)
|
||||
{
|
||||
FMLLog.bigWarning("Dangerous extra prefix %s for name %s, invalid registry invocation/invalid name?", name.substring(0, index), name);
|
||||
}
|
||||
|
||||
ResourceLocation rl = addPrefix(name);
|
||||
return registerItem(item, rl, -1);
|
||||
}
|
||||
|
||||
private int registerItem(Item item, ResourceLocation name, int idHint)
|
||||
{
|
||||
return iItemRegistry.add(idHint, name, item);
|
||||
return iItemRegistry.add(-1, addPrefix(name), item);
|
||||
}
|
||||
|
||||
int registerBlock(Block block, String name) // from GameRegistry
|
||||
{
|
||||
int index = name.indexOf(':');
|
||||
if (index != -1)
|
||||
{
|
||||
FMLLog.bigWarning("Dangerous alternative prefix %s for name %s, invalid registry invocation/invalid name?", name.substring(0, index), name);
|
||||
}
|
||||
|
||||
ResourceLocation rl = addPrefix(name);
|
||||
return registerBlock(block, rl, -1);
|
||||
}
|
||||
|
||||
private int registerBlock(Block block, ResourceLocation name, int idHint)
|
||||
{
|
||||
return iBlockRegistry.add(idHint, name, block);
|
||||
return iBlockRegistry.add(-1, addPrefix(name), block);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,12 +141,13 @@ public class GameData
|
||||
{
|
||||
int index = name.lastIndexOf(':');
|
||||
String oldPrefix = index == -1 ? "" : name.substring(0, index);
|
||||
name = index == -1 ? name : name.substring(index + 1);
|
||||
String prefix;
|
||||
ModContainer mc = Loader.instance().activeModContainer();
|
||||
|
||||
if (mc != null)
|
||||
{
|
||||
prefix = mc.getModId();
|
||||
prefix = mc.getModId().toLowerCase();
|
||||
}
|
||||
else // no mod container, assume minecraft
|
||||
{
|
||||
@@ -179,6 +156,7 @@ public class GameData
|
||||
|
||||
if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
|
||||
{
|
||||
FMLLog.bigWarning("Dangerous alternative prefix %s for name %s, invalid registry invocation/invalid name?", prefix, name);
|
||||
prefix = oldPrefix;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,15 +127,29 @@ public class GameRegistry
|
||||
sortedGeneratorList = ImmutableList.copyOf(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an item with the item registry with a the name specified in Item.getRegistryName()
|
||||
*
|
||||
* @param item The item to register
|
||||
*/
|
||||
public static void registerItem(Item item)
|
||||
{
|
||||
registerItem(item, item.getRegistryName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an item with the item registry with a custom name : this allows for easier server->client resolution
|
||||
*
|
||||
* @param item The item to register
|
||||
* @param name The mod-unique name of the item
|
||||
*/
|
||||
public static void registerItem(net.minecraft.item.Item item, String name)
|
||||
public static void registerItem(Item item, String name)
|
||||
{
|
||||
registerItem(item, name, null);
|
||||
if (Strings.isNullOrEmpty(name))
|
||||
{
|
||||
throw new IllegalArgumentException("Attempted to register a block with no name: " + item);
|
||||
}
|
||||
GameData.getMain().registerItem(item, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,13 +159,13 @@ public class GameRegistry
|
||||
* @param name The mod-unique name to register it as - null will remove a custom name
|
||||
* @param modId deprecated, unused
|
||||
*/
|
||||
@Deprecated // See version without modID remove in 1.9
|
||||
public static Item registerItem(Item item, String name, String modId)
|
||||
{
|
||||
GameData.getMain().registerItem(item, name);
|
||||
registerItem(item, name);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a forced persistent substitution alias for the block or item to another block or item. This will have
|
||||
* the effect of using the substituted block or item instead of the original, where ever it is
|
||||
@@ -168,6 +182,16 @@ public class GameRegistry
|
||||
GameData.getMain().registerSubstitutionAlias(nameToSubstitute, type, object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a block with the name that Block.getRegistryName returns.
|
||||
*
|
||||
* @param block The block to register
|
||||
*/
|
||||
public static Block registerBlock(Block block)
|
||||
{
|
||||
return registerBlock(block, block.getRegistryName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a block with the specified mod specific name
|
||||
*
|
||||
@@ -179,6 +203,17 @@ public class GameRegistry
|
||||
return registerBlock(block, ItemBlock.class, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a block with the world, with the specified item class using Block.getRegistryName's name
|
||||
*
|
||||
* @param block The block to register
|
||||
* @param itemclass The item type to register with it : null registers a block without associated item.
|
||||
*/
|
||||
public static Block registerBlock(Block block, Class<? extends ItemBlock> itemclass)
|
||||
{
|
||||
return registerBlock(block, itemclass, block.getRegistryName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a block with the world, with the specified item class and block name
|
||||
*
|
||||
@@ -191,6 +226,19 @@ public class GameRegistry
|
||||
return registerBlock(block, itemclass, name, new Object[] {});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register a block with the world, with the specified item class using Block.getRegistryName's name
|
||||
*
|
||||
* @param block The block to register
|
||||
* @param itemclass The item type to register with it : null registers a block without associated item.
|
||||
* @param itemCtorArgs Arguments to pass (after the required {@code Block} parameter) to the ItemBlock constructor (optional).
|
||||
*/
|
||||
public static Block registerBlock(Block block, Class<? extends ItemBlock> itemclass, Object... itemCtorArgs)
|
||||
{
|
||||
return registerBlock(block, itemclass, block.getRegistryName(), itemCtorArgs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a block with the world, with the specified item class, block name and owning modId
|
||||
*
|
||||
@@ -201,6 +249,10 @@ public class GameRegistry
|
||||
*/
|
||||
public static Block registerBlock(Block block, Class<? extends ItemBlock> itemclass, String name, Object... itemCtorArgs)
|
||||
{
|
||||
if (Strings.isNullOrEmpty(name))
|
||||
{
|
||||
throw new IllegalArgumentException("Attempted to register a block with no name: " + block);
|
||||
}
|
||||
if (Loader.instance().isInState(LoaderState.CONSTRUCTING))
|
||||
{
|
||||
FMLLog.warning("The mod %s is attempting to register a block whilst it it being constructed. This is bad modding practice - please use a proper mod lifecycle event.", Loader.instance().activeModContainer());
|
||||
|
||||
Reference in new issue
Block a user