More cleanups, some documentation, a bunch of deprecations.

This commit is contained in:
cpw 2015-11-24 16:47:46 -05:00
parent c5a980f8a4
commit 85d7b69d19
2 changed files with 105 additions and 45 deletions

View file

@ -235,6 +235,15 @@ public class EntityRegistry
return instance().entityEggsUn;
}
/**
* Registers in the minecraft Entity ID list. This is generally not a good idea and shouldn't be used.
* Simply use {@link #registerModEntity(Class, String, int, Object, int, int, boolean, int, int)} instead.
*
* @param entityClass Class of the entity being registered
* @param entityName Name for the entity being registered
* @param id A globally unique ID for the entity
*/
@Deprecated
public static void registerGlobalEntityID(Class <? extends Entity > entityClass, String entityName, int id)
{
if (EntityList.classToStringMapping.containsKey(entityClass))
@ -256,6 +265,37 @@ public class EntityRegistry
EntityList.addMapping(entityClass, entityName, id);
}
/**
* Registers in the minecraft Entity ID list. This is generally not a good idea, and shouldn't be used.
* Simply use {@link #registerModEntity(Class, String, int, Object, int, int, boolean)} instead.
* @param entityClass The class of the entity being registered
* @param entityName The name of the entity being registered
* @param id The globally unique ID of the entity
* @param backgroundEggColour An RGB colour value for the spawn egg background colour
* @param foregroundEggColour An RGB colour value for the spawn egg foreground colour
*/
@Deprecated
public static void registerGlobalEntityID(Class <? extends Entity > entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour)
{
if (EntityList.classToStringMapping.containsKey(entityClass))
{
ModContainer activeModContainer = Loader.instance().activeModContainer();
String modId = "unknown";
if (activeModContainer != null)
{
modId = activeModContainer.getModId();
}
else
{
FMLLog.severe("There is a rogue mod failing to register entities from outside the context of mod loading. This is incredibly dangerous and should be stopped.");
}
FMLLog.warning("The mod %s tried to register the entity class %s which was already registered - if you wish to override default naming for FML mod entities, register it here first", modId, entityClass);
return;
}
instance().validateAndClaimId(id);
EntityList.addMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
}
private int validateAndClaimId(int id)
{
// workaround for broken ML
@ -287,32 +327,19 @@ public class EntityRegistry
return realId;
}
public static void registerGlobalEntityID(Class <? extends Entity > entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour)
{
if (EntityList.classToStringMapping.containsKey(entityClass))
{
ModContainer activeModContainer = Loader.instance().activeModContainer();
String modId = "unknown";
if (activeModContainer != null)
{
modId = activeModContainer.getModId();
}
else
{
FMLLog.severe("There is a rogue mod failing to register entities from outside the context of mod loading. This is incredibly dangerous and should be stopped.");
}
FMLLog.warning("The mod %s tried to register the entity class %s which was already registered - if you wish to override default naming for FML mod entities, register it here first", modId, entityClass);
return;
}
instance().validateAndClaimId(id);
EntityList.addMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour);
}
/**
* Add a spawn entry for the supplied entity in the supplied {@link BiomeGenBase} list
* @param entityClass Entity class added
* @param weightedProb Probability
* @param min Min spawn count
* @param max Max spawn count
* @param typeOfCreature Type of spawn
* @param biomes List of biomes
*/
public static void addSpawn(Class <? extends EntityLiving > entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
{
for (BiomeGenBase biome : biomes)
{
@SuppressWarnings("unchecked")
List<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature);
for (SpawnListEntry entry : spawns)
@ -331,22 +358,35 @@ public class EntityRegistry
}
}
@SuppressWarnings("unchecked")
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes)
/**
* Add a spawn entry for the supplied entity in the supplied {@link BiomeGenBase} list
* @param entityName The entity name
* @param weightedProb Probability
* @param min Min spawn count
* @param max Max spawn count
* @param typeOfCreature type of spawn
* @param biomes List of biomes
*/
public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
{
Class <? extends Entity > entityClazz = (Class<? extends Entity>) EntityList.stringToClassMapping.get(entityName);
Class <? extends Entity > entityClazz = EntityList.stringToClassMapping.get(entityName);
if (EntityLiving.class.isAssignableFrom(entityClazz))
{
addSpawn((Class <? extends EntityLiving >) entityClazz, weightedProb, min, max, spawnList, biomes);
addSpawn((Class <? extends EntityLiving >) entityClazz, weightedProb, min, max, typeOfCreature, biomes);
}
}
/**
* Remove the spawn entry for the supplied entity
* @param entityClass The entity class
* @param typeOfCreature type of spawn
* @param biomes Biomes to remove from
*/
public static void removeSpawn(Class <? extends EntityLiving > entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
{
for (BiomeGenBase biome : biomes)
{
@SuppressWarnings("unchecked")
Iterator<SpawnListEntry> spawns = biome.getSpawnableList(typeOfCreature).iterator();
while (spawns.hasNext())
@ -360,17 +400,29 @@ public class EntityRegistry
}
}
@SuppressWarnings("unchecked")
public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes)
/**
* Remove the spawn entry for the supplied entity
* @param entityName Name of entity being removed
* @param typeOfCreature type of spawn
* @param biomes Biomes to remove from
*/
public static void removeSpawn(String entityName, EnumCreatureType typeOfCreature, BiomeGenBase... biomes)
{
Class <? extends Entity > entityClazz = (Class<? extends Entity>) EntityList.stringToClassMapping.get(entityName);
Class <? extends Entity > entityClazz = EntityList.stringToClassMapping.get(entityName);
if (EntityLiving.class.isAssignableFrom(entityClazz))
{
removeSpawn((Class <? extends EntityLiving>) entityClazz, spawnList, biomes);
removeSpawn((Class <? extends EntityLiving>) entityClazz, typeOfCreature, biomes);
}
}
/**
* Utility function to try and obtain a globally unique entity ID. Not useful as it requires syncing between
* client and server. Use {@link #registerModEntity(Class, String, int, Object, int, int, boolean)} instead,
* for a much better experience.
* @return A theoretically globally unique ID
*/
@Deprecated
public static int findGlobalUniqueEntityId()
{
int res = instance().availableIndicies.nextSetBit(0);

View file

@ -88,11 +88,11 @@ public class GameRegistry
* Callback hook for world gen - if your mod wishes to add extra mod related generation to the world
* call this
*
* @param chunkX
* @param chunkZ
* @param world
* @param chunkGenerator
* @param chunkProvider
* @param chunkX Chunk X coordinate
* @param chunkZ Chunk Z coordinate
* @param world World we're generating into
* @param chunkGenerator The chunk generator
* @param chunkProvider The chunk provider
*/
public static void generateWorld(int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
@ -142,7 +142,6 @@ public class GameRegistry
* @param item The item to register
* @param name The mod-unique name to register it as - null will remove a custom name
* @param modId deprecated, unused
* where one mod should "own" all the blocks of all the mods, null defaults to the active mod
*/
public static Item registerItem(Item item, String name, String modId)
{
@ -329,6 +328,10 @@ public class GameRegistry
return GameData.findItem(modId, name);
}
/**
* Will be switching to using ResourceLocation, since it's used widely elsewhere
*/
@Deprecated
public static final class UniqueIdentifier
{
public final String modId;
@ -387,7 +390,7 @@ public class GameRegistry
}
}
public static enum Type {
public enum Type {
BLOCK
{
@Override
@ -407,8 +410,6 @@ public class GameRegistry
}
/**
* Look up the mod identifier data for a block.
* Returns null if there is no mod specified mod identifier data, or it is part of a
* custom itemstack definition {@link #registerCustomItemStack}
*
* Note: uniqueness and persistence is only guaranteed by mods using the game registry
* correctly.
@ -416,14 +417,13 @@ public class GameRegistry
* @param block to lookup
* @return a {@link UniqueIdentifier} for the block or null
*/
@Deprecated
public static UniqueIdentifier findUniqueIdentifierFor(Block block)
{
return GameData.getUniqueName(block);
}
/**
* Look up the mod identifier data for an item.
* Returns null if there is no mod specified mod identifier data, or it is part of a
* custom itemstack definition {@link #registerCustomItemStack}
*
* Note: uniqueness and persistence is only guaranteed by mods using the game registry
* correctly.
@ -431,6 +431,7 @@ public class GameRegistry
* @param item to lookup
* @return a {@link UniqueIdentifier} for the item or null
*/
@Deprecated
public static UniqueIdentifier findUniqueIdentifierFor(Item item)
{
return GameData.getUniqueName(item);
@ -439,9 +440,8 @@ public class GameRegistry
/**
* This will cause runtime injection of public static final fields to occur at various points
* where mod blocks and items <em>could</em> be subject to change. This allows for dynamic
* substitution to occur.
* ObjectHolder can be used to automatically populate public static final fields with entries
* from the registry. These values can then be referred within mod code directly.
*
*/
@Retention(RetentionPolicy.RUNTIME)
@ -457,6 +457,14 @@ public class GameRegistry
String value();
}
/**
* ItemStackHolder can be used to automatically populate public static final fields with
* {@link ItemStack} instances, referring a specific item, potentially configured with NBT.
* These values can then be used in things like recipes and other places where ItemStacks
* might be required.
*
* If the item is not found, the field will be populated with null.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ItemStackHolder