[Java] [Java] Let’s create a mod for Minecraft 1.16.1 [Basic file]

5 minute read

(This article is one of a series of commentary articles)

First article: Introduction
Previous article: Introduction
Next article:

Basic file

We will set the basic files. There are files that I copied and pasted in Last time, so I will change these for myself.

package name

Package Naming Convention #% E3% 83% 91% E3% 83% 83% E3% 82% B1% E3% 83% BC% E3% 82% B8% E5% 91% BD% E5% 90% 8D% E8% A6% 8F If you read% E7% B4% 84), you will be required to avoid conflicts by using your domain as a namespace. However, I don’t have a domain, so I did the following.

Change before


D:\projects\mc_liveinwater\src\main\java
   com
       example
           examplemod
               ExampleMod.java

After change


D:\projects\mc_liveinwater\src\main\java
   jp
      koteko
           liveinwater
               LiveInWater.java

assets folder, data folder

Create a ʻassets \ liveinwater folder to place files such as textures and sound effects, and a data \ liveinwater` folder to place files such as recipes and drop tables.

D:\projects\mc_liveinwater\src\main\resources
   ├ assets
   │  └ liveinwater
   ├ data
   │  └ liveinwater
   ├ META-INF
   │   └ mods.toml
   └ pack.mcmeta

pack.mcmeta
The pack.mcmeta file is a file that describes the details of the resource pack.
For details, refer to Wiki. Since 1.15, pack_format is 5. The comment line is unnecessary, so delete it.

After change


{
    "pack": {
        "description": "live in water Mod resources",
        "pack_format": 5
    }
}

mods.toml
The mods.toml file is a file that contains mod information.
In addition to information such as dependencies, the information displayed on the screen when the mod is installed is also included here, so change it if necessary.
It’s long, but the explanation of each item is only written in comments, so read it carefully and set it appropriately. mandatory is required and ʻoptional` is optional.

mods.toml


# This is an example mods.toml file. It contains the data relating to the loading mods.
# There are several mandatory fields (#mandatory), and many more that are optional (#optional).
# The overall format is standard TOML format, v0.5.0.
# Note that there are a couple of TOML lists in this file.
# Find more information on toml format here:  https://github.com/toml-lang/toml
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[32,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="MIT License"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="http://my.issue.tracker/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="liveinwater" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="${file.jarVersion}" #mandatory
 # A display name for the mod
displayName="live in water Mod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
#updateJSONURL="http://myurl.me/" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="http://example.com/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
#logoFile="examplemod.png " #optional
# A text field displayed in the mod UI
#credits="Thanks for this example mod goes to Java" #optional
# A text field displayed in the mod UI
#authors="Love, Cheese and small house plants" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
live in water
 – deep, silent, sea.
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.liveinwater]] #optional
    # the modid of the dependency
    modId="forge" #mandatory
    # Does this dependency have to exist - if not, ordering below must be specified
    mandatory=true #mandatory
    # The version range of the dependency
    versionRange="[32,)" #mandatory
    # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
    ordering="NONE"
    # Side this dependency is applied on - BOTH, CLIENT or SERVER
    side="BOTH"
# Here's another dependency
[[dependencies.liveinwater]]
    modId="minecraft"
    mandatory=true
    versionRange="[1.16.1]"
    ordering="NONE"
    side="BOTH"

Regarding license, if you think about distribution in the future, you should carefully read the reference page etc. in the comment and set it properly. (I’m not familiar with it, so I set it as the MIT License.)
Other non-essential items are commented out as appropriate.

Main file

LiveInWater.java (originally ʻExampleMod.java`) is the main class of the mod. Erase things that are obviously not used and make them cleaner.

LiveInWater.java


package jp.koteko.liveinwater;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod("liveinwater")
public class LiveInWater
{
    private static final Logger LOGGER = LogManager.getLogger();

    public LiveInWater() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        LOGGER.info("SETUP START");

        LOGGER.info("SETUP END");
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client
    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
    }

    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        LOGGER.info("server starting");
    }
}

Make sure the filename (LiveInWater.java) matches the class name (public class LiveInWater) and the constructor (public LiveInWater ()). Also, make sure that the modId specification (@Mod ("liveinwater ")) is the same as the one in mods.toml edited above.
The image of what this class is doing is to put four life cycles on a rail and insert that rail onto the Forge. I’m not familiar with these treatments yet, so I’ll leave four for the time being.
Also, I think there was a code to register the block at the end, but I deleted it on this file because it would be cleaner to prepare a separate class.

Start confirmation

Finally, make sure that the game starts just in case. Once started, open mods and verify that the information has been updated.
キャプチャ.PNG
VERSION is NONE, but since it is given when actually constructing the mod jar file, it is NONE here.

reference

Structuring Your Mod - Forge Documentation
[Java] Let’s create a mod for Minecraft 1.14.4 [0. Basic file]
Minecraft 1.14.4 Forge Mod Creation Part 2 [Basic File Arrangement]

Next article