跳到主要内容

43生物群系

代码

添加gradle依赖:

maven { url = 'https://maven.minecraftforge.net/' }
modImplementation 'com.github.glitchfiend:TerraBlender-fabric:1.20.2-3.0.0.170'

fabric.mod.json:

"entrypoints": {
"terrablender": [
"net.kaupenjoe.tutorialmod.world.biome.ModTerrablenderAPI"
]
},

world中新建biome/surface包:

ModMaterialRules:

public class ModMaterialRules {
private static final MaterialRules.MaterialRule DIRT = makeStateRule(Blocks.DIRT);
private static final MaterialRules.MaterialRule GRASS_BLOCK = makeStateRule(Blocks.GRASS_BLOCK);
private static final MaterialRules.MaterialRule RUBY = makeStateRule(ModBlocks.RUBY_BLOCK);
private static final MaterialRules.MaterialRule RAW_RUBY = makeStateRule(ModBlocks.RAW_RUBY_BLOCK);

public static MaterialRules.MaterialRule makeRules() {
MaterialRules.MaterialCondition isAtOrAboveWaterLevel = MaterialRules.water(-1, 0);

MaterialRules.MaterialRule grassSurface = MaterialRules.sequence(MaterialRules.condition(isAtOrAboveWaterLevel, GRASS_BLOCK), DIRT);

return MaterialRules.sequence(
MaterialRules.sequence(MaterialRules.condition(MaterialRules.biome(ModBiomes.TEST_BIOME),
MaterialRules.condition(MaterialRules.STONE_DEPTH_FLOOR, RAW_RUBY)),
MaterialRules.condition(MaterialRules.STONE_DEPTH_CEILING, RUBY)),

// Default to a grass and dirt surface
MaterialRules.condition(MaterialRules.STONE_DEPTH_FLOOR, grassSurface)
);
}

private static MaterialRules.MaterialRule makeStateRule(Block block) {
return MaterialRules.block(block.getDefaultState());
}
}

ModBiomes:

public class ModBiomes {
public static final RegistryKey<Biome> TEST_BIOME = RegistryKey.of(RegistryKeys.BIOME,
new Identifier(TutorialMod.MOD_ID, "test_biome"));

public static void boostrap(Registerable<Biome> context) {
context.register(TEST_BIOME, testBiome(context));
}

public static void globalOverworldGeneration(GenerationSettings.LookupBackedBuilder builder) {
DefaultBiomeFeatures.addLandCarvers(builder);
DefaultBiomeFeatures.addAmethystGeodes(builder);
DefaultBiomeFeatures.addDungeons(builder);
DefaultBiomeFeatures.addMineables(builder);
DefaultBiomeFeatures.addSprings(builder);
DefaultBiomeFeatures.addFrozenTopLayer(builder);
}

public static Biome testBiome(Registerable<Biome> context) {
SpawnSettings.Builder spawnBuilder = new SpawnSettings.Builder();
spawnBuilder.spawn(SpawnGroup.CREATURE, new SpawnSettings.SpawnEntry(ModEntities.PORCUPINE, 2, 3, 5));

spawnBuilder.spawn(SpawnGroup.CREATURE, new SpawnSettings.SpawnEntry(EntityType.WOLF, 5, 4, 4));

DefaultBiomeFeatures.addFarmAnimals(spawnBuilder);
DefaultBiomeFeatures.addBatsAndMonsters(spawnBuilder);

GenerationSettings.LookupBackedBuilder biomeBuilder =
new GenerationSettings.LookupBackedBuilder(context.getRegistryLookup(RegistryKeys.PLACED_FEATURE),
context.getRegistryLookup(RegistryKeys.CONFIGURED_CARVER));

globalOverworldGeneration(biomeBuilder);
DefaultBiomeFeatures.addMossyRocks(biomeBuilder);
DefaultBiomeFeatures.addDefaultOres(biomeBuilder);
DefaultBiomeFeatures.addExtraGoldOre(biomeBuilder);

biomeBuilder.feature(GenerationStep.Feature.VEGETAL_DECORATION, VegetationPlacedFeatures.TREES_PLAINS);
DefaultBiomeFeatures.addForestFlowers(biomeBuilder);
DefaultBiomeFeatures.addLargeFerns(biomeBuilder);

DefaultBiomeFeatures.addDefaultMushrooms(biomeBuilder);
DefaultBiomeFeatures.addDefaultVegetation(biomeBuilder);

return new Biome.Builder()
.precipitation(true)
.downfall(0.4f)
.temperature(0.7f)
.generationSettings(biomeBuilder.build())
.spawnSettings(spawnBuilder.build())
.effects((new BiomeEffects.Builder())
.waterColor(0xe82e3b)
.waterFogColor(0xbf1b26)
.skyColor(0x30c918)
.grassColor(0x7f03fc)
.foliageColor(0xd203fc)
.fogColor(0x22a1e6)
.moodSound(BiomeMoodSound.CAVE)
.music(MusicType.createIngameMusic(RegistryEntry.of(ModSounds.BAR_BRAWL))).build())
.build();
}
}

ModOverworldRegion:

public class ModOverworldRegion extends Region {
public ModOverworldRegion(Identifier name, int weight) {
super(name, RegionType.OVERWORLD, weight);
}

@Override
public void addBiomes(Registry<Biome> registry, Consumer<Pair<MultiNoiseUtil.NoiseHypercube,
RegistryKey<Biome>>> mapper) {
this.addModifiedVanillaOverworldBiomes(mapper, modifiedVanillaOverworldBuilder -> {
modifiedVanillaOverworldBuilder.replaceBiome(BiomeKeys.FOREST, ModBiomes.TEST_BIOME);
});
}
}

ModTerrablenderAPI:

public class ModTerrablenderAPI implements TerraBlenderApi {
@Override
public void onTerraBlenderInitialized() {
Regions.register(new ModOverworldRegion(new Identifier(TutorialMod.MOD_ID, "overworld"), 4));

SurfaceRuleManager.addSurfaceRules(SurfaceRuleManager.RuleCategory.OVERWORLD, TutorialMod.MOD_ID, ModMaterialRules.makeRules());
}
}

TutorialModDataGenerator:

registryBuilder.addRegistry(RegistryKeys.BIOME, ModBiomes::boostrap);

效果

image-20240825214923963