Thursday 26 December 2013

Forge concepts - some general notes

Forge is comprised of a couple of main components
  • FML – forge mod loader – which is mostly concerned with loading mods and initialising them, but also provides most of the Registries.
  • Minecraftforge – adds a large number of extra events and hooks
They were developed independently and are stored in different packages (cpw.mods.fml vs net.minecraftforge), but apart from that you’ll use them in the same way. The biggest symptom you might notice is that the paradigms are sometimes a bit inconsistent – naming conventions, hook methods, event handlers, commenting style – but nothing too hard to get used to.

Often it is difficult to know exactly which forge methods or hooks are going to be useful to create the behaviour you want.  A general strategy I have found effective is:
  1. Think of a part of the vanilla minecraft which does something similar to what you want to do.
  2. Open up that item, block, entity (or whatever) and browse through the vanilla code to see how it works.
  3. Look for ways to divert the program flow to your own code:
    * Methods that you can override in your own classes (especially for Blocks, Items, Entities)
    * A forge event or hook inserted into the vanilla code, which you can register for.
Sometimes, if there is no appropriate event or class method to override, it is possible to check for a condition using a tickhandler (called 20 times per second) and act on that – for example, checking if the player is holding a particular item in their hand and making sparks fly from their head if it is.



~Overview of Forge (and what it can do for you)
    Forge concepts
           Some general notes
           How Forge starts up your code (@Mod, @SidedProxy, etc)  
           Registering your classes
           Extra methods for vanilla base classes
           Events
     Forge summary - grouped by task
           Blocks
           Items
           TileEntities
           Entities
           World generation, loading, saving
           Miscellaneous - player input, rendering, GUI, chat, sounds

2 comments:

  1. I noticed that you have created separate areas for 1.8 topics and outdated 1.6/1.7 topics, however many of the 1.8 topics are actually the outdated ones and were posted prior to 1.8 (and Forge for 1.8) being released. One example on this page is that fml has now been integrated as net.minecraftforge.fml and is no longer a separate package. Do you have any plans for systematically updating your posts and/or flag what the major changes from 1.7 to 1.8 are?
    - Thanks, KRB

    ReplyDelete
  2. Hi Keith
    Hmmm yeah you're right, I did re-use many of the old topics and some of them have parts which are out of date, like the change where they merged cpw's fml into Forge.
    I revisit topics occasionally as something major changes, and hopefully I've picked up all the important ones. I plan to update again for 1.9 when that is released so that will be the next systematic check. If you notice any big discrepancies, please let me know?

    Cheers
    TGG

    ReplyDelete