今天我们尝试对昨天自定义的群系中的地面进行制作。
1.在开发包data文件夹下面新建worldgen包 -> 在worldgen包中新建configured_surface_builder包 -> 在configured_surface_builder包中新建一个自定义的.json类型文件(以re8_wasteland.json进行演示)
在re8_wasteland.json中进行编辑:
{
"config": {
"top_material": {
"Name": "re8joymod:wasteland_grass" //顶部方块:你想设置的基础方块名称
},
"under_material": {
"Name": "re8joymod:wasteland_grass" //下层方块:同上
},
"underwater_material": {
"Name": "re8joymod:wasteland_grass" //水下方块:同上
}
},
"type": "re8joymod:re8_wasteland" //你的.json的名称
}
2.在common包下新建world包,在world包中新建surface包,在surface包中新建一个.java文件(以WasteLandSurfaceBuilder.java举例)
在WasteLandSurfaceBuilder.java中编写代码:
package com.joy187.re8joymod.common.world.surface;
import com.joy187.re8joymod.common.init.ModBlocks;
import com.mojang.serialization.Codec;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;
import java.util.Random;
public class WasteLandSurfaceBuilder extends SurfaceBuilder<SurfaceBuilderConfig> {
//你想在地面生成的方块(可以续写)
public static final BlockState WASTELAND_BLOCK = ModBlocks.WASTELAND_BLOCK.get().defaultBlockState();
public static final BlockState WASTELAND_ROCK_BLOCK = ModBlocks.WASTELAND_ROCK_BLOCK.get().defaultBlockState();
public static final BlockState PODZ_STONE = Blocks.PODZOL.defaultBlockState();
//每个方块对应有一个生成的配置
public static final SurfaceBuilderConfig WASTELAND_BLOCK_CONFIG = new SurfaceBuilderConfig(WASTELAND_BLOCK,
WASTELAND_BLOCK, WASTELAND_BLOCK);
public static final SurfaceBuilderConfig WASTELAND_ROCK_BLOCK_CONFIG = new SurfaceBuilderConfig(WASTELAND_ROCK_BLOCK,
WASTELAND_ROCK_BLOCK, WASTELAND_ROCK_BLOCK);
public static final SurfaceBuilderConfig STONE_CONFIG = new SurfaceBuilderConfig(PODZ_STONE, PODZ_STONE, PODZ_STONE);
public WasteLandSurfaceBuilder(Codec<SurfaceBuilderConfig> codec) {
super(codec);
}
@Override
public void apply(Random random, IChunk chunkIn, Biome biomeIn, int x, int z, int startHeight, double noise,
BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed, SurfaceBuilderConfig config) {
//由于是随机生成,你需要用一个random()函数进行方块的随机生成,具体数量由你上面的SurfaceBuilderConfig数量而定
//这里我们让地形由三种主要方块组成(荒草地(模组)、荒地岩(模组)、灰化土(原版方块))
if (random.nextInt(3) == 0) {
SurfaceBuilder.DEFAULT.apply(random, chunkIn, biomeIn, x, z, startHeight, noise, defaultBlock,
defaultFluid, seaLevel, seed, WASTELAND_BLOCK_CONFIG);
} else if (random.nextInt(3) == 1) {
SurfaceBuilder.DEFAULT.apply(random, chunkIn, biomeIn, x, z, startHeight, noise, defaultBlock,
defaultFluid, seaLevel, seed, STONE_CONFIG);
}
else {
SurfaceBuilder.DEFAULT.apply(random, chunkIn, biomeIn, x, z, startHeight, noise, defaultBlock,
defaultFluid, seaLevel, seed, WASTELAND_ROCK_BLOCK_CONFIG);
}
}
}
3.在Init包中新建SurfaceBuilderInit.java
在SurfaceBuilderInit.java中编写:
package com.joy187.re8joymod.common.init;
import com.joy187.re8joymod.Utils;
import com.joy187.re8joymod.common.world.surface.WasteLandSurfaceBuilder;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.gen.surfacebuilders.SurfaceBuilderConfig;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
public class SurfaceBuilderInit {
public static final DeferredRegister<SurfaceBuilder<?>> SURFACE_BUILDERS = DeferredRegister.create(ForgeRegistries.SURFACE_BUILDERS, Utils.MOD_ID);
public static final RegistryObject<WasteLandSurfaceBuilder> EXAMPLE_SURFACE_BUILDER = SURFACE_BUILDERS.register("re8_wasteland",
() -> new WasteLandSurfaceBuilder(SurfaceBuilderConfig.CODEC));
}
4.在Main.java中添加地面生成的注册事件:
在Main()函数中添加如下字段:
SurfaceBuilderInit.SURFACE_BUILDERS.register(bus);
5.找到之前我们的re8_biome.json文件,将第一行的地形进行替换(替换为第1步configured_surface_builder包中的.json文件名称)
5.运行游戏进行测试:
创建一个新的世界,出现以下的字段:
选择“Proceed”,进入主世界
输入如下命令对我们的自定义群系进行查找:
/locatebiome re8joymod:re8_biome
找到后游戏会传给我们一个群系的坐标 -> 输入一下指令进行传送
/tp @s 坐标(游戏中具体值)