--Build a Minecraft Mod development environment in IntelliJ IDEA and create a simple Hello World Mod
Java 11 or later is not supported in this development environment, so Java 8 must be installed in advance.
Reference: Install Java 8 \ (OpenJDK: AdoptOpenJDK ) on macOS with Homebrew -Qiita
Download Mdk (Mod Development Kit) of Minecraft Forge 1.15.2-31.1.0 which is the recommended environment at the moment (as of February 16, 2020) from Minecraft Forge To do.
Extract the downloaded forge-1.15.2-31.1.0-mdk.zip.
$ unzip forge-1.15.2-31.1.0-mdk.zip
Archive: forge-1.15.2-31.1.0-mdk.zip
inflating: gradlew
inflating: gradlew.bat
inflating: CREDITS.txt
inflating: LICENSE.txt
inflating: changelog.txt
creating: gradle/
creating: gradle/wrapper/
inflating: gradle/wrapper/gradle-wrapper.properties
inflating: gradle/wrapper/gradle-wrapper.jar
inflating: .gitignore
creating: src/
creating: src/main/
creating: src/main/java/
creating: src/main/java/com/
creating: src/main/java/com/example/
creating: src/main/java/com/example/examplemod/
inflating: src/main/java/com/example/examplemod/ExampleMod.java
creating: src/main/resources/
inflating: src/main/resources/pack.mcmeta
creating: src/main/resources/META-INF/
inflating: src/main/resources/META-INF/mods.toml
inflating: build.gradle
inflating: README.txt
inflating: gradle.properties
The setup method is described in README.txt.
If you prefer to use IntelliJ:
- Open IDEA, and import project.
- Select your build.gradle file and have it import.
- Run the following command: "gradlew genIntellijRuns" (./gradlew genIntellijRuns if you are on Mac/Linux)
- Refresh the Gradle Project in IDEA if required.
Reference: MinecraftForge / mdk at 1 \ .15 \ .x · MinecraftForge / MinecraftForge · GitHub
Create a project by specifying the folder extracted by Import Project in IntelliJ IDEA.
If the following message is output, the appropriate Java version has not been set.
> Failed to apply plugin [id 'net.minecraftforge.gradle']
> Found java version null. Minimum required is 1.8.0_101. Versions 11.0.0 and newer are not supported yet.
IntelliJ Settings Preferences> Build, Execution, Deployment> Build Tools> Gradle> Gradle JVM requires Java 8 or later to be specified.
./gradlew genIntellijRuns
Run ./gradlew genIntellijRuns in IntelliJ IDEA Terminal etc.
$ ./gradlew genIntellijRuns
Since Java 8 or later is used here as well, set it as necessary. Reference: Install Java 8 \ (OpenJDK: AdoptOpenJDK ) on macOS with Homebrew -Qiita
Run Tasks> fg_runs> runClient from the Gradle Tool Window in the upper right corner of IntelliJ IDEA, or run ./gradlew runClient from Terminal etc. to start Minecraft.
If you click "Mods", you can see that the Example Mod included in Mdk is loaded.
The source code of Example Mod is included in Mdk as a sample of mod development.
Source code list.
You can also check the contents of the source code at MinecraftForge / mdk at 1 \ .15 \ .x · MinecraftForge / MinecraftForge · GitHub Possible.
Create a mod that realizes a simple Hello World on the built development environment.
src/main/java/com/example/HelloWorldMod.java
Write a Java class that executes the main processing of the mod.
package com.example;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod("helloworldmod") // META-INF/mods.modId described in toml
public class HelloWorldMod {
public HelloWorldMod() {
// MinecraftForge.EVENT_Object with handler method for events to be processed by BUS(this)Register
MinecraftForge.EVENT_BUS.register(this);
}
/**
*An event handler method that runs when the player logs in.
*The method name can be anything.
*
* @param event PlayerLoggedInEvent object
*/
@SubscribeEvent
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
PlayerEntity player = event.getPlayer();
BlockPos pos = player.getPosition();
String message =
"Hello, World!\n"
+ "[name]=[" + player.getName().getFormattedText() + "]\n"
+ "[pos]=[" + pos.getX() + "," + pos.getY() + "," + pos.getZ() + "]";
ITextComponent text = new StringTextComponent(message);
player.sendMessage(text);
}
}
src/main/resources/pack.mcmeta
File for describing resource pack information. Without this file, an error such as "failed to load a valid ResourcePackInfo" will occur. Only the minimum contents are described here.
{
"pack": {
"description": "Hello World mod resources",
"pack_format": 5
}
}
src/main/resources/META-INF/mods.toml
Mod information description file. Only the minimum contents are described here.
modLoader="javafml"
loaderVersion="[31,)"
[[mods]]
modId="helloworldmod"
version="1.2.3"
displayName="Hello World Mod"
description='''
This is the ...
Hello World mod.
'''
build.gradle
Build configuration file for Gradle. Only the minimum contents are described here.
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
}
}
apply plugin: 'net.minecraftforge.gradle'
version = '1.2.3'
group = 'com.example.helloworld'
archivesBaseName = 'helloworldmod'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
minecraft {
mappings channel: 'snapshot', version: '20190719-1.14.3'
runs {
client {
workingDirectory project.file('run')
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'
mods {
helloworldmod {
source sourceSets.main
}
}
}
}
}
dependencies {
minecraft 'net.minecraftforge:forge:1.15.2-31.1.0'
}
Run Tasks> build> build from the Gradle Tool Window in the upper right corner of IntelliJ IDEA, or run ./gradlew build from Terminal etc.
$ ./gradlew build
The jar file for distribution is output to the build / libs directory.
$ ls build/libs/
helloworldmod-1.2.3.jar
Launch the regular Minecraft Java Edition Minecraft Launcher and configure the configuration for Minecraft Forge 1.15.2-31.1.0.
Place the created jar file in the mods directory of the game directory with the configuration you set, and start Minecraft Forge 1.15.2-31.1.0.
You can see that the Hello World Mod is loaded.
When you enter the world, Hello World is displayed in the chat column.
Recommended Posts