うまげーむさん

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

【マインクラフト Modding】1.15対応 自作MODの作り方 #10 バイオーム

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

umagame.hatenablog.jp

どうも。ついにパート10まで行きました。

はじめに

今回はバイオームを作ります。

言わずもがな土バイオームです。

前回:

umagame.hatenablog.jp

バイオームを作る

バイオームのクラス

バイオームのクラスをworld/biomeに作ります。

f:id:Umagame:20200322115046p:plain

バニラの草原バイオームを参考にコードを書きます。

package com.umagame.dirtmod.world.biome;

import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.DefaultBiomeFeatures;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.structure.MineshaftConfig;
import net.minecraft.world.gen.feature.structure.MineshaftStructure;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;

public class BiomeDirt extends Biome{
    public BiomeDirt() {
        super((new Biome.Builder()).surfaceBuilder(SurfaceBuilder.DEFAULT,
                new SurfaceBuilderConfig(Blocks.COARSE_DIRT.getDefaultState(),
                        Blocks.DIRT.getDefaultState(),
                        Blocks.GRAVEL.getDefaultState()))
                .precipitation(Biome.RainType.RAIN).category(Biome.Category.PLAINS)
                .depth(0.125F).scale(0.05F).temperature(0.8F).downfall(0.4F)
                .waterColor(8666880).waterFogColor(8666880).parent((String)null));
        this.func_226711_a_(Feature.MINESHAFT.func_225566_b_(new MineshaftConfig(0.004D, MineshaftStructure.Type.NORMAL)));
        this.func_226711_a_(Feature.STRONGHOLD.func_225566_b_(IFeatureConfig.NO_FEATURE_CONFIG));
        DefaultBiomeFeatures.addCarvers(this);
        DefaultBiomeFeatures.addLakes(this);
        DefaultBiomeFeatures.addMonsterRooms(this);
        DefaultBiomeFeatures.addStoneVariants(this);
        DefaultBiomeFeatures.addOres(this);
        DefaultBiomeFeatures.addSedimentDisks(this);
        this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.SHEEP, 12, 4, 4));
        this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.PIG, 10, 4, 4));
        this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.CHICKEN, 10, 4, 4));
        this.addSpawn(EntityClassification.CREATURE, new Biome.SpawnListEntry(EntityType.COW, 8, 4, 4));
        this.addSpawn(EntityClassification.AMBIENT, new Biome.SpawnListEntry(EntityType.BAT, 10, 8, 8));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SPIDER, 100, 4, 4));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ZOMBIE, 95, 4, 4));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ZOMBIE_VILLAGER, 5, 1, 1));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SKELETON, 100, 4, 4));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.CREEPER, 100, 4, 4));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.SLIME, 100, 4, 4));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.ENDERMAN, 10, 1, 4));
        this.addSpawn(EntityClassification.MONSTER, new Biome.SpawnListEntry(EntityType.WITCH, 5, 1, 1));
    }
}

少し説明すると、

上の方のnew SurfaceBuilderConfigのところでバイオームのブロックを設定できます。

今回は地表が荒れた土、その下が普通の土、海底のブロックを砂利にしています。(バニラのバイオームでも同じようなやつがあった気がする)

あと、それのもう少し下のwaterColor、waterFogColorで水と水に入ったときのフォグの色を設定しています。(今回は茶色にしています)

この数字についてはこちらのサイトで確認することができます。

https://www.mathsisfun.com/hexadecimal-decimal-colors.html(MathIsFun)

f:id:Umagame:20200322115751p:plain

画像バグってるけど気にしない

Decimalのとこの数字を使いましょう。
あと、廃坑や遺跡、スポナーも出るようにしています。

バイオームの登録

バイオーム登録用のクラスをinitパッケージに作ります。

f:id:Umagame:20200322120051p:plain

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

package com.umagame.dirtmod.init;

import com.umagame.dirtmod.main.DirtMod;
import com.umagame.dirtmod.world.biome.BiomeDirt;

import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.BiomeManager;
import net.minecraftforge.common.BiomeManager.BiomeEntry;
import net.minecraftforge.common.BiomeManager.BiomeType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.ObjectHolder;

@ObjectHolder(DirtMod.MOD_ID)
public class DirtModBiomes {
public static final BiomeDirt DIRT = null;

    @Mod.EventBusSubscriber(modid = DirtMod.MOD_ID, bus = Bus.MOD)
    public static class Register {

        @SubscribeEvent
        public static void registerBiomes(final RegistryEvent.Register<Biome> event) {
            final Biome[] biomes = {
                new BiomeDirt().setRegistryName(DirtMod.MOD_ID, "dirt")
            };

            event.getRegistry().registerAll(biomes);
        }
    }

    public static void addBiomes() {
        BiomeManager.addBiome(BiomeType.WARM, new BiomeEntry(DIRT, 10));
        BiomeManager.addSpawnBiome(DIRT);
    }
}

これも少し説明すると、

真ん中の"dirt"がバイオームIDです。

で、下の方のaddBiomeの左がバイオームのタイプで、右の数字はバイオームのでやすさです。(草原とかは10)

バイオームは設定が多いのでここですべて紹介することはできませんが、大体の設定はこれでOKです。

あと、langファイルでバイオームの名前も設定しておきます。

この一行を追加。

"biome.dirtmod.dirt": ""

これで起動して確認してみます。

いつのアプデか知りませんが、ビュッフェというワールドタイプが使えそうなのでこれを使ってみます。

f:id:Umagame:20200322122024p:plain

「土」って書いてあるのなんか面白いですね。

f:id:Umagame:20200322122322p:plain

ちゃんとブロックと水の色が適応されています。

f:id:Umagame:20200322152418p:plain

さいごに

今回はここまでです。

前回の記事のときにいいましたが、鉱石の生成にバイオームを指定できるのでやってみてはいかがでしょうか。

次回:

umagame.hatenablog.jp