Minecraft 1.14.4 Forge模组制作-第二部分【基本文件的设置】
首先
Minecraft 1.12.2の時に比べて書き方が大きく変わっている印象を受けました。
基本的なファイルを配置し、MinecraftがModを読み込むところまで進めます。

由于发生以下异常情况,请修改pack.mcmeta文件。
Caused by: com.google.gson.stream.MalformedJsonException: Expected name at line 5 column 6 path $.pack.pack_format
電腦開發环境
ここでは環境は以下のようにします。
-
Windows 10
JDK 8u211
Minecraft 1.14.4
Minecraft Forge 1.14.4 (28.1.0)
IntelliJ IDEA 2019.1.4
制作包装
まずはパッケージ(フォルダ)を作成しておきます。
パッケージの名前の付け方には一般的な決め方があります。
-
GroupId: 組織名のこと。一般的にはドメインを逆から書く形式
ArtifactId: プロジェクトの名前
当按照这个来决定名字时,将创建包装,并会变成以下形式。
C:\Users\HIRO\IdeaProjects\biwako_mod
└─src
└─main
├─java
│ └─jp
│ └─yuyu
│ └─biwako_mod
└─resources
└─assets
└─biwako_mod
pack.mcmeta
包装/mcmeta
这是一个记录资源包详细信息的文件。
我会参考之前下载的Mdk和forge-1.14.4-28.1.0-mdk.zip中的样本来编写。
我将在resources文件夹中创建一个文件。
1.7以前は”pack_format”: 1に、1.8以降からは”pack_format”: 2,に、1.11以降から1.12までは”pack_format”: 3に,1.13以降は”pack_format”:4にする必要があります。
リソースパックの作成方法 – Minecraft Japan Wiki – アットウィキより
由於這次是Minecraft 1.14.4版本,所以”pack_format”將變為4。
└─resources
│ *pack.mcmeta
│
└─assets
└─biwako_mod
{
"pack": {
"description": "Biwako Mod resources",
"pack_format": 4
}
}
mods.toml的含义是对游戏或软件进行自定义修改的配置文件。
这是一个包含Mod信息的文件。
在Minecraft 1.12.2中,它被称为mcmod.info。
我会根据”forge-1.14.4-28.1.0-mdk.zip”中的样本进行参考,并进行书写。
创建一个名为resources/META-INF的文件夹,并将mods.toml放置其中。
另外,将logo文件放置在resources文件夹中,并指定该文件的路径。
└─resources
│ pack.mcmeta
│ *logo.png
│
├─assets
│ └─biwako_mod
│
└─*META-INF
*mods.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 list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="biwako_mod" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
version="1.0.0"
# A display name for the mod
displayName="Biwako Mod" #mandatory
# A URL for the "homepage" for this mod, displayed in the mod UI
displayURL="https://github.com/Hiroya-W/biwakoMC" #optional
# A file name (in the root of the mod JAR) containing a logo for display
logoFile="logo.png" #optional
# A text field displayed in the mod UI
authors="Hiroya_W" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''
Biwako is the largest lake in Japan.
'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.biwako_mod]] #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.biwako_mod]]
modId="minecraft"
mandatory=true
versionRange="[1.14.4]"
ordering="NONE"
side="BOTH"
主类
创造
请将 BiwakoMod.java 放置在以下位置。
└─src
└─main
├─java
│ └─jp
│ └─yuyu
│ └─biwako_mod
│ *BiwakoMod.java
模板 (mó
@ModアノテーションにはMOD_ID名のみ記述する。
なので、1.12.2でのMOD_NAME、MOD_VERSIONはmods.tomlのみで管理するのだと思う。
@Modアノテーションのあるクラスのコンストラクタで、初期化処理のリスナを登録する
setupメソッドが1.12.2のpreInitメソッドに相当する。
doClientStuffはクライアント側でのみ実行する初期化処理を記述する。
1.12.2のClientProxyに相当する。
@ModアノテーションにはMOD_ID名のみ記述する。
なので、1.12.2でのMOD_NAME、MOD_VERSIONはmods.tomlのみで管理するのだと思う。
@Modアノテーションのあるクラスのコンストラクタで、初期化処理のリスナを登録する
setupメソッドが1.12.2のpreInitメソッドに相当する。
doClientStuffはクライアント側でのみ実行する初期化処理を記述する。
1.12.2のClientProxyに相当する。
在【Forge】1.13.2中详细介绍了自定义Entity和EntityRender的注册方法。
然后,这很可能会成为主类的模板。
package jp.yuyu.biwako_mod;
import net.minecraft.block.Block;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
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.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
// The value here should match an entry in the META-INF/mods.toml file
@Mod(BiwakoMod.MOD_ID)
public class BiwakoMod
{
public static final String MOD_ID = "biwako_mod";
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public BiwakoMod() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// 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");
}
private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("HELLO FROM Client Setup");
}
// 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");
}
}
}
启动Minecraft
在GitHub上发布了项目。

在GitHub上发布了项目。