うまげーむさん

ゲームの情報を主に投稿します。

【マインクラフト Modding】1.15対応 自作MODの作り方 #9 鉱石の生成

このシリーズのまとめはこちら:

umagame.hatenablog.jp

こんばんは。

はじめに

今回は鉱石ブロックを作って、それをワールドに生成されるようにしたいと思います。

前回:

umagame.hatenablog.jp

鉱石ブロックを作る

まず、以前の記事を参考に鉱石ブロックを作ります。

以前の記事:

umagame.hatenablog.jp

あと、ドロップ用のアイテムも作っておきます。

アイテムについてはこちら:

umagame.hatenablog.jp

こんな感じ。

f:id:Umagame:20200321211221p:plain

生成の設定

生成のクラスをworld/genにを作ります。

f:id:Umagame:20200321211654p:plain

例によりコードは丸パクリです。

package com.umagame.dirtmod.world.gen;

import com.umagame.dirtmod.init.DirtModBlocks;
import com.umagame.dirtmod.main.DirtMod;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.ConfiguredPlacement;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ObjectHolder;

@ObjectHolder(DirtMod.MOD_ID)
public class DirtModOreGen {
    @Mod.EventBusSubscriber(modid = DirtMod.MOD_ID, bus = Bus.MOD)
    public static class Register {
        @SubscribeEvent
        public static void loadCompleteEvent(FMLLoadCompleteEvent event) {
            for(Biome biome : ForgeRegistries.BIOMES) {
                ConfiguredPlacement<CountRangeConfig> customConfig = Placement.COUNT_RANGE
                        .func_227446_a_(new CountRangeConfig(20,0,0,64));
                biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE
                        .func_225566_b_(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, DirtModBlocks.DIRT_CRYSTAL_ORE.getDefaultState(), 9))
                        .func_227228_a_(customConfig));
            }
        }
    }
}

下の方のDirtModBlocks.DIRT_CRYSTAL_OREが生成される鉱石ブロックです。

また、この5つある数字についてですが、どれがなにを表しているかよくわかりません!

なので内部データを見てバニラの鉱石はどうなっているかを調べました。

適当にまとめるとこんな感じ(LibreOffice Calcで作ってそのまま記事にコピペしたらちゃんと表になりました。はてなブログすごい。)

  石炭 レッドストーン ダイヤモンド
new CountRangeConfigのところのやつ 20,0,0,128 20,0,0,64 2,0,0,32 8,0,0,16 1,0,0,16
.getDefaultState()のあとのやつ 17 9 9 8 8

今回は鉄と同じにしました。

あと、変数biomeを使って鉱石が生成されるバイオームを制限することもできます。

起動して確認してみるとありました。

f:id:Umagame:20200321221408p:plain

f:id:Umagame:20200321221422p:plain

 ブロックの修正

ブロックを壊せばそのままアイテムが出てくるので、経験値が壊したときに出るようにしましょう。

レッドストーン鉱石ブロックのコードからそのまま持ってきます。

@Override
public int getExpDrop(BlockState state, net.minecraft.world.IWorldReader world, BlockPos pos, int fortune, int silktouch) {
    return silktouch == 0 ? 1 + RANDOM.nextInt(5) : 0;
}

これをブロックのクラスに追加すればOKです。

さいごに

今回はここまでです。

次回:

umagame.hatenablog.jp