Insane96MCP Posted September 23, 2017 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
Leviathan143 Posted September 23, 2017 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
Insane96MCP Posted September 24, 2017 Author 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
Insane96MCP Posted September 24, 2017 Author Posted September 24, 2017 On 9/24/2017 at 6:50 AM, Creeper_Guy2008 said: What app are you using? Expand Please don't go off-topic in other peoples' posts. Quote
Creeper_Guy2008 Posted September 24, 2017 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
Abastro Posted September 24, 2017 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.
Insane96MCP Posted September 29, 2017 Author Posted September 29, 2017 On 9/24/2017 at 10:11 AM, 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. Expand And if I don't have access to source code? So I don't know the Entity class? Quote
Abastro Posted September 29, 2017 Posted September 29, 2017 On 9/29/2017 at 9:43 AM, Insane96MCP said: And if I don't have access to source code? So I don't know the Entity class? Expand 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.
MrBendelScrolls Posted September 29, 2017 Posted September 29, 2017 On 9/24/2017 at 6:50 AM, Creeper_Guy2008 said: What app are you using? Expand On 9/24/2017 at 6:53 AM, Creeper_Guy2008 said: Ya kinda right Expand 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 Expand This is the Modder Support forum, please don't spam and don't suggest stuff you know nothing about. Quote
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.