User Tools

Site Tools


tutorial:biomes

This is an old revision of the document!


Adding a Biome

Introduction

This wiki tutorial is focused on registering and adding biomes to the world.

To add a biome, we will first need to create and register the biome, then add it to the world using helper methods from Fabric API. This tutorial will go over:

  • Creating a biome
  • Registering a biome
  • Adding a biome to a climate zone in the world
  • Allowing the player to spawn in the biome

We will also briefly go over other helpful biome-adding methods in the api.

Creating a Biome

To create a biome, create a class that extends Biome. This is the base class that holds biome information, and all vanilla biomes extend this. This class defines:

  • The basic properties of the biome
  • What features (trees, plants and structures) generate here
  • What entities spawn here

We need to pass a Biome.Settings instance with all the basic properties of the biome to the super constructor. Missing one property will likely cause the game to crash. It is recommended to look at vanilla biomes such as MountainsBiome and ForestBiome as examples.

Some important settings are depth (height), scale (hill size), and precipitation (weather)

  1. public class MyBiome extends Biome
  2. {
  3. public MyBiome()
  4. {
  5. super(new Biome.Settings().configureSurfaceBuilder(SurfaceBuilder.DEFAULT, SurfaceBuilder.GRASS_CONFIG).precipitation(Biome.Precipitation.RAIN).category(Biome.Category.PLAINS).depth(0.24F).scale(0.2F).temperature(0.6F).downfall(0.7F).waterColor(4159204).waterFogColor(329011).parent((String)null));
  6. }
  7. }

We then need to specify the features and entities that spawn in the biome. Aside from some structures, trees, rocks, plants and custom entities, these are mostly the same for each biome. Vanilla configured features for biomes are defined through methods in DefaultBiomeFeatures.

  1. public class MyBiome extends Biome
  2. {
  3. public MyBiome()
  4. {
  5. super(new Biome.Settings().configureSurfaceBuilder(SurfaceBuilder.DEFAULT, SurfaceBuilder.GRASS_CONFIG).precipitation(Biome.Precipitation.RAIN).category(Biome.Category.PLAINS).depth(0.24F).scale(0.2F).temperature(0.6F).downfall(0.7F).waterColor(4159204).waterFogColor(329011).parent((String)null));
  6.  
  7. this.addStructureFeature(Feature.MINESHAFT, new MineshaftFeatureConfig(0.004D, MineshaftFeature.Type.NORMAL));
  8. this.addStructureFeature(Feature.STRONGHOLD, FeatureConfig.DEFAULT);
  9. this.addStructureFeature(Feature.VILLAGE, new VillageFeatureConfig("village/plains/town_centers", 6));
  10. DefaultBiomeFeatures.addLandCarvers(this);
  11. DefaultBiomeFeatures.addDefaultStructures(this);
  12. DefaultBiomeFeatures.addDefaultLakes(this);
  13. DefaultBiomeFeatures.addDungeons(this);
  14. DefaultBiomeFeatures.addExtraMountainTrees(this);
  15. DefaultBiomeFeatures.addDefaultFlowers(this);
  16. DefaultBiomeFeatures.addDefaultGrass(this);
  17. DefaultBiomeFeatures.addMineables(this);
  18. DefaultBiomeFeatures.addDefaultOres(this);
  19. DefaultBiomeFeatures.addDefaultDisks(this);
  20. DefaultBiomeFeatures.addDefaultVegetation(this);
  21. DefaultBiomeFeatures.addSprings(this);
  22. DefaultBiomeFeatures.addFrozenTopLayer(this);
  23. this.addSpawn(EntityCategory.CREATURE, new Biome.SpawnEntry(EntityType.SHEEP, 12, 4, 4));
  24. this.addSpawn(EntityCategory.CREATURE, new Biome.SpawnEntry(EntityType.PIG, 10, 4, 4));
  25. this.addSpawn(EntityCategory.CREATURE, new Biome.SpawnEntry(EntityType.CHICKEN, 10, 4, 4));
  26. this.addSpawn(EntityCategory.CREATURE, new Biome.SpawnEntry(EntityType.COW, 8, 4, 4));
  27. this.addSpawn(EntityCategory.AMBIENT, new Biome.SpawnEntry(EntityType.BAT, 10, 8, 8));
  28. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.SPIDER, 100, 4, 4));
  29. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.ZOMBIE, 95, 4, 4));
  30. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.ZOMBIE_VILLAGER, 5, 1, 1));
  31. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.SKELETON, 100, 4, 4));
  32. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.CREEPER, 100, 4, 4));
  33. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.SLIME, 100, 4, 4));
  34. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.ENDERMAN, 10, 1, 4));
  35. this.addSpawn(EntityCategory.MONSTER, new Biome.SpawnEntry(EntityType.WITCH, 5, 1, 1));
  36. }
  37. }

Registering Biomes

To register your biome, we will create a field which holds a biome instance, and add our biome to Registry.BIOME. It is recommended to make a class to hold your biome objects.

  1. public class TutorialBiomes
  2. {
  3. public static final Biome MY_BIOME = Registry.register(Registry.BIOME, new Identifier("tutorial", "my_biome"), new MyBiome());
  4. }

You should also give your biome a language entry in your en_us.json file:

src/main/resources/assets/tutorial/lang/en_us.json
{
  "biome.tutorial.my_biome": "My Biome"
}

Adding a biome to the world generator

To make your biome spawn in the world, we will use the helper methods provided by the Fabric-Biomes API module. The code for this should ideally be run during mod initialization.

We need to specify the climate to which the biome is added, the biome which we are adding, and the weight of the biome (a double value). The weight is a measurement of the chance the biome has to spawn. A higher weight corresponds to a higher chance for the biome to spawn, proportional to the weights of other biomes. The Javadoc comments of each climate give the vanilla biome weights in each climate. You may want to give your biome a higher weight during testing so you can find the biome more easily.

In this tutorial, we will add the custom biome to the TEMPERATE and COOL climates as an example:

  1. public class ExampleMod implements ModInitializer
  2. {
  3. @Override
  4. public void onInitialize()
  5. {
  6. OverworldBiomes.addContinentalBiome(OverworldClimate.TEMPERATE, TutorialBiomes.MY_BIOME, 2D);
  7. OverworldBiomes.addContinentalBiome(OverworldClimate.COOL, TutorialBiomes.MY_BIOME, 2D);
  8. }
  9. }

To make the player able to spawn in the biome, we will use another method from the fabric-biomes api module:

  1. FabricBiomes.addSpawnBiome(TutorialBiomes.MY_BIOME);

Congratulations! Your biome should now be generating in the world!

Other useful biome methods

There are other useful methods in the fabric biomes api that you may want to use, that add extra functionality.

  • Setting the river biome

For example, setting your biome not to generate a river:

OverworldBiomes.setRiverBiome(OverworldClimate.TEMPERATE, TutorialBiomes.MY_BIOME);
  • Adding biome variants

The third number is the chance (out of 1) for the biome to replaced with the specified variant. For example, setting your biome to be a variant of plains, 33% of the time:

OverworldBiomes.addBiomeVariant(Biomes.PLAINS, TutorialBiomes.MY_BIOME, 0.33);

The following methods take a weight value which specifies how common the biome is relative to other specified variants

  • Adding hills biomes

For example, setting mountains to be a “hills” variant of your biome:

OverworldBiomes.addHillsBiome(TutorialBiomes.MY_BIOME, Biomes.MOUNTAINS, 1);
  • Adding biome edges

For example, making forest generate on the edge of your biome:

OverworldBiomes.addEdgeBiome(TutorialBiomes.MY_BIOME, Biomes.FOREST, 1);
  • Adding biome shores / beaches

For example, making stone beach generate on the shore of your biome:

OverworldBiomes.addShoreBiome(TutorialBiomes.MY_BIOME, Biomes.STONE_BEACH, 1);
tutorial/biomes.1562191261.txt.gz · Last modified: 2019/07/03 22:01 by valoeghese