Skip to content

Introduction: Mod Strucutre

John Doe edited this page Mar 11, 2022 · 8 revisions

An introduction to the structure of this Forge mod

Configuration Files

build.gradle and src/main/recources/recources/mcmod.info are two files that need minor changes every now and then. Things like updating the mod version number for example, which also needs an update in me.mcforgesample.Main every now and then.

Packages and core Classes

In src/main/recources/java all the packages and java classes can be found and this is the folder that you will spend most of your time modifying.

Main Java Class

The main Java class is logically me.mcforgesample.Main. Here the initial functions executed on startup / initialisation of the mod are defined. The key part is what is in public void init(FMLInitializationEvent event). Here commands - using ClientCommandHandler.instance.registerCommand() - and event handlers - using MinecraftForge.EVENT_BUS.register() - are registered. It is also the center of this mod that provides references to important variables.

Events and Event Handlers

The core event handler is the me.mcforgesample.MinecraftEventHandler. This one subscibes to standard Forge events like ClientChatReceivedEvent, GuiScreenEvent.InitGuiEvent.Post, PlaySoundEvent. If these events fulfill special criteria, they are used to trigger custom events listed in me.mcforgesample.event using MinecraftForge.EVENT_BUS.post().

Custom event handlers in me.mcforgesample.eventhandler then subscribe to custom events. This then is where the action happens.

Commands

Commands are found in me.mcforgesample.command. One of those would be the TestCommand which when triggered responds with a simple text in chat.

Status

me.mcforgesample.status contains classes that are initialized in the main class at preInit() and serve as some sort of organized memory storage of game states. It's main purpose is to save information that is available only during a special event, but is needed a few minutes later.

Utils

me.mcforgesample.util contains all sorts of Java files that provide some kind of - more or less universal - functionality. Some also provide functionality used in more than one event like the HypixelEntityExtractor that extracts and summarizes the stacked armor stands Hypixel - among other servers - likes so much.

Wrapper

me.mcforgesample.wrapper is for wrapper classes. These are classes that take a complex Minecraft Forge object and provide easy access to it's attributes.