Insane96MCP Posted September 23, 2017 Share Posted September 23, 2017 (edited) 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 September 23, 2017 by Insane96MCP Quote Link to comment Share on other sites More sharing options...
Leviathan143 Posted September 23, 2017 Share Posted September 23, 2017 (edited) 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 September 23, 2017 by Leviathan143 Remove doubled ==. Quote Link to comment Share on other sites More sharing options...
Insane96MCP Posted September 24, 2017 Author Share Posted September 24, 2017 Is it better use EntityList#getEntityString() or EntityList#getKey().toString()? if (EntityList.getKey(entity).toString().equals("babymobs:zombiechicken")) //or if (EntityList.getEntityString(entity).equals("zombiechicken") Quote Link to comment Share on other sites More sharing options...
Creeper_Guy2008 Posted September 24, 2017 Share Posted September 24, 2017 What app are you using? Quote Link to comment Share on other sites More sharing options...
Insane96MCP Posted September 24, 2017 Author Share Posted September 24, 2017 1 minute ago, Creeper_Guy2008 said: What app are you using? Please don't go off-topic in other peoples' posts. Quote Link to comment Share on other sites More sharing options...
Creeper_Guy2008 Posted September 24, 2017 Share Posted September 24, 2017 Ya kinda right Quote Link to comment Share on other sites More sharing options...
Creeper_Guy2008 Posted September 24, 2017 Share Posted September 24, 2017 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 Quote Link to comment Share on other sites More sharing options...
Abastro Posted September 24, 2017 Share Posted September 24, 2017 (edited) 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 September 24, 2017 by Abastro Quote 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 More sharing options...
Insane96MCP Posted September 29, 2017 Author Share Posted September 29, 2017 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? Quote Link to comment Share on other sites More sharing options...
Abastro Posted September 29, 2017 Share Posted September 29, 2017 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. Quote 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 More sharing options...
MrBendelScrolls Posted September 29, 2017 Share Posted September 29, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.