Jump to content

Recommended Posts

Posted

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

Posted

Instead of using IDs, use the class name so you can grab a class object by reflection with it.  The IDs are mod specific, different mods can use the same Entity IDs, so would not be of much help.

Posted

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());

}

}

 

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Recovering stolen Bitcoin can feel like an insurmountable challenge, especially after falling victim to scams that promise high returns with little investment. My journey began with excitement when I first learned about Bitcoin mining pools. The idea of earning substantial profits from a modest investment was enticing. I was encouraged to invest $5,200, and soon found myself caught in a web of endless demands for more money to access my funds. As time went on, I paid out hundreds of thousands of dollars, believing that each payment would finally unlock my investments. However, the requests never ceased, and I soon realized I was trapped in a scam. The weight of losing $826,000 worth of Bitcoin was unbearable, and I felt utterly helpless. I reached out to authorities, but their responses were disheartening, leaving me feeling even more isolated in my struggle. In my desperation, I even went to pray, seeking guidance and hope in what felt like a hopeless situation. I poured my heart out, asking for a sign or a way to recover my lost funds. It was during this time of reflection that I began searching for solutions online, hoping to find a way to recover my investments. That’s when I stumbled upon RAPID DIGITAL RECOVERY. At first, I was cynical after all, I had already been deceived so many times. However, I decided to reach out and share my story. The team at RAPID DIGITAL RECOVERY was understanding and compassionate, assuring me they had the expertise to help me recover my stolen Bitcoin. Within hours of providing them with the necessary information, I began to see progress. They guided me through the recovery process, keeping me informed every step of the way. It was surreal to watch as they worked diligently to trace my funds and navigate the complexities of the blockchain. To my astonishment, I received confirmation that my Bitcoin had been successfully recovered. The relief and joy I felt were indescribable. I had almost given up hope, but RAPID DIGITAL RECOVERY proved to be the lifeline I desperately needed. If you find yourself in a similar situation, I urge you to seek help from Reputable team at RAPID DIGITAL RECOVERY.  
    • https://mclo.gs/9Byd16j Hi, I've had my BetterMC world for a couple days now (1.19.2 vers & Fabric loader) but recently whenever I try to open the profile the minecraft launcher crashes and provides this error code. I've checked both this forum and google and haven't found any similar problems or solution to my problem. I'm not the best at reading crash logs but I gathered that there's an issue with fabric possibly, so I re-downloaded the same one on the modpack, then the latest version for 1.19.2 fabric and the issue still occurred. What can I do now?
    • it works now but idk why lmao. i removed terrablender and it didnt work. i then left it for a couple of days and, when i came back, updated the mods that needed updating because "what's the worst that could happen". i then tried launching it and now it works. i genuenly have no clue what i did to make it work, othen than updating the mods. so, thanks for your help
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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