Jump to content

ForgeSubscribe and Overriding Vanilla Systems


Morgrhim

Recommended Posts

So I'm familiar with Java, but not so much the Forge API. I've gotten my environment set up, and I'm working on some code for a mod I have in mind. Part of the mod involves adding quite a few NBT tags to the player. To figure out how this works, I'm using the tutorial at https://github.com/coolAlias/Forge_Tutorials/blob/master/IExtendedEntityPropertiesTutorial.java. My questions are these:

 

1. When I try to use @ForgeSubscribe on line 192, I get an error "ForgeSubscribe cannot be resolved to a type". Do I need to replace this with SubscribeEvent?

 

2. I want to overhaul the health and armor system with my own algorithms. I've specified tags and have the algorithms worked out. If I add health and maxhealth to the NBT tags will it override the vanilla health system?

 

3. I'm understanding how to implement these tags for players. Is it the same for mobs? I need to be able to edit mobs as well and going through the Forge javadocs I'm not seeing how I would override mobs.

 

Link to comment
Share on other sites

First of all, for changing vanilla behavior you should look for these things in the following order

 

1. Public fields and methods.  Many vanilla classes have public fields and methods that you can directly access.  For example if you look at EntityLiving, the living sound time and the AI list are public fields, and there are public getter methods for the look helper, move helper, jump helper, navigator, setting the attack target and so on.  Use Eclipse to check the "type hierarchy" of the class to see all the fields and methods available to you.

 

2. Registries and dictionaries.  You can find out a lot about what blocks, items, entities, recipes, ores, etc. are available and possibly modify them.

 

3. Events.  Forge has tried to provide hooks for many common, useful places to intercept the vanilla processing.  for example, you can change what an entity drops when it dies, you can change how pretty much everything renders, etc.

 

4. Java Reflection.  Java is a funny language but you can get access to private and protected fields and methods with reflection.  It is a lot easier than it sounds.

 

5. Replacing vanilla stuff with your own custom copy.  You can intercept spawns, placements, registrations and use your own custom class instead.  If your custom class extends the vanilla class it is replacing, then other code should generally consider it like the vanilla class (e.g. instanceof tests would pass).

 

6. Access transformers (ASM). I don't know much about this, but you can basically change how the vanilla code executes.

 

Anyway, don't just jump into using events. First of all check for public methods. 

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

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.

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.