-
Notifications
You must be signed in to change notification settings - Fork 0
コメントを改善 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
コメントを改善 #1
Changes from all commits
6e5296f
07c518e
45e1959
fea043f
a83694e
ba2d5a2
ad270c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,104 +15,117 @@ | |||||||||||||||
| import net.neoforged.fml.common.Mod; | ||||||||||||||||
| import net.neoforged.fml.config.ModConfig; | ||||||||||||||||
| import net.neoforged.fml.ModContainer; | ||||||||||||||||
| import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; | ||||||||||||||||
| import net.neoforged.neoforge.registries.DeferredHolder; | ||||||||||||||||
| import net.neoforged.neoforge.registries.DeferredRegister; | ||||||||||||||||
|
|
||||||||||||||||
| // この値はMETA-INF/neoforge.mods.tomlファイルの入力と一致する必要があります。 | ||||||||||||||||
| // Modアノテーション、1.21.1になっても1.7.10と機能は同じ? | ||||||||||||||||
| @Mod(PolygonTrainMod.MODID) | ||||||||||||||||
| public class PolygonTrainMod { | ||||||||||||||||
| // すべての人が参照できるように、共通の場所にmodのidを定義する。 | ||||||||||||||||
| // コード全体から参照できるmodのid | ||||||||||||||||
| public static final String MODID = "polygontrainmod"; | ||||||||||||||||
| // slf4j ロガーを直接参照する | ||||||||||||||||
| // PolygonTrainModからのログと識別するため、そのMod専用のロガーを取得する。1.7.10時代のLog4jとは違い、SLF4Jはロギングライブラリではないらしい | ||||||||||||||||
| public static final Logger LOGGER = LogUtils.getLogger(); | ||||||||||||||||
| // CreativeModeTabsを保持するDeferred Registerを作成し、すべて "polygontrainmod "ネームスペースに登録する。 | ||||||||||||||||
| // CreativeModeTabsを保持するDeferredRegisterを作成し、すべてを名前空間"polygontrainmod"に登録する。 | ||||||||||||||||
| public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); | ||||||||||||||||
|
|
||||||||||||||||
| // DeferredRegisterは、MinecraftのRegistriesに登録されているタイプの要素の新しいバリエーションを実装する場合に必要になる | ||||||||||||||||
| // 対象となるのは、BlockやItem、Entityなど、`minecraft:object_id`の形式で表すタイプのオブジェクト? | ||||||||||||||||
| // GameRegistryを自由に呼びつけるのは危険なため、代わりにこれが使用されるようになったらしい | ||||||||||||||||
|
Comment on lines
+32
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメントに疑問符
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| // 名前空間とパスを組み合わせて、id "polygontrainmod:example_block "で新しいブロックを作成します。 | ||||||||||||||||
| // public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE)); | ||||||||||||||||
| // public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE)); | ||||||||||||||||
| // 名前空間とパスを組み合わせて、id "polygontrainmod:example_block "の新しいBlockItemを作成します。 | ||||||||||||||||
| // public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK); | ||||||||||||||||
| // public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK); | ||||||||||||||||
|
|
||||||||||||||||
| /* ~~~~~~~~~~ 以下DeferredHolderへの登録 ~~~~~~~~~~ */ | ||||||||||||||||
| // 作ったDeferredRegisterに登録されるそれぞれの要素を表すのが、DeferredHolder | ||||||||||||||||
| // FMLPreInitializationEventでGameRegistryに登録していた時代は、BlockやItemをコード内で使用する際に、そのオブジェクトのインスタンスが必ず生成されていることが明らかだったが | ||||||||||||||||
| // Modローダーの判断で生成されるシステムのDeferredRegisterではそれがない | ||||||||||||||||
| // そのため、実際のオブジェクトの代わりにコードで使用されるためにつくられたのが、DeferredHolderだと思う | ||||||||||||||||
|
Comment on lines
+41
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメントの末尾が
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| // 戦闘タブの後に配置される、idが"polygontrainmod:example_tab"のクリエイティブタブを登録 | ||||||||||||||||
| // クリエイティブタブ"polygontrainmod:main_tab"を登録 | ||||||||||||||||
| @SuppressWarnings("unused") | ||||||||||||||||
| public static final DeferredHolder<CreativeModeTab, CreativeModeTab> MAIN_TAB = CREATIVE_MODE_TABS.register("main_tab", () -> CreativeModeTab.builder() | ||||||||||||||||
| .title(Component.translatable("itemGroup.polygontrainmod")) //CreativeModeTabのタイトルの言語キー | ||||||||||||||||
| .withTabsBefore(CreativeModeTabs.COMBAT) | ||||||||||||||||
| // タブのアイコンを切符アイテムに設定 | ||||||||||||||||
| .icon(() -> PolygonTrainModItems.TICKET.get().getDefaultInstance()) | ||||||||||||||||
| .displayItems((parameters, output) -> { | ||||||||||||||||
| output.accept(PolygonTrainModItems.EXAMPLE_ITEM.get()); // サンプルアイテムをタブに追加します。独自のタブの場合は、イベントよりもこの方法が推奨されます。 | ||||||||||||||||
|
|
||||||||||||||||
| // EXAMPLE_ITEMをこのタブに追加 | ||||||||||||||||
| // Mod独自のタブにアイテムを追加する場合は、後述のEventよりもこの方法が推奨されるらしい | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||
| output.accept(PolygonTrainModItems.EXAMPLE_ITEM.get()); | ||||||||||||||||
| // 通常の乗車券をクリエイティブタブに追加 | ||||||||||||||||
| output.accept(PolygonTrainModItems.TICKET.get()); | ||||||||||||||||
| // 回数乗車券をクリエイティブタブに追加 | ||||||||||||||||
| output.accept(PolygonTrainModItems.COUPON_TICKET.get()); | ||||||||||||||||
| // ICカード乗車券をクリエイティブタブに追加 | ||||||||||||||||
| output.accept(PolygonTrainModItems.IC_CARD_TICKET.get()); | ||||||||||||||||
|
|
||||||||||||||||
| // インベントリに作成したブロックアイテムを追加する、ブロックを直接登録しても自動でブロックアイテムを探索してやってくれるらしい | ||||||||||||||||
| // 各種BlockのBlockItemをクリエイティブタブに追加する | ||||||||||||||||
| // 今回はItemを指定しているが、Blockを直接登録した場合も、自動で対応するBlockItemを探索してやってくれるらしい | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||
| output.accept(PolygonTrainModItems.TEST_AUTOMATIC_TICKET_GATE_ITEM.get()); | ||||||||||||||||
| output.accept(PolygonTrainModItems.OVERHEAD_LINE_POLE_ITEM.get()); | ||||||||||||||||
| }).build()); | ||||||||||||||||
|
|
||||||||||||||||
| // MODクラスのコンストラクタは、MODがロードされたときに最初に実行されるコードです。 | ||||||||||||||||
| // FML は IEventBus や ModContainer のようないくつかのパラメータタイプを認識し、 自動的に渡してくれます。 | ||||||||||||||||
| // MODクラスのコンストラクタは、MODがロードされたときに最初に実行されるらしい | ||||||||||||||||
| // FMLはIEventBusやModContainerのようないくつかの引数の型を認識し、自動的に渡すらしい | ||||||||||||||||
|
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||
| public PolygonTrainMod(IEventBus modEventBus, ModContainer modContainer, Dist dist) { | ||||||||||||||||
| // modloading用のcommonSetupメソッドを登録する。 | ||||||||||||||||
| modEventBus.addListener(this::commonSetup); | ||||||||||||||||
| // Modローディング時に行われるセットアップのメソッドを登録する | ||||||||||||||||
| // メソッド参照で、そのメソッドの引数のイベントの型が渡される | ||||||||||||||||
| // modEventBus.addListener(this::commonSetup); | ||||||||||||||||
|
|
||||||||||||||||
| // Dist.CLIENTをチェックして、クライアントサイドでのみ実行されるようにする | ||||||||||||||||
| if (dist == Dist.CLIENT) { | ||||||||||||||||
| // Entityのレンダラーの描画イベントを購読するメソッド | ||||||||||||||||
| modEventBus.addListener(PolygonTrainModRenderers::registerEntityRenderers); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // DeferredレジスタをMODイベントバスに登録し、ブロックが登録されるようにする | ||||||||||||||||
| // DeferredRegisterをNeoForgeのModEventBusに登録し、DeferredRegisterに登録された各ブロックがゲームに登録されるようにする | ||||||||||||||||
| PolygonTrainModBlocks.BLOCKS.register(modEventBus); | ||||||||||||||||
| // MODイベントバスにDeferred Registerを登録し、アイテムが登録されるようにする。 | ||||||||||||||||
| PolygonTrainModItems.ITEMS.register(modEventBus); | ||||||||||||||||
| // MODイベントバスにDeferred Registerを登録し、タブが登録されるようにする。 | ||||||||||||||||
| CREATIVE_MODE_TABS.register(modEventBus); | ||||||||||||||||
| // MODイベントバスに | ||||||||||||||||
| PolygonTrainModComponents.REGISTRAR.register(modEventBus); | ||||||||||||||||
| PolygonTrainModEntities.ENTITY_TYPES.register(modEventBus); | ||||||||||||||||
|
|
||||||||||||||||
| // 興味のあるサーバーやその他のゲームイベントに登録する。 | ||||||||||||||||
| // これは、*この*クラス(PolygonTrainMod)がイベントに直接反応することを望む場合にのみ必要であることに注意してください。 | ||||||||||||||||
| // 以下の onServerStarting() のように、このクラスに @SubscribeEvent アノテーション関数がない場合は、この行を追加しないでください。 | ||||||||||||||||
| // NeoForge.EVENT_BUS.register(this); | ||||||||||||||||
| // 利用したいサーバー、あるいはその他のゲームイベントに登録する | ||||||||||||||||
| // これは、このPolygonTrainModクラスがEventに直接反応することを望む場合にのみ必要であることに注意するらしい | ||||||||||||||||
| // 以下のonServerStarting()のような@SubscribeEventアノテーション関数がこのクラスにない場合は、この行を追加してはならないらしい | ||||||||||||||||
| // NeoForge.EVENT_BUS.register(this); | ||||||||||||||||
|
|
||||||||||||||||
| // アイテムをクリエイティブタブに登録する | ||||||||||||||||
| // modEventBus.addListener(this::addCreative); | ||||||||||||||||
| // modEventBus.addListener(this::addCreative); | ||||||||||||||||
|
|
||||||||||||||||
| // modのModConfigSpecを登録し、FMLが設定ファイルを作成して読み込むようにする。 | ||||||||||||||||
| // modのModConfigSpecを登録し、FMLがConfigファイルを作成して読み込むようにする | ||||||||||||||||
| modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| private void commonSetup(FMLCommonSetupEvent event) { | ||||||||||||||||
| // これがFMLInitializationEventに近いらしい | ||||||||||||||||
| // private void commonSetup(FMLCommonSetupEvent event) { | ||||||||||||||||
| // 一般的なセットアップコード | ||||||||||||||||
| // LOGGER.info("HELLO FROM COMMON SETUP"); | ||||||||||||||||
|
|
||||||||||||||||
| // if (Config.LOG_DIRT_BLOCK.getAsBoolean()) { | ||||||||||||||||
| // LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT)); | ||||||||||||||||
| // } | ||||||||||||||||
|
|
||||||||||||||||
| // LOGGER.info("{}{}", Config.MAGIC_NUMBER_INTRODUCTION.get(), Config.MAGIC_NUMBER.getAsInt()); | ||||||||||||||||
|
|
||||||||||||||||
| // Config.ITEM_STRINGS.get().forEach((item) -> LOGGER.info("ITEM >> {}", item)); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // ビルディング・ブロック・タブにサンプル・ブロック項目を追加する | ||||||||||||||||
| // private void addCreative(BuildCreativeModeTabContentsEvent event) { | ||||||||||||||||
| // if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) { | ||||||||||||||||
| // event.accept(EXAMPLE_BLOCK_ITEM); | ||||||||||||||||
| // } | ||||||||||||||||
| // } | ||||||||||||||||
|
|
||||||||||||||||
| // SubscribeEvent を使用し、イベントバスに呼び出すメソッドを発見させることができます | ||||||||||||||||
| // @SubscribeEvent | ||||||||||||||||
| // public void onServerStarting(ServerStartingEvent event) { | ||||||||||||||||
| // LOGGER.info("HELLO FROM COMMON SETUP"); | ||||||||||||||||
|
|
||||||||||||||||
| // if (Config.LOG_DIRT_BLOCK.getAsBoolean()) { | ||||||||||||||||
| // LOGGER.info("DIRT BLOCK >> {}", BuiltInRegistries.BLOCK.getKey(Blocks.DIRT)); | ||||||||||||||||
| // } | ||||||||||||||||
|
|
||||||||||||||||
| // LOGGER.info("{}{}", Config.MAGIC_NUMBER_INTRODUCTION.get(), Config.MAGIC_NUMBER.getAsInt()); | ||||||||||||||||
|
|
||||||||||||||||
| // Config.ITEM_STRINGS.get().forEach((item) -> LOGGER.info("ITEM >> {}", item)); | ||||||||||||||||
| // } | ||||||||||||||||
|
|
||||||||||||||||
| // 既存のクリエイティブタブにブロックを追加する例 | ||||||||||||||||
| // 建築ブロックタブにSAMPLE_BLOCKを追加する | ||||||||||||||||
| // 好きなEventを購読し、その際の処理を追加できるらしい | ||||||||||||||||
| // 購読できるEventは、net.neoforged.neoforge.eventにあるっぽい | ||||||||||||||||
| // private void addCreative(BuildCreativeModeTabContentsEvent event) { | ||||||||||||||||
| // if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) { | ||||||||||||||||
| // event.accept(EXAMPLE_BLOCK_ITEM); | ||||||||||||||||
| // } | ||||||||||||||||
| // } | ||||||||||||||||
|
|
||||||||||||||||
| // SubscribeEventを使用し、EventBusに呼び出すメソッドを発見させることができるらしい | ||||||||||||||||
| // @SubscribeEvent | ||||||||||||||||
| // public void onServerStarting(ServerStartingEvent event) { | ||||||||||||||||
| // サーバー起動時に何かする | ||||||||||||||||
| // LOGGER.info("HELLO from server starting"); | ||||||||||||||||
| // } | ||||||||||||||||
| // LOGGER.info("HELLO from server starting"); | ||||||||||||||||
| // } | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,9 +10,10 @@ | |||||||||
| import net.neoforged.neoforge.client.gui.ConfigurationScreen; | ||||||||||
| import net.neoforged.neoforge.client.gui.IConfigScreenFactory; | ||||||||||
|
|
||||||||||
| // このクラスは専用サーバーではロードされません。ここからクライアント側のコードにアクセスしても安全です。 | ||||||||||
| // Modアノテーションに、dist = Dist.CLIENTを指定しているため、このクラスはクライアントサイドにのみ存在するようになるらしい | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
| @Mod(value = PolygonTrainMod.MODID, dist = Dist.CLIENT) | ||||||||||
| // EventBusSubscriber を使用すると、@SubscribeEvent でアノテーションされたクラス内のすべての静的メソッドを自動的に登録できます。 | ||||||||||
| // EventBusSubscriberを使用すると、@SubscribeEventアノテーションのあるこのクラス内のすべての静的メソッドが、 | ||||||||||
| // Modコンストラクタで登録せずとも自動的に登録されるらしい | ||||||||||
|
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメントに
Suggested change
|
||||||||||
| @EventBusSubscriber(modid = PolygonTrainMod.MODID, value = Dist.CLIENT) | ||||||||||
| public class PolygonTrainModClient { | ||||||||||
| public PolygonTrainModClient(ModContainer container) { | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コメントに疑問符
?が含まれています。コードのドキュメントとして、コメントは事実を断定的に記述することが望ましいです。これにより、他の開発者がコードを理解しやすくなります。