Jump to content

Inner workings of forge


Melonslise

Recommended Posts

So becoming a more experienced coder I've some questions about how forge functions. I couldn't really find anything about this when browsing source (because I'm blind).

 

1. How are external modules in form of jars loaded? I'm presuming forge uses a custom class loader or reflection for this?

2. How are annotated classes and methods handled? I'm guessing reflection is used here?

3. How are external resources like textures, models and sounds loaded?

4. This one's more about Minecraft. How does the main loop look like and where is it?

 

Thanks.

Edited by Melonslise
Link to comment
Share on other sites

Just now, Melonslise said:

Thanks for the quick reply!

Your answer cleared most things up for me. However, I'd still like to see Minecraft's "asset-loading mechanisms".

 

The client uses an IResourceManager instance (Minecraft#mcResourceManager) to load resources from its list of IResourcePacks (this list is compiled in Minecraft#refreshResources).

 

The server uses various mechanisms:

  • AdvancementManager and CraftingManager use Class#getResource to find the vanilla advancements and recipes directories respectively and then uses Java 7's NIO.2 system to iterate and load them.
  • Forge's CraftingHelper.findFiles method (used to load mod advancements and recipes) also uses NIO.2 to iterate through the directories and load the files.
  • LootTableManager.Loader uses Guava's Files#toString to load loot tables from files on disk and Resources#toString to load loot tables from files in JARs.
  • TemplateManager uses FileInputStream to load structure templates from files on disk and Class#getResourceAsStream to load structure templates from files in JARs.

These might be unified with the addition of data packs in 1.13.

  • Like 2

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Thanks!

There are still a few things that interest me:

1. Due to my lack of java knowledge I don't quite understand how the mod Loader works. Can someone break it down to me?

2. Is there a way of doing the same thing as ASM does with annotations, but without external libraries?

Edited by Melonslise
Link to comment
Share on other sites

1 hour ago, diesieben07 said:
  1. If you do not have Java knowledge then sorry, you are not qualified to make mods or even begin to understand how Forge itself works. Forge uses quite a few techniques that require deep knowledge about Java and even the JVM itself to make modding work in Minecraft. This is not really something you want to tackle before getting at least the very basics of Java down.
  2. Loader is not a mod, it is a class. And a quite long and complex one at that. Which part are you confused about?

Are you writing your own plugin/mod/whatever loader? Or what are you trying to achieve? The answer depends on your exact requirements.

1. No, that's not quite what I meant. I'm okay with java. In fact, I've been using it for more than a year now.

2. I didn't mean Loader as a mod, I meant that it loads mods. What interests me is how forge "handles" mods (that would be how they're found, loaded and later accessed).

So I've looked at the FMLServerHandler and at Loader and I have some questions. First, in beginServerLoading I see that loadMods is called with an empty immutable list. Second, I can't find where the mods are found. I'm guessing that happens in identifyMods, but I only see mcp and minecraft being added as mods (why?). Third, what is the ModDiscoverer? Fourth, why are the mods sorted? And last, why is there no post init in the Loader?

 

Not quite. Apart from Minecraft I do other things with java. Minecraft and Forge are a great example to me and I've learned quite a bit from them. Understanding and making something similar would be quite beneficial to me.

Edited by Melonslise
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Is this a question? This is probably an artifact from an older version of FML.

 

MCP and Minecraft are built-in "mods" (they don't actually do anything). Mods are discovered by the ModDiscoverer, which is also invoked in identifyMods.

 

It searches the file system (mods folder) and classpath for mods.

 

If Mod A wants to interact with Mod B's blocks, it has to load after Mod B, because otherwise Mod B's blocks are not there yet (Mod B might not even be loaded yet).

 

There is. initializeMods transitions to the postinit state.

 

The problem is, they aren't. Many things (especially in Forge) are done backwards due to Minecraft not being designed for modding. If you make a new project from the ground up I suggest you do not follow what Forge and Minecraft are doing.

Thanks for the fast reply! I might have some more question later.

 

Well now that I think about it, I haven't learned much from forge, more from Minecraft. Can you provide examples of some "backwards things" from Forge/Minecraft?

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.