2023年9月18日月曜日

MinecraftForgeについてくる ExampleMod.java の翻訳をしてみた

  Forge の mdk に入ってる gradle.properties を翻訳してみました。

ノリでバーッとやった完全な意訳なので、間違いなどのご指摘がございましたらお伝えいただけますと非常に助かります🙇


package com.example.examplemod;

import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.slf4j.Logger;

// The value here should match an entry in the META-INF/mods.toml file
// ここの値は、META-INF/mods.toml ファイル内のエントリと一致する必要がある
@Mod(ExampleMod.MODID)
public class ExampleMod
{
    // Define mod id in a common place for everything to reference
    // すべてが参照できる共通の場所で MOD ID を定義する (訳注: public static finalにする事でアクセス権がパブリックの静的定数でMOD IDを定義する)
    public static final String MODID = "examplemod";
    // Directly reference a slf4j logger
    // slf4jロガーへの直接参照 (訳注: SLF4Jはログ関係のライブラリ)
    private static final Logger LOGGER = LogUtils.getLogger();
    // Create a Deferred Register to hold Blocks which will all be registered under the "examplemod" namespace
    // "examplemod"ネームスペースに登録されるブロックを持ったDeferredRegisterクラスのインスタンスを作る(Deferred Register: 遅延登録)
    // @see https://docs.minecraftforge.net/en/1.20.x/concepts/registries/#deferredregister
    public static final DeferredRegister BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
    // Create a Deferred Register to hold Items which will all be registered under the "examplemod" namespace
    // "examplemod"ネームスペースに登録されるアイテムを持ったDeferredRegisterクラスのインスタンスを作る
    public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID);
    // Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace
    // "examplemod"ネームスペースに登録されるクリエイティブモードタブを持ったDeferredRegisterクラスのインスタンスを作る
    public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);

    // Creates a new Block with the id "examplemod:example_block", combining the namespace and path
    // ネームスペースとパスを組み合わせて、IDとして"examplemod:example_block"をもつ新しいブロッククラスのインスタンスを作る
    public static final RegistryObject EXAMPLE_BLOCK = BLOCKS.register("example_block", () -> new Block(BlockBehaviour.Properties.of().mapColor(MapColor.STONE)));
    // Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path
    // ネームスペースとパスを組み合わせて、IDとして"examplemod:example_block"をもつ新しいブロックアイテムクラスのインスタンスを作る
    public static final RegistryObject EXAMPLE_BLOCK_ITEM = ITEMS.register("example_block", () -> new BlockItem(EXAMPLE_BLOCK.get(), new Item.Properties()));

    // Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2
    // 満腹度1で隠し満腹度2の、IDとして"examplemod:example_id"をもつ新しい食料系アイテムクラスのインスタンスを作る
    // @see https://nekoyue.github.io/ForgeJavaDocs-NG/javadoc/1.19.3/net/minecraft/world/food/FoodProperties.Builder.html
    public static final RegistryObject EXAMPLE_ITEM = ITEMS.register("example_item", () -> new Item(new Item.Properties().food(new FoodProperties.Builder()
            .alwaysEat().nutrition(1).saturationMod(2f).build())));

    // Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab
    // IDとして"examplemod:example_tab"をもつ新しいクリエイティブタブクラスのインスタンスをつくって、コンバットタブの後に配置する。
    // @see https://nekoyue.github.io/ForgeJavaDocs-NG/javadoc/1.19.3/net/minecraft/world/item/CreativeModeTab.Builder.html
    public static final RegistryObject EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()
            .withTabsBefore(CreativeModeTabs.COMBAT)
            .icon(() -> EXAMPLE_ITEM.get().getDefaultInstance())
            .displayItems((parameters, output) -> {
                // Add the example item to the tab. For your own tabs, this method is preferred over the event
                // example_itemをタブに追加する。独自タブでは、このメソッドはイベントよりも優先される。
                output.accept(EXAMPLE_ITEM.get());
            }).build());

    public ExampleMod()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        // Register the commonSetup method for modloading
        // commonSetupメソッドをMODローディングに登録する
        modEventBus.addListener(this::commonSetup);

        // Register the Deferred Register to the mod event bus so blocks get registered
        // (45行目で作った)DiferredRegisterクラスのインスタンスをMODイベントバスに登録することで、ブロックが登録されるようにする
        BLOCKS.register(modEventBus);
        // Register the Deferred Register to the mod event bus so items get registered
        // (48行目で作った)DiferredRegisterクラスのインスタンスをMODイベントバスに登録することで、アイテムが登録されるようにする
        ITEMS.register(modEventBus);
        // Register the Deferred Register to the mod event bus so tabs get registered
        // (67行目で作った)DeferredRegisterクラスのインスタンスをMODイベントバスに登録する事で、タブが登録されるようにする
        CREATIVE_MODE_TABS.register(modEventBus);

        // Register ourselves for server and other game events we are interested in
        // 受信したいサーバーその他のゲームイベントを受け取るために自分自身を登録する
        MinecraftForge.EVENT_BUS.register(this);

        // Register the item to a creative tab
        // クリエイティブタブにアイテムを登録する
        modEventBus.addListener(this::addCreative);

        // Register our mod's ForgeConfigSpec so that Forge can create and load the config file for us
        // このMODのフォージコンフィグスペックを登録して、ForgeがこのMOD用のコンフィグファイルを作って読み込めるようにする
        ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.SPEC);
    }

    private void commonSetup(final FMLCommonSetupEvent event)
    {
        // Some common setup code
        // 全般的な設定のコード
        LOGGER.info("HELLO FROM COMMON SETUP  コモンセットアップのこんにちは");

        // 訳注 以下はコンフィグクラスを使った定数の取得方法の例になっている
        if (Config.logDirtBlock)
            LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT));

        LOGGER.info(Config.magicNumberIntroduction + Config.magicNumber);

        Config.items.forEach((item) -> LOGGER.info("ITEM >> {}", item.toString()));
    }

    // Add the example block item to the building blocks tab
    // exampleブロックアイテムをクリエイティブタブの建築タブに追加する
    private void addCreative(BuildCreativeModeTabContentsEvent event)
    {
        if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS)
            event.accept(EXAMPLE_BLOCK_ITEM);
    }

    // You can use SubscribeEvent and let the Event Bus discover methods to call
    // SubscribeEventを使ってイベントバスが呼び出すメソッドを見つけられるようにすることができる
    // @see https://docs.minecraftforge.net/en/1.20.x/concepts/events/#instance-annotated-event-handlers
    @SubscribeEvent
    public void onServerStarting(ServerStartingEvent event)
    {
        // Do something when the server starts
        // サーバーが起動した時になにかする
        LOGGER.info("HELLO from server starting  サーバー起動のこんにちは");
    }

    // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
    // クラス中に@SubscribeEventをアノテーションされたスタティックメソッドを自動で登録するために、EventBusSubscriberを使う事ができる。
    // 訳注 スタティックなイベントハンドラーをアノテーションを使って登録する場合には@Mod.EventBusSubscriberを使う必要がある。(アノテーションを使わない場合、 `MinecraftForge.EVENT_BUS.register(ClientModEvents.class)` のような形で登録する)
    // @see https://docs.minecraftforge.net/en/1.20.x/concepts/events/#automatically-registering-static-event-handlers
    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public static class ClientModEvents
    {
        @SubscribeEvent
        public static void onClientSetup(FMLClientSetupEvent event)
        {
            // Some client setup code
            // クライアントをセットアップする何かしらのコード
            LOGGER.info("HELLO FROM CLIENT SETUP  クライアントセットアップのこんにちは");
            LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
        }
    }
}

changelogのバージョン表記は『47.1.0 1.20.1』でした。
nutritionとsaturationをどう訳せば良いのかわからずちょっと困りました
友人にアドバイスを頼んだりして、結局 nutrition を「満腹度」、 saturation を「隠し満腹度」としたのですが、合ってますでしょうか…😓

0 件のコメント:

コメントを投稿

MinecraftForgeについてくる ExampleMod.java の翻訳をしてみた

  Forge の mdk に入ってる gradle.properties を翻訳してみました。 ノリでバーッとやった完全な意訳なので、間違いなどのご指摘がございましたらお伝えいただけますと非常に助かります🙇