Jump to content

[SOLVED][1.7.2] Question about use(fulness) of IAnimal interface


Recommended Posts

The IAnimal interface is kind of wierdly used.  Or maybe more likely it is weirdly named by MCP.


Normally an interface is used to define the common public methods for a set of classes.  It can also be used as a "grouping" mechanism for classes that aren't otherwise in common inheritance -- in other words you can use instanceof to check for implementation of an interface.


It seems that IAnimal is empty (no methods) so is used simply for grouping (I'll get to that in a sec).  A true "IAnimal" would be expected to define those methods actually used by EntityAnimal, like for mating.  However it doesn't so is really just a grouping interface.


Now EntityAnimal does in fact implement IAnimal.  However, IMob extends IAnimal so that means that all EntityMob subclasses are also instanceof IAnimal, as are boss entities.  And EntityAmbientCreature also implements IAnimal.


So that is fine, but this is so broad that it doesn't have that much in common, and it doesn't enforce an actual animal-like interface -- i.e. Zombies implement IAnimal (through extension by IMob) but don't mate like EntityAnimal does.


As far as I can tell, the only real use of IAnimal is in EntityTracker where it checks for instanceof IAnimal and considers it something that should be tracked.


So it seems that IAnimal was really misnamed.  It should just be called ITrackable or similar.  It has nothing to do specifically with "animals" except for fact that EntityAnimal is one of many classes that implement it.


Any thoughts?  Do others agree?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

What you say is another of the many unfortunate name snafus in the codebase. It is likely to stay that way, so get used to it.

Link to comment
Share on other sites

Well, the people doing the naming are working hard so I won't be too critical.  And I can see why whoever was figuring out the deobfuscation might have thought IAnimal was a suitable name if the first entity they saw extend it was EntityAnimal.  The rest of the entities mostly inherit it from IMob so not as clear that the interface was implemented by classes beyond EntityAnimal.  So if you were working on MCP and trying to figure out what the interface did it would be easy to start with assumption that it was related to animals.


But yeah this is second questionable naming I've found.  One I mentioned before is flat-out wrong -- the isClientWorld() method in EntityLivingBase has the logic backwards (it returns true if on server world).


Similarly, block method names related to "solid", "collidable", "normalCube", "opaque" and stuff are all probably slightly misnamed because everyone assumes they have to do with pathfinding or colliding with blocks when instead they can be related to other more nuanced meaning.


Anyway, I'm definitely getting more cautious about using any field or method without inspecting the implementation carefully.  I was surprised by some modders who don't use decomp workspace and instead use dev workspace (without source attached).  Seems a little risky to trust the methods functionality based on their deobfuscated names...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Yeah. I don't mean to point and yell at people. But that is still the moral of the story... Name things appropriately. I, for one, use the decomp workspace too.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

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.

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.