Jump to content

Help with modloader registered entities


biouxtai

Recommended Posts

I am working on a mod that when an op issues a command, I would like to get a list of all the entities that have been registered through modloader using the registerEntityId call.  Specifically, I am looking to get their classname and the string identifier that was passed to write out to a datafile.  I have been looking through the code and I am probably missing it, but I can't seem to find a function like getRegisiteredEntities that would return me a list.  I don't want to get the list out of the world as the entities that are available may not have all spawned.  I would like to be able to be mod agnostic in this so that *any* mod that registers a new entity will have it show up in this list.

 

I currently run a bukkit server with forge.  When I can my event handler and try to access the mobs names through the bukkit api they always come back as null.  I can get an unique id out of that api, but no other information.  As the modloader getUniqueId function will return different ids per server, this function is designed to map out the class names without having to resort to IDs to make config of my mod easier.

 

The ultimate goal is to get the list of names/classes so I can put them into a config file for my mod that will be used to make comparisons to entity events allowing for custom entities.

 

Thanks for any info.

 

~b

Link to comment
Share on other sites

hey OvermindDL1,

  Thanks for replying.  The Classname is exactly what I am looking for.  More specifically a usable classname.  I tried the reflection idea, but that didn't work so well to determine of the class was an instanceof EntityLiving.  I kept getting cannot convert from Class<? extends Entity> to EntityLiving.. really aggravating.  This is what I wound up doing.  It works, but probably not the cleanest.  What I was hoping for was a simple way of getting the living entities by the name they are registered with in ModLoader.

 

For example, Mo'Creatures (only mod I have that adds creatures right now) using call like this:

ModLoader.registerEntityID(MoCEntityHorse.class, "Horse", ModLoader.getUniqueEntityId());

 

I would live it if there was a function that allowed me to request the entities that are based off of EntityLiving like:

 

ModLoader.getRegisteredEntities(<baseClass>);

 

and it returns a list of strings that would be the second parameter to the register function of only the entities that are based off the class I pass in.

 

My code is below.  It works, but I am not happy with it and would like to improve it.

 

Iterator<Entry<String, Class<? extends Entity>>> iter = EntityTypes.getEntityToClassMapping().entrySet().iterator();

while (iter.hasNext()) {

Map.Entry<String, Class<? extends Entity>> mapEntry = iter.next();

eName = mapEntry.getKey();

try {

Class<?> c = mapEntry.getValue().getSuperclass();

boolean done = false;

eClass = "F";

while (!done) {

String en = c.getSimpleName();

if (en.equalsIgnoreCase("LivingEntity") ||en.equalsIgnoreCase("EntityLiving")){

eClass = "T";

done = true;

this.getLogger().info("Entity: " + eName);

} else if (en.equalsIgnoreCase("Entity") && !eName.equalsIgnoreCase("fakeBlock"))

done = true;

 

c = c.getSuperclass();

if (c.getCanonicalName().equalsIgnoreCase("java.lang.object"))

done = true;

}

} catch (Exception ex) {

this.getLogger().info("Exception! "+ex.getMessage());

}

}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.