Base mod files and some resource files | mcmod.dev

Tutorials CustomQuests Generator (1.x.x) CustomQuests Wiki (2.x.x)

Creating a package

Navigate to the 'src/main/java' folder, and delete the package(s) inside (com.example.examplemod). Now create a new package: 'com.vincentmet.randomlycreative'. Withing that package create a new class. I prefer to name that class 'BaseClass', but others might name it by their mod name, 'Main' or something else.

Creating the base mod class and the Reference class

Before we continue with the main mod class, we're first gonna to create the 'Ref' class where we will put most of our static variables for easy access. For now I'm putting the modid, the mod name and the version in there. (they're all final since they won't be changed code-wise)


        

Continuing the new 'BaseClass' you just created, above the class declaration, put next the Annotation:

@Mod(Ref.MODID)

This annotation is there so forge knows this is you main mod class, and will load your constructor of this class. (and also associate you your modid with the mod.)

Create the constructor for this class, and then register an event listener to the mod event bus inside (which we have yet to create).

FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);

Now create a method with the event you want to subscribe to as first parameter:


        

Inside this method you will register most stuff that isn't handled by other event handlers.

Creating and registering an EventHandler class

Start by creating the class, and annotating it, and supplying it your modid and a bus to listen to:

@Mod.EventBusSubscriber(modid = Ref.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)

We will filling this class with listeners in later tutorials.

Return to the constructor of your main mod file, and register the EventHandler you just created with:

MinecraftForge.EVENT_BUS.register(EventHandler.class);

There are multiple ways you can register event handlers that have different access modifiers, I won't be using these others, but here is a simple flowchart of which to use when:

Updating the resource: pack.mcmeta

Navigate to the 'src/main/resources' folder, and open the 'pack.mcmeta' file. When you open it, you'll find you some json. Change the description to whatever you want, ill name it 'randomlycreative resources'. Keep the 'pack_format' at '4', since that has to do with with Mojang's naming conventions which they usually change every big update. The most noticeable change here is the localization files changing from 'en_US.lang' to 'en_us.json' for example. As for the '_comment', you can remove that full line (don't forget to remove the comma on the previous line since it's still a json file).

The file looks like this now:


        

Updating the resource: META-INF/mods.toml

Open the 'mods.toml' file inside the 'META-INF' folder. This file contains a lot of the static properties of your minecraft mod. These should all speak for themselves, so I won't go in depth here. For most all of my mods, I remove all the commands, and all the optional dependencies on the bottom. And after changing the variables to our mod's values, the file looks something like this:


        

Setting up resources file structure

The next image shows how you should lay out your folders inside the resources root directory. Later tutorials will explain what is what, and what goes where.