Jump to content

Detect another mod's entity


Insane96MCP

Recommended Posts

I'm trying to fix a problem with my mod where it checks even some mod's entity that shouldn't.
How can I check if an entity is an instanceof another mod's entity (or any way to check if that mob is a mod's entity) without having to make it a dependence?
 

So far this is what I have

if (Loader.isModLoaded("babymobs")){
	//if (entity instanceof EntityZombieChicken) That would require the mod's import
	//or
	//if (entity.getId() == "babymobs:zombiechicken") That's pseudocode, not actually possible ... I think
}

 

Edited by Insane96MCP
Link to comment
Share on other sites

Your pseudocode is on the right track. To get the string id of the entity, you can pass it into EntityList.getEntityString(). You should also be using Object#equals() to check string equality, rather than ==. == checks identity, it returns true if the two objects are the same object, i.e they are located at the same memory address. Object#equals() returns true if the two objects can be considered equivalent, the definition of equivalence depends on the object. For a String, two Strings are equal if they have the same characters at the same positions.

Edited by Leviathan143
Remove doubled ==.
Link to comment
Share on other sites

If you are on the latest version, afaik it's better to check with EntityEntry registry. Use @ObjectHolder to get the entry and check if the class is the same with the class from the entry.

Edited by Abastro

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

On 24/9/2017 at 0:11 PM, Abastro said:

If you are on the latest version, afaik it's better to check with EntityEntry registry. Use @ObjectHolder to get the entry and check if the class is the same with the class from the entry.

And if I don't have access to source code? So I don't know the Entity class?

Link to comment
Share on other sites

2 hours ago, Insane96MCP said:

And if I don't have access to source code? So I don't know the Entity class?

Well. @ObjectHolder requires Entity ID, not class.

If you took a glance on EntityEntry, you must've found that it holds the class you need...

So check for entity with the class.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

On 9/24/2017 at 6:50 AM, Creeper_Guy2008 said:

What app are you using?

On 9/24/2017 at 6:53 AM, Creeper_Guy2008 said:

Ya kinda right

On 9/24/2017 at 6:54 AM, Creeper_Guy2008 said:

If you want to check if a mod is an entity either go in f3 mode and look at the mob and it should say if its an enitity

This is the Modder Support forum, please don't spam and don't suggest stuff you know nothing about.

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.

Announcements



×
×
  • Create New...

Important Information

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