プロジェクトの構成 1.21.8
Fabric Mod プロジェクトの構成の概要
WARNING
This page is written for version 1.21.8. Documentation for older versions may be incomplete.
このページでは、Fabric Mod プロジェクトの構成と、各ファイルやフォルダの目的について説明します。
fabric.mod.json
fabric.mod.json ファイルは Mod の情報を Fabric Loader に伝えます。 ファイルには Mod の ID、バージョン、依存関係などの情報が書かれます。 ファイルには Mod の ID、バージョン、依存関係などの情報が書かれます。
fabric.mod.json 内の最も重要なフィールドは次の通りです:
id: Mod の ID。一意の値である必要がある。name: Mod の名前。environment: Mod が動く環境。client、server、*(両方)のいずれか。entrypoints: Mod が提供するエントリポイント。mainやclientなど。depends: Mod が依存する Mod の ID のリスト。mixins: Mod が提供する Mixin 構成ファイルのリスト。
以下に fabric.mod.json ファイルの例を示します。これは、このドキュメント上のサンプルプロジェクトで使われる fabric.mod.json ファイルです。
サンプルプロジェクト fabric.mod.json
json
{
"schemaVersion": 1,
"id": "fabric-docs-reference",
"version": "1.0.0",
"name": "Fabric docs reference",
"icon": "assets/fabric-docs-reference/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"com.example.docs.FabricDocsReference",
"com.example.docs.event.FabricDocsReferenceEvents",
"com.example.docs.command.FabricDocsReferenceCommands",
"com.example.docs.effect.FabricDocsReferenceEffects",
"com.example.docs.potion.FabricDocsReferencePotions",
"com.example.docs.sound.FabricDocsReferenceSounds",
"com.example.docs.damage.FabricDocsReferenceDamageTypes",
"com.example.docs.item.FabricDocsReferenceItems",
"com.example.docs.enchantment.FabricDocsReferenceEnchantments",
"com.example.docs.block.FabricDocsReferenceBlocks",
"com.example.docs.block.entity.FabricDocsReferenceBlockEntities",
"com.example.docs.component.FabricDocsReferenceComponents",
"com.example.docs.advancement.FabricDocsReferenceDatagenAdvancement",
"com.example.docs.networking.FabricDocsReferenceNetworking",
"com.example.docs.networking.basic.FabricDocsReferenceNetworkingBasic",
"com.example.docs.debug.FabricDocsReferenceDebug"
],
"client": [
"com.example.docs.client.command.FabricDocsReferenceClientCommands",
"com.example.docs.FabricDocsBlockEntityRenderer",
"com.example.docs.FabricDocsDynamicSound",
"com.example.docs.FabricDocsReferenceClient",
"com.example.docs.rendering.CustomRenderPipeline",
"com.example.docs.rendering.HudRenderingEntrypoint",
"com.example.docs.rendering.RenderingConceptsEntrypoint",
"com.example.docs.network.basic.FabricDocsReferenceNetworkingBasicClient"
],
"fabric-datagen": [
"com.example.docs.datagen.FabricDocsReferenceDataGenerator"
]
},
"mixins": [
"fabric-docs-reference.mixins.json",
{
"config": "fabric-docs-reference.client.mixins.json",
"environment": "client"
}
],
"depends": {}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
エントリポイント
上述のとおり、fabric.mod.json ファイルは entrypoints というフィールドを持ちます。このフィールドは、Mod が提供するエントリポイントを示します。
テンプレート Mod ジェネレータはデフォルトで main と client のエントリポイントを作成します。main エントリポイントは共通するコードに使用され、client エントリポイントはクライアントでのみ実行されるコードに使用されます。 これらのエントリポイントは、ゲーム開始時にそれぞれ呼び出されます。
mainエントリポイントはクライアントとサーバの両方の環境で共通するコードに使用され、そのクラスはModInitializerを実装しますclientエントリポイントはクライアント固有のコードに使用され、そのクラスはClientModInitializerを実装します
これらのエントリポイントは、ゲーム開始時にそれぞれ呼び出されます。
上記のコードは、ゲーム開始時にコンソールにログを出力する、シンプルな main エントリポイントの例です。
java
public class FabricDocsReference implements ModInitializer {
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final String MOD_ID = "fabric-docs-reference";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.
LOGGER.info("Hello Fabric world!");
// #tooltip_provider
ComponentTooltipAppenderRegistry.addAfter(DataComponents.DAMAGE, ModComponents.COMPONENT_WITH_TOOLTIP);
// #tooltip_provider
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
src/main/resources
src/main/resources フォルダは、 Mod が使用するリソースを格納するために使用されます。リソースは、テクスチャ、モデル、サウンドなどのことです。
また、fabric.mod.json ファイルや Mod が使用する Mixin 構成ファイルが配置される場所でもあります。
リソースは、リソースパックの構造に従って格納されます。例えば、ブロックのテクスチャは assets/modid/textures/block/block.png に格納されます。
src/client/resources
src/client/resources フォルダは、クライアント固有のリソースを格納するために使用されます。
src/main/java
src/client/java フォルダは、クライアント固有の Java コードを格納するために使用されます。クライアント固有のコードとは、描画処理を行うコードや、クライアントサイドにのみ存在するロジックのコード(ブロックカラープロバイダなど)を指します。
src/client/java
src/main/java フォルダは、クライアントとサーバの両方の環境で共通する Java コードを格納するために使用されます。

