(This article is one of a series of commentary articles)
First article: Introduction Previous article: Introduction Next article: 1. Add Items
The development environment is ready, and we are finally on the starting line. Let's get ready for you to proceed with your modding. I think that this area ** should be imitated without thinking deeply now **.
First, set the GroupId and ArtifactId. This is not like Minecraft, it seems to be a request from Java, but I am not familiar with it, so I will omit it.
There is a general way to decide how to name a package.
--GroupId: The name of the organization. Generally, the domain is written in reverse --ArtifactId: The name of the project
So I did the following.
item | value |
---|---|
GroupId | jp.koteko |
ArtifactId | example_mod |
Please change it to suit you. Rename the folder based on this.
Change before
D:\projects\mc_example_mod\src\main\java
└ com
└ example
└ examplemod
└ ExampleMod.java
After change
D:\projects\mc_example_mod\src\main\java
└ jp
└ koteko
└ example_mod
└ ExampleMod.java
Next, create a ʻassets \ example_mod` folder where you can place files such as textures and sound effects.
D:\projects\mc_example_mod\src\main\resources
├ assets
│ └ example_mod
├ META-INF
│ └ mods.toml
└ pack.mcmeta
pack.mcmeta So what are the files already in place? Let's look at each one.
pack.mcmeta
{
"pack": {
"description": "examplemod resources",
"pack_format": 4,
"_comment": "A pack_format of 4 requires json lang files. Note: we require v4 pack meta for all mods."
}
}
The pack.mcmeta
file is a file that describes the details of the resource pack.
See Wiki for details. Feel free to change the description
and delete the _comment
line as it is not needed.
After change
{
"pack": {
"description": "Example Mod resources",
"pack_format": 4
}
}
mods.toml
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="[28,)" #mandatory (28 is current forge version)
# 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="examplemod" #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="Example 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='''
This is a long form description of the mod. You can write whatever you want here
Have some lorem ipsum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.examplemod]] #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="[28,)" #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.examplemod]]
modId="minecraft"
mandatory=true
versionRange="[1.14.4]"
ordering="NONE"
side="BOTH"
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 the comment, so let's delete it (make it available for reference when needed). mandatory
is required and ʻoptional` is optional. The following is an example of editing appropriately.
After change
modLoader="javafml"
loaderVersion="[28,)"
[[mods]]
modId="example_mod"
version="${file.jarVersion}"
displayName="Example Mod"
logoFile="logo.png "
description='''
here
Explanation
input
'''
[[dependencies.example_mod]]
modId="forge"
mandatory=true
versionRange="[28,)"
ordering="NONE"
side="BOTH"
[[dependencies.example_mod]]
modId="minecraft"
mandatory=true
versionRange="[1.14.4]"
ordering="NONE"
side="BOTH"
Also, logo.png
is placed directly under resources
as the mod logo image.
D:\projects\mc_example_mod\src\main\resources
├ assets
│ └ example_mod
├ META-INF
│ └ mods.toml
├ logo.png
└ pack.mcmeta
As a result, the screen display has changed as follows.
ExampleMod.java
package jp.koteko.example_mod;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
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;
import java.util.stream.Collectors;
// The value here should match an entry in the META-INF/mods.toml file
@Mod("example_mod")
public class ExampleMod
{
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public ExampleMod() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event)
{
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}
private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
}
private void enqueueIMC(final InterModEnqueueEvent event)
{
// some example code to dispatch IMC to another mod
InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
}
private void processIMC(final InterModProcessEvent event)
{
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m->m.getMessageSupplier().get()).
collect(Collectors.toList()));
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
// do something when the server starts
LOGGER.info("HELLO from server starting");
}
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
@SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// register a new block here
LOGGER.info("HELLO from Register Block");
}
}
}
This is the main mod file. First of all, you can use it as it is, and if you understand it to some extent, you can rewrite it as needed.
The point to note here is that the file name (ʻExampleMod.java) matches the class name (
public class ExampleMod) and the constructor (
public ExampleMod () ), and the modId specification (
Is @Mod ("examplemod") ) the same as specified in
mods.toml`? If not, let's fix it.
Minecraft 1.14.4 Forge Mod Creation Part 2 [Basic File Arrangement]