Jump to content

[1.6.4] How to override a super class method when you are calling said method


Recommended Posts

Posted

Hi all,

 

Couldnt fit what I wanted in the title so apologies about the vagueness.

 

My issue is im trying to make a version of zombies that dont burn in sunlight, so I have extended the EntityZombie Class and overriden the method that does the burning, however in this same method is a call to the super.method which is in EntityZombie and obviously DOES contain the burning code. Now i need the stuff further up the chain in the supers so but would like to basically bypass the EntityZombie method and go straight to EntityMob, am I missing something fundementally simple here or am i going to have create a whole new Entity for this?

Posted

By having a class that extends EntityZombie and calling that method, you eliminate the call to the super as well. Just call the EntityMob methods then within your method. Thats the best I can think of with what I got from your post.

Posted

Hi

 

I am told by experts that there is no way in Java to call super.super.method.

 

Which means that if you want to call EntityMob.method directly, you're out of luck.  You will either need to copy the code from EntityMob.method into your own Entity (which might not work if it accesses any private variables or methods), or derive from EntityMob instead.  (Copy the EntityZombie code into your own Entity).

 

-TGG

Posted

Duplicate the zombie.  Name it something else.  Done.

 

You have encountered the failing of the Object Inheritance Pattern.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Thats what I had done to begin with but it came with its own issues (nameley the forgeEventFactory for call zombie aid) I couldnt resolve the errors with that as it will only take EntityZombie not EntityCustomZombie.

Posted

Ok i kind of have it working, had to make copy:

 

EntityZombie

RenderEntityZombie

EntityZombieGroupData

EntityZombieINNER1

ZombieEvent

 

This gets me no fire in daylight, brilliant! however, all custom zombies are zombie villagers...*sigh*...nerd world problems....ill have a play for a bit see if i cant backtrace why this is happening and post a new thread if I get nowhere.

 

edit - nope i derped, all is well. I accidentally deleted an IF so it was setting villager to TRUE all the time.....

Posted

Yeah, you have to copy the render stuff too.  Like I said, failing of the Object Inheritance Model.

 

You might be interested in this topic.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hi

 

To be honest, I don't think it's a failing of the Object inheritance model, it's a feature.  OO is all about encapsulation and preventing you from having to know the details of how an object is written, and allowing you to make changes to objects without breaking all your existing code.  Inheritance is intended for the situation when your derived class can always be substituted for the base class(es), and it should not be possible to violate this by ignoring what the super class says.  The problem in the case of the Zombie is that the vanilla code has been designed with the two incompatible assumptions that all zombies burn in sunlight, and that only zombies can call to each other for aid.  That's not a failing of the inheritance model, that's a design decision.

 

I do agree that there's a tendency for folks to use inheritance when they should use something else such as interfaces or composition. 

 

-TGG

Posted
I do agree that there's a tendency for folks to use inheritance when they should use something else such as interfaces or composition.

 

Mob behavior should probably be the latter, not the former.

 

I was able to, however, implement some version of composition on top of the Item system.  My last count (which was an estimation anyway) was 67 million combinations allowable.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.