[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]

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

First article: Introduction Previous article: Introduction Next article: 1. Add Items

Basic file

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 **.

GroupId and ArtifactId

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

assets folder

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. キャプチャ.PNG

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. キャプチャ.PNG

Main file

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.

reference

Minecraft 1.14.4 Forge Mod Creation Part 2 [Basic File Arrangement]

Next article

1. Add items

Recommended Posts

[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]
[Java] Let's create a mod for Minecraft 1.16.1 [Basic file]
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
[Java] Let's create a mod for Minecraft 1.14.4 [4. Add tools]
[Java] Let's create a mod for Minecraft 1.14.4 [5. Add armor]
[Java] Let's create a mod for Minecraft 1.14.4 [Extra edition]
[Java] Let's create a mod for Minecraft 1.14.4 [7. Add progress]
[Java] Let's create a mod for Minecraft 1.14.4 [6. Add recipe]
[Java] Let's create a mod for Minecraft 1.16.1 [Add item]
[Java] Let's create a mod for Minecraft 1.14.4 [1. Add items]
[Java] Let's create a mod for Minecraft 1.14.4 [2. Add block]
[Java] Let's create a mod for Minecraft 1.16.1 [Add block]
[Java] Let's create a mod for Minecraft 1.14.4 [3. Add creative tab]
[Java] Let's create a mod for Minecraft 1.16.1 [Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [9. Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [8. Add and generate ore]
[Java] Create a temporary file
Let's create a Java development environment (updating)
Let's create a timed process with Java Timer! !!
Let's create a super-simple web framework in Java
[Java] Create a filter
Let's create a versatile file storage (?) Operation library by abstracting file storage / acquisition in Java
[Beginner] Create a competitive game with basic Java knowledge
[Java basics] Let's make a triangle with a for statement
[Java] Basic statement for beginners
Create a java method [Memo] [java11]
How to create a lightweight container image for Java apps
[Java twig] Create a parser combinator for recursive descent parsing 2
Create a MOB using the Minecraft Java Mythicmobs plugin | Preparation 1
Let's create a file upload system using Azure Computer Vision API and Azure Storage Java SDK
Let's create a TODO application in Java 4 Implementation of posting function
Upload a file using Java HttpURLConnection
How to sign a Minecraft MOD
Let's create a TODO application in Java 6 Implementation of search function
Let's create a TODO application in Java 8 Implementation of editing function
Run a batch file from Java
Create a Java project using Eclipse
[Java] How to create a folder
Let's create a TODO application in Java 1 Brief explanation of MVC
Let's create a TODO application in Java 5 Switch the display of TODO
Create a fluentd server for testing
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
To create a Zip file while grouping database search results in Java
[Java] Create a jar file with both compressed and uncompressed with the jar command
[Java twig] Create a parser combinator for recursive descent parsing (also memoize)
Let's go with Watson Assistant (formerly Conversation) ⑤ Create a chatbot with Watson + Java + Slack
Create a java web application development environment with docker for mac part2
[Java] Create and apply a slide master
Create a jar file with the command
How to create a Maven repository for 2020
Why does Java call a file a class?
Create a TODO app in Java 7 Create Header
[Rails] Let's create a super simple Rails API
[Java] Let's make a DB access library!
Let's make a calculator application with Java ~ Create a display area in the window
[Note] Java: Create a simple project while learning how the configuration file works.
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
I made a Diff tool for Java files
Let's write Java file input / output with NIO