Cleaned up entity registration, added first loc text (#5).

The way entities were being registered was not friendly with other mods.
This method has the advantage of not only allowing us to localize the
entity names sanely, but also avoids potential ID conflicts with other
mods that may add fairies, etc.

This IS a breaking change, any existing fairies will unspawn.
This commit is contained in:
Ammon Lauritzen 2016-02-22 11:48:30 -06:00
parent 1afd38fef1
commit cacf3f1c6a
3 changed files with 23 additions and 2 deletions

View File

@ -77,6 +77,7 @@ public class FairyFactions {
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
fairySpawner = new Spawner();
// TODO: move these thresholds into config file
final int maxNum = 18;
final int freqNum = 8;
fairySpawner.setMaxAnimals(maxNum);

View File

@ -12,6 +12,7 @@ import fairies.entity.EntityFairy;
import fairies.entity.FairyEntityFishHook;
import fairies.event.FairyEventListener;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.Packet;
@ -36,8 +37,26 @@ public class CommonProxy {
}
public void initEntities() {
EntityRegistry.registerGlobalEntityID( EntityFairy.class, "Fairy", EntityRegistry.findGlobalUniqueEntityId(), 0xea8fde, 0x8658bf );
EntityRegistry.registerModEntity( FairyEntityFishHook.class, "FairyFishhook", EntityRegistry.findGlobalUniqueEntityId(), FairyFactions.INSTANCE, 64, 4, true );
int entityID = 0;
registerEntity( entityID++, EntityFairy.class, "Fairy", 0xea8fde, 0x8658bf );
registerEntity( entityID++, FairyEntityFishHook.class, "FairyFishhook" );
}
private void registerEntity( int entityID, Class<?extends Entity> entityClass, String entityName ) {
EntityRegistry.registerModEntity( entityClass, entityName, entityID, FairyFactions.INSTANCE, 64, 4, true);
}
private void registerEntity( int entityID, Class<?extends Entity> entityClass, String entityName, int backgroundEggColor, int foregroundEggColor ) {
registerEntity( entityID, entityClass, entityName );
// Thanks to the Metallurgy team for the clean implementation of this in Atum that I am adapting.
int i = 120;
do {
++i;
} while( EntityList.getStringFromID(i) != null );
final Integer eggID = Integer.valueOf(i);
EntityList.IDtoClassMapping.put(eggID, entityClass);
EntityList.entityEggs.put(eggID, new EntityList.EntityEggInfo(eggID, backgroundEggColor, foregroundEggColor));
}
public void initGUI() {

View File

@ -0,0 +1 @@
entity.FairyFactions.Fairy.name=Fairy