Jump to content

Recommended Posts

Posted

Hello there. I have been spending my time looking into ways to modify the behavior of vanilla mobs.

 

I did not want to create a new mob by extending the vanilla mob. Google has pointed me towards Forge hooks, however I cannot find up to date information to help guide me.

 

I want to modify the onLivingUpdate() and some of the code for the chicken itself. I wanted to be able to feed the chicken my custom seeds. Once that chicken eats the seeds I wanted it to have one chance to drop my custom egg instead of a normal egg.

 

I am unsure how to approach this.

Posted

Generally, if you want to change vanilla behavior I look for the following possibilities (in this order).

 

a) Look for public methods in the vanilla classes.  For example, the AI of entities is in a public list that can be changed.  For EntityChicken the time between eggs is a public field so you could change that, etc.  Basically you can use your IDE (Eclipse) to suggest all available methods if you write the name of a class or class instance and then put the dot "." and wait a second -- a popup window will show all available methods.  As a modder it is very useful to frequently browse through these -- they can even give you ideas for new mods.

b) Look for Forge events that relate to what you want to do.  The Forge programmers know the types of things that modders commonly want to do, and so they "fire" events at the points in the vanilla code that are likely useful.  The events pass additional information to aid processing that particular event.  For more on event handling you can check out my tutorial: http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html.  In this case, as diesieben07 suggests above there is an event that might be useful for your chicken mod need.

c) Use Java reflection.  This is easier than it sounds and allows inspection of fields and methods in other classes that were originally meant to have limited scope.  In other words you can see private or protected stuff.  This is a peculiarity of Java that allows this, and while it isn't really good programming practice generally it is a very important modding tool.

d) Use ASM access transformers.  I honestly haven't done a lot with this, but basically seems to be a framework to affect code that otherwise isn't within scope.  I'm sure there are tutorials.

 

Another approach that can be useful is to replace the vanilla items, blocks, or entities with your own custom ones that extend the original classes.  There are events for most places where these are created, placed or spawned and in worst case you can use tick events to poll for existence of things you want to replace.  This method can cause some side effects, if other vanilla code or other mods are expecting the vanilla classes and use something other than instanceof to test them or cast them.

 

Anyway, just some ideas on techniques worth learning as a modder.

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

Posted

Thanks!

 

@diesieben07:

I've been working with this for a bit, this is absolutely the most awesome thing I have seen since working on a server for an MMO.

 

I wonder, why not use multicasting delegates in place of hard coding callbacks into specific classes?

 

@jabelar:

I did look into some of these methods before comping back. My ASM is weak so I didn't want to play it too much. Part of my googling did point me to replacing  vanilla mobs and passives with my own but along with the tutorial it was made clear that should anyone ever hook into the vanilla mobs and I decided to block their spawning, their mod would not work.

 

Some of the practices that are using to mod are pretty straight forward, I just kinda took a bad step and did not make sure I got myself some reliable documentation first, haha. It seems there aren't a lot of tutorials that deal with 1.7.X so thoroughly as 1.6.X. xD

 

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.