LoginSignup
8
11

More than 3 years have passed since last update.

Minecraft 1.14.4 Forge Modの作成 その2 【基本的なファイルの配置】

Last updated at Posted at 2019-09-16

はじめに

Minecraft 1.12.2の時に比べて書き方が大きく変わっている印象を受けました。
基本的なファイルを配置し、MinecraftがModを読み込むところまで進めます。

2019-09-16_14.52.03.png

2019/10/29 下記例外が発生するため、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: プロジェクトの名前

これに従って名前を決めた時、パッケージを作成すると以下のようになります。

項目
GroupId jp.yuyu
ArtifactId biwako_mod
C:\Users\HIRO\IdeaProjects\biwako_mod
└─src
    └─main
        ├─java
        │  └─jp
        │      └─yuyu
        │          └─biwako_mod
        └─resources
            └─assets
                └─biwako_mod

pack.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.mcmeta
{
    "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を配置します。
また、ロゴファイルはresourcesフォルダ内に配置して、そのファイルパスを指定することにします。

└─resources
    │  pack.mcmeta
    │  *logo.png
    │
    ├─assets
    │  └─biwako_mod
    │
    └─*META-INF
            *mods.toml
mods.moml
# 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

ひな型

  • @ModアノテーションにはMOD_ID名のみ記述する。 なので、1.12.2でのMOD_NAMEMOD_VERSIONmods.tomlのみで管理するのだと思う。
  • @Modアノテーションのあるクラスのコンストラクタで、初期化処理のリスナを登録する
  • setupメソッドが1.12.2のpreInitメソッドに相当する。
  • doClientStuffはクライアント側でのみ実行する初期化処理を記述する。 1.12.2のClientProxyに相当する。

詳しくは【Forge】1.13.2での自作したEntityとEntityRenderの登録方法に詳しく書かれていました。

そして、おそろくこれがメインクラスのひな型になる。

BiwakoMod.java
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の起動

2019-09-16_14.52.03.png


Githubにてプロジェクトを公開しています。

8
11
14

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
11