提供: Minecraft Modding Wiki
細 |
細 (→鉱石を生成する) |
||
47行目: | 47行目: | ||
} | } | ||
} | } | ||
+ | } | ||
+ | </source> | ||
+ | *SampleDefaultBiomeFeaturesMixin.java | ||
+ | <source lang = "java"> | ||
+ | package com.example.ore.mixin; | ||
+ | |||
+ | import net.minecraft.world.biome.GenerationSettings; | ||
+ | import net.minecraft.world.gen.GenerationStep; | ||
+ | import net.minecraft.world.gen.feature.DefaultBiomeFeatures; | ||
+ | |||
+ | import com.example.ore.SampleMod; | ||
+ | |||
+ | import org.spongepowered.asm.mixin.Mixin; | ||
+ | import org.spongepowered.asm.mixin.injection.At; | ||
+ | import org.spongepowered.asm.mixin.injection.Inject; | ||
+ | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
+ | |||
+ | @Mixin(DefaultBiomeFeatures.class) | ||
+ | public class SampleDefaultBiomeFeaturesMixin { | ||
+ | @Inject(method = "addDefaultOres(Lnet/minecraft/world/biome/GenerationSettings$Builder;)V", at = @At("TAIL")) | ||
+ | private static void addDefaultOres(GenerationSettings.Builder builder, CallbackInfo ci) { | ||
+ | builder.feature(GenerationStep.Feature.UNDERGROUND_ORES, SampleMod.ORE_OAK_LOG_OVERWORLD); | ||
+ | } | ||
} | } | ||
</source> | </source> | ||
56行目: | 79行目: | ||
"package": "com.example.ore.mixin", | "package": "com.example.ore.mixin", | ||
"compatibilityLevel": "JAVA_8", | "compatibilityLevel": "JAVA_8", | ||
+ | "$comment": "↓SampleDefaultBiomeFeaturesMixinをミックスインに追加", | ||
"mixins": [ | "mixins": [ | ||
− | " | + | "SampleDefaultBiomeFeaturesMixin" |
], | ], | ||
"client": [ | "client": [ | ||
67行目: | 91行目: | ||
} | } | ||
</source> | </source> | ||
+ | ===解説=== | ||
+ | |||
==解説== | ==解説== | ||
<source lang = "java"> | <source lang = "java"> |
2020年10月11日 (日) 12:47時点における版
この記事は"Fabric API 0.3.2 build 230~"を前提MODとしています。 |
ワールド上で鉱石のようにブロックを生成する方法
動作確認済みのバージョン:1.16.3
鉱石を生成する
ソースコード
- SampleMod.java
package com.example.ore; 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 ConfiguredFeature<?, ?> ORE_OAK_LOG_OVERWORLD = Feature.ORE .configure(new OreFeatureConfig( OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, Blocks.OAK_LOG.getDefaultState(), 9)) //鉱石(生成物)の最大サイズ .decorate(Decorator.RANGE.configure(new RangeDecoratorConfig( 0, 0, //鉱石(生成物)Y座標の最小レベル 64))) //鉱石(生成物)Y座標の最大レベル .spreadHorizontally() .repeat(20); //1チャンクあたりの鉱石(生成物)の数 @Override public void onInitialize() { //つくった鉱石(生成物)を登録 Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new Identifier(MOD_ID, "ore_oak_log_overworld"), ORE_OAK_LOG_OVERWORLD); } } }
- SampleDefaultBiomeFeaturesMixin.java
package com.example.ore.mixin; import net.minecraft.world.biome.GenerationSettings; import net.minecraft.world.gen.GenerationStep; import net.minecraft.world.gen.feature.DefaultBiomeFeatures; import com.example.ore.SampleMod; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(DefaultBiomeFeatures.class) public class SampleDefaultBiomeFeaturesMixin { @Inject(method = "addDefaultOres(Lnet/minecraft/world/biome/GenerationSettings$Builder;)V", at = @At("TAIL")) private static void addDefaultOres(GenerationSettings.Builder builder, CallbackInfo ci) { builder.feature(GenerationStep.Feature.UNDERGROUND_ORES, SampleMod.ORE_OAK_LOG_OVERWORLD); } }
- samplemod.mixins.json
{ "required": true, "minVersion": "0.8", "package": "com.example.ore.mixin", "compatibilityLevel": "JAVA_8", "$comment": "↓SampleDefaultBiomeFeaturesMixinをミックスインに追加", "mixins": [ "SampleDefaultBiomeFeaturesMixin" ], "client": [ "SampleMixin" ], "injectors": { "defaultRequire": 1 } }
解説
解説
public static final Block SAMPLE_BLOCK = new Block(FabricBlockSettings.of(Material.METAL).build());
素材を金属として設定。 ブロックを作成。
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)));
ブロックIDとアイテムIDの登録。 ブロックをアイテムとしてクリエイティブタグ、ItemGroup.MISC(その他)に登録。