提供: Minecraft Modding Wiki
(ページの作成:「{{前提MOD|reqmod="Fabric API 0.3.2 build 230~"}} {{チュートリアル難易度|difficulty=0|clear=none}} {{チュートリアルカテゴリー|difficulty=0|type=B…」) |
|||
37行目: | 37行目: | ||
} | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | ===ソースコード2=== | ||
+ | *SampleMod.java | ||
+ | <source lang = "java"> | ||
+ | package com.example.block; | ||
+ | |||
+ | import net.fabricmc.api.ModInitializer; | ||
+ | import net.minecraft.item.Item; | ||
+ | import net.minecraft.block.Block; | ||
+ | import net.minecraft.item.BlockItem; | ||
+ | import net.minecraft.item.ItemGroup; | ||
+ | import net.minecraft.util.Identifier; | ||
+ | import net.minecraft.util.registry.Registry; | ||
+ | |||
+ | public class SampleMod implements ModInitializer | ||
+ | { | ||
+ | /** | ||
+ | * ModID文字列 | ||
+ | */ | ||
+ | public static final String MOD_ID = "samplemod"; | ||
+ | |||
+ | //ブロック作成 | ||
+ | public static final Block SAMPLE_BLOCK = new SampleBlock(); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() | ||
+ | { | ||
+ | //ブロック登録 | ||
+ | Registry.register(Registry.BLOCK, new Identifier(MOD_ID, "sample_block"), SAMPLE_BLOCK); | ||
+ | //ブロックアイテムの登録 | ||
+ | Registry.register(Registry.ITEM, new Identifier(MOD_ID, "sample_block"), new BlockItem(SAMPLE_BLOCK, new Item.Settings().group(ItemGroup.MISC))); | ||
+ | |||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | *SampleBlock.java | ||
+ | <source lang = "java"> | ||
+ | package com.example.block; | ||
+ | |||
+ | import net.minecraft.item.Item; | ||
+ | |||
+ | public class SampleBlock extends Block | ||
+ | { | ||
+ | public SampleBlock(Settings settings) | ||
+ | { | ||
+ | super(settings); | ||
} | } | ||
} | } | ||
</source> | </source> |
2019年9月14日 (土) 18:22時点における版
この記事は"Fabric API 0.3.2 build 230~"を前提MODとしています。 |
ワールド上に設置できる簡単な無機能ブロックの追加方法
ブロックの追加
ソースコード
- SampleMod.java
package com.example.block; import net.fabricmc.api.ModInitializer; import net.minecraft.item.Item; import net.minecraft.block.Block; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemGroup; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; public class SampleMod implements ModInitializer { /** * ModID文字列 */ public static final String MOD_ID = "samplemod"; //ブロック作成 public static final Block SAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).build()); @Override public void onInitialize() { //ブロック登録 Registry.register(Registry.BLOCK, new Identifier(MOD_ID, "sample_block"), SAMPLE_BLOCK); //ブロックアイテムの登録 Registry.register(Registry.ITEM, new Identifier(MOD_ID, "sample_block"), new BlockItem(SAMPLE_BLOCK, new Item.Settings().group(ItemGroup.MISC))); } } }
ソースコード2
- SampleMod.java
package com.example.block; import net.fabricmc.api.ModInitializer; import net.minecraft.item.Item; import net.minecraft.block.Block; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemGroup; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; public class SampleMod implements ModInitializer { /** * ModID文字列 */ public static final String MOD_ID = "samplemod"; //ブロック作成 public static final Block SAMPLE_BLOCK = new SampleBlock(); @Override public void onInitialize() { //ブロック登録 Registry.register(Registry.BLOCK, new Identifier(MOD_ID, "sample_block"), SAMPLE_BLOCK); //ブロックアイテムの登録 Registry.register(Registry.ITEM, new Identifier(MOD_ID, "sample_block"), new BlockItem(SAMPLE_BLOCK, new Item.Settings().group(ItemGroup.MISC))); } } }
- SampleBlock.java
package com.example.block; import net.minecraft.item.Item; public class SampleBlock extends Block { public SampleBlock(Settings settings) { super(settings); } }