提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
5行目: | 5行目: | ||
== 必要最低限のコード == | == 必要最低限のコード == | ||
− | + | MODのエントリポイントとなる@Modアノテーションが付いたクラスのみがある状態です。何の処理も行えないのですがMod一覧には表示されます。 | |
<source lang="java"> | <source lang="java"> | ||
18行目: | 18行目: | ||
== 初期化イベントを受け取る == | == 初期化イベントを受け取る == | ||
− | @ | + | @EventHandlerアノテーションをメソッドにつけると、MODが読み込まれる時にそのメソッドが呼ばれるためその中で様々な処理を行えます。ただし、その引数はある特定のイベントを表すクラス一つのみでなければなりません。 |
<source lang="java"> | <source lang="java"> | ||
25行目: | 25行目: | ||
import net.minecraftforge.fml.common.Mod; | import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.Mod.EventHandler; | import net.minecraftforge.fml.common.Mod.EventHandler; | ||
− | import net.minecraftforge.fml.common.event. | + | import net.minecraftforge.fml.common.event.PreInitializationEvent; |
− | import net.minecraftforge.fml.common.event. | + | import net.minecraftforge.fml.common.event.InitializationEvent; |
− | import net.minecraftforge.fml.common.event. | + | import net.minecraftforge.fml.common.event.PostInitializationEvent; |
@Mod(modid = "samplemod") | @Mod(modid = "samplemod") | ||
public class Sample { | public class Sample { | ||
@EventHandler | @EventHandler | ||
− | public | + | public preInit(PreInitializationEvent event) { |
− | // | + | // ... |
} | } | ||
@EventHandler | @EventHandler | ||
− | public | + | public init(InitializationEvent event) { |
− | // | + | // ... |
} | } | ||
@EventHandler | @EventHandler | ||
− | public | + | public postInit(PostInitializationEvent event) { |
− | // | + | // ... |
} | } | ||
} | } | ||
52行目: | 52行目: | ||
* [https://github.com/MinecraftForge/MinecraftForge/blob/b15269fde504dbe8837a540202a0947c1a5b3e62/src/main/java/net/minecraftforge/fml/common/Mod.java#L278-L303 公式ドキュメント(2017/12/13時点)] | * [https://github.com/MinecraftForge/MinecraftForge/blob/b15269fde504dbe8837a540202a0947c1a5b3e62/src/main/java/net/minecraftforge/fml/common/Mod.java#L278-L303 公式ドキュメント(2017/12/13時点)] | ||
− | == | + | == 様々なイベントを受け取る == |
− | + | @EventBusSubscriberアノテーションをクラスにつけると、@SubscribeEventアノテーションを'''static'''メソッドにつけることでイベントを受け取れます。 | |
− | + | ||
− | + | <source lang="java"> | |
− | + | package info.minecraftjp; | |
+ | |||
+ | import net.minecraftforge.fml.common.Mod; | ||
+ | import net.minecraftforge.fml.common.Mod.EventHandler; | ||
+ | import net.minecraftforge.fml.common.Mod.EventBusSubscriber; | ||
+ | import net.minecraftforge.fml.common.event.PreInitializationEvent; | ||
+ | import net.minecraftforge.fml.common.event.InitializationEvent; | ||
+ | import net.minecraftforge.fml.common.event.PostInitializationEvent; | ||
+ | |||
+ | @Mod(modid = "samplemod") | ||
+ | @EventBusSubscriber | ||
+ | public class Sample { | ||
+ | @EventHandler | ||
+ | public preInit(PreInitializationEvent event) { | ||
+ | // ... | ||
+ | } | ||
+ | |||
+ | @EventHandler | ||
+ | public init(InitializationEvent event) { | ||
+ | // ... | ||
+ | } | ||
+ | |||
+ | @EventHandler | ||
+ | public postInit(PostInitializationEvent event) { | ||
+ | // ... | ||
+ | } | ||
+ | |||
+ | @SubscribeEvent | ||
+ | public static registerItem(RegistryEvent.Register<Item> event) { | ||
+ | // ... | ||
+ | } | ||
+ | } | ||
+ | </source> |