The Forge BiomeDictionary contains a set of tools that make it easier to support modded biomes in mods that add biome specific world gen, or mobs. It does this by assigning tags to biomes (such as FOREST) based on their properties (temperature, height, number of trees, etc.). This tutorial will cover how to register biomes you've created, manually, how to check if a biome has specific tags (for world generation), or get a list of all biomes with a specific tag (for mobs). I will assume that you already know how create a biome, a world generator, or a mob, depending on which section of the tutorial you're interested in.
Imports
To use BiomeDictionary, you must import the following:
You should already understand what the first line does if you're at all familiar with Java, however, the second line may need some explanation. import static allows you to import a specific public field in a class in such a way that you can reference it directly, without referring to the class that contains it. In this case, we are using an import static on the enum which contains the different tags defined by BiomeDictionary. This will make your code look a lot cleaner, as it will allow us to say something like "Type.FOREST", instead of "BiomeDictionary.Type.FOREST". I'm not going to get into the details of how Java enums work in this tutorial, as it shouldn't be necessary for you to fully understand then to use BiomeDictionary. If you're interested in learning more about them, a quick google search should bring up relevant information.
How To Register a Biome Manually
You should first of all note that BiomeDictionary can automatically register a biome when a mod requests information on it using a pre-defined rule system (see BiomeDictionary.makeBestGuess() for details). However, in some cases, particularly unusual biomes will not be classified correctly, and you should register them manually. This is very simple to do:
BiomeGenBase theBiome = new BiomeGenSpecial(theBiomeID);
GameRegistry.addBiome(theBiome);
BiomeDictionary.registerBiomeType(theBiome, Type.MOUNTAIN, Type.WASTELAND);
You should already be familiar with the first two lines, which are just creating and registering the biome using FML. The third line is registering the biome in BiomeDictionary with two tags, MOUNTAIN, and WASTELAND. The first parameter of BiomeDictionary.registerBiomeType the BiomeGenBase instance representing the biome you wish to register, and all subsequent parameters (you can give as many as you want) are of type BiomeDictionary.Type, and these are the types you want to register the biome as. For maximum compatibility with mob mods, you should do this within your mod's load() method. It's also very important that you register your biome with BiomeDictionary after you've registered it with FML, as BiomeDictionary requires that a biome is in the master biome list in BiomeGenBase before it can be registered with BiomeDictionary.
For reference, here's the enum that defines all the biome types:
public enum Type
{
FOREST,
PLAINS,
MOUNTAIN,
HILLS,
SWAMP,
WATER,
DESERT,
FROZEN,
JUNGLE,
WASTELAND,
BEACH,
NETHER,
END,
MUSHROOM,
MAGICAL;
}
Of these tags, HILLS, WASTELAND, BEACH, NETHER, END, MUSHROOM, and MAGICAL, will never be automatically assigned to a biome, so if one of these applies to your biome, you should manually register it. It should also be noted, that if a biome is registered manually with any tag, automatic registration will not be attempted, so if you do register manually, you must register it will all relevant tags. Finally, you should never register vanilla biomes, as BiomeDictionary has automatic manual registrations for all of them.
How To Use BiomeDictionary for World Generation
Being able to restrict world generation based on biome, yet still support all biome mods without a huge amount of extra work is the reason BiomeDictionary was written in the first place. As a few amazing mods such as Forestry have done, you could look at the properties of the biome yourself, however, this is difficult if you don't know a huge amount about biomes, and most people tend to just support vanilla biomes for that reason. BiomeDictionary takes care of all of that for you, and you just have to ask it if the biome you're trying to generate in has specific tags applied to it. When you request information about a biome, if it has not already been registered with BiomeDictionary, BiomeDictionary will automatically classify it for you. Because this only has to happen once per biome, it isn't very costly at all to do this at world generation time.
I'm going to assume in this section that you already have a world generator (class that implements FML's IWorldGenerator) that you wish to apply this to, and already know the basics of adding world generation.
You should have a method that looks something like this:
@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
//World generation code
}
The first thing you have to do is get the x and z coordinates of some block in the chunk you're generating in. The easiest way to do this is:
int x = chunkX * 16;
int z = chunkZ * 16;
This will give you the coordinates of the block at x = 0, z = 0, relative to the chunk.
Now, you need to get the biome at that position:
The code in the true branch of that if statement will only execute if that biome is of type FOREST. Keep in mind that biomes can have multiple types, so if you want, you can use &&, ||, and ! to check for any combination you want. For instance, you may want to check if a biome is not FROZEN, is both FOREST and MOUNTAIN, or is either SWAMP or WASTELAND. For a complete listing of the available tags, see either the previous section, or BiomeDictionary.Type
To summarize, here's the final code for this method:
@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
int x = chunkX * 16;
int z = chunkZ * 16;
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(x, z);
if(BiomeDictionary.isBiomeOfType(biome, Type.FOREST))
{
//World generation code
}
}
And that's all you have to do. It's just as easy as restricting your world generation based on a vanilla biome, but using BiomeDictionary will make your world generation compatible with any biome mod your users might install. Plus you'll find that the tags available are very similar to the vanilla biomes.
Mob Spawning Using BiomeDictionary
First of all, I want to apologize if anything I say in this section isn't quite correct. I'm not as familiar with how mob spawning works as I am with world generation and biomes, so please feel free to correct me if I make a mistake.
As with world generation, BiomeDictionary will make it much easier to support all biome mods when adding mobs that have their spawn restricted by biome. In this tutorial, I assume that you already have a mob, and know the basics of how to register it to spawn in a specific biome.
First of all, while you can do any initialization of your mobs in your mod's load() method, actually using BiomeDictionary to register them for biomes that have a specific tag applied to them must be done in your mod's postInit() method. This is to ensure that all biomes have already been registered in the master biome list using FML.
The first thing you have to do within postInit() is add the following line of code
BiomeDictionary.registerAllBiomes();
This method only needs to be called once within postInit() (and shouldn't be called anywhere else in your code). All it does is loop through the master biome list in BiomeGenBase, and automatically register any biomes that were not manually registered with BiomeDictionary by their creators. Even if your mod is not the first to call it, you don't have to worry, as the method will just loop through all the biomes, and not do anything if the method has already been called. Since there are a maximum of 256 biomes, this isn't going to be that costly while the game is loading.
Now that you've done that, you want to get a list of all the biomes that have the tag you're interested in applied to them. You do this as follows:
At this point, you can simply loop through the list and register your mobs to spawn in that biome as you normally would.
SpawnListEntry ocelotSpawn = new SpawnListEntry(EntityOcelot.class, 2, 1, 1);
for(int i = 0; i < biomes.length; i++)
{
biomes[i].getSpawnableList(EnumCreatureType.monster).add(ocelotSpawn);
}
This example adds vanilla ocelots to all biomes registered as FROZEN. However, there are a few problems. First of all, what if you want to spawn the mob only in biomes that are both FROZEN and FOREST. Easy:
SpawnListEntry ocelotSpawn = new SpawnListEntry(EntityOcelot.class, 2, 1, 1);
for(int i = 0; i < biomes.length; i++)
{
if(BiomeDictionary.isBiomeOfType(biomes[i], Type.FOREST))
{
biomes[i].getSpawnableList(EnumCreatureType.monster).add(ocelotSpawn);
}
}
As I explained in the world generation section, you can use BiomeDictionary.isBiomeOfType() to check if an individual biome has a specific tag applied to it. You can of course, use &&, ||, and ! to create any combination you want. If you want to add it to biomes of one tag, or another, you should check before adding to the second tag (and any subsequent tags) to make sure it does not also have the first tag applied to it to avoid duplicate entries.
To see the full list of available tags, either look in the section on manual biome registration, or look at BiomeDictionary.Type.
Feel free to ask any questions, or point out any mistakes I've made.
Can you provide more information about what kind of biomes get registered in what categories? Specifically, how do the various vanilla biomes get registered, and what gets registered as "Mountains"?
I'm not actually doing coding / moding, but working with a mod's config and trying to find the biome dictionary equivalent of the "Extreme hills", without triggering on every type of hill
(In regard to a mod that gives realistic animal genetics):
Would you really rather have bees that make diamonds and oil with magical genetic blocks?
... did I really ask that?
As you can see, extreme hills is registered as MOUNTAIN and only MOUNTAIN.
As for biomes added by mods, biomes can either have tags registered manually by a mod author, or they are registered automatically by Forge during postinit if they have not been registered manually. Different mod authors might interpret the tags differently, but in most cases, biomes will be registered in the same way as the closest vanilla biome.
For reference, this is the code that does the automatic registration:
(In regard to a mod that gives realistic animal genetics):
Would you really rather have bees that make diamonds and oil with magical genetic blocks?
... did I really ask that?
Is there a list of which biomes have which tags. or a way to see this? I'm looking to find out which biomes in various mods count as Magical (for Mana Bean farming purposes).
Rollback Post to RevisionRollBack
~~~~~~~~
Fall into the hands of sorrow
Drawn by the darkest bay
Walk into the pit of silence
I am the one calling your name
~~~~~~~~
this may be a bit out of place, but what if I wanted to return a list of all registered Biomes / loaded biomes.. mods and vanilla. I want all data on the biome like name and id.
Edit: Never mind I figured out Biomelist has what I need.. Sorry to answer my own question..
Rollback Post to RevisionRollBack
Like the mods I make? Consider supporting me on Patreon or PayPal
(In regard to a mod that gives realistic animal genetics):
Would you really rather have bees that make diamonds and oil with magical genetic blocks?
... did I really ask that?
The Forge BiomeDictionary contains a set of tools that make it easier to support modded biomes in mods that add biome specific world gen, or mobs. It does this by assigning tags to biomes (such as FOREST) based on their properties (temperature, height, number of trees, etc.). This tutorial will cover how to register biomes you've created, manually, how to check if a biome has specific tags (for world generation), or get a list of all biomes with a specific tag (for mobs). I will assume that you already know how create a biome, a world generator, or a mob, depending on which section of the tutorial you're interested in.
Imports
To use BiomeDictionary, you must import the following:
You should already understand what the first line does if you're at all familiar with Java, however, the second line may need some explanation. import static allows you to import a specific public field in a class in such a way that you can reference it directly, without referring to the class that contains it. In this case, we are using an import static on the enum which contains the different tags defined by BiomeDictionary. This will make your code look a lot cleaner, as it will allow us to say something like "Type.FOREST", instead of "BiomeDictionary.Type.FOREST". I'm not going to get into the details of how Java enums work in this tutorial, as it shouldn't be necessary for you to fully understand then to use BiomeDictionary. If you're interested in learning more about them, a quick google search should bring up relevant information.
How To Register a Biome Manually
You should first of all note that BiomeDictionary can automatically register a biome when a mod requests information on it using a pre-defined rule system (see BiomeDictionary.makeBestGuess() for details). However, in some cases, particularly unusual biomes will not be classified correctly, and you should register them manually. This is very simple to do:
You should already be familiar with the first two lines, which are just creating and registering the biome using FML. The third line is registering the biome in BiomeDictionary with two tags, MOUNTAIN, and WASTELAND. The first parameter of BiomeDictionary.registerBiomeType the BiomeGenBase instance representing the biome you wish to register, and all subsequent parameters (you can give as many as you want) are of type BiomeDictionary.Type, and these are the types you want to register the biome as. For maximum compatibility with mob mods, you should do this within your mod's load() method. It's also very important that you register your biome with BiomeDictionary after you've registered it with FML, as BiomeDictionary requires that a biome is in the master biome list in BiomeGenBase before it can be registered with BiomeDictionary.
For reference, here's the enum that defines all the biome types:
Of these tags, HILLS, WASTELAND, BEACH, NETHER, END, MUSHROOM, and MAGICAL, will never be automatically assigned to a biome, so if one of these applies to your biome, you should manually register it. It should also be noted, that if a biome is registered manually with any tag, automatic registration will not be attempted, so if you do register manually, you must register it will all relevant tags. Finally, you should never register vanilla biomes, as BiomeDictionary has automatic manual registrations for all of them.
How To Use BiomeDictionary for World Generation
Being able to restrict world generation based on biome, yet still support all biome mods without a huge amount of extra work is the reason BiomeDictionary was written in the first place. As a few amazing mods such as Forestry have done, you could look at the properties of the biome yourself, however, this is difficult if you don't know a huge amount about biomes, and most people tend to just support vanilla biomes for that reason. BiomeDictionary takes care of all of that for you, and you just have to ask it if the biome you're trying to generate in has specific tags applied to it. When you request information about a biome, if it has not already been registered with BiomeDictionary, BiomeDictionary will automatically classify it for you. Because this only has to happen once per biome, it isn't very costly at all to do this at world generation time.
I'm going to assume in this section that you already have a world generator (class that implements FML's IWorldGenerator) that you wish to apply this to, and already know the basics of adding world generation.
You should have a method that looks something like this:
The first thing you have to do is get the x and z coordinates of some block in the chunk you're generating in. The easiest way to do this is:
This will give you the coordinates of the block at x = 0, z = 0, relative to the chunk.
Now, you need to get the biome at that position:
And finally, you'll need to check to see if the biome is of the type you want to generate in:
The code in the true branch of that if statement will only execute if that biome is of type FOREST. Keep in mind that biomes can have multiple types, so if you want, you can use &&, ||, and ! to check for any combination you want. For instance, you may want to check if a biome is not FROZEN, is both FOREST and MOUNTAIN, or is either SWAMP or WASTELAND. For a complete listing of the available tags, see either the previous section, or BiomeDictionary.Type
To summarize, here's the final code for this method:
And that's all you have to do. It's just as easy as restricting your world generation based on a vanilla biome, but using BiomeDictionary will make your world generation compatible with any biome mod your users might install. Plus you'll find that the tags available are very similar to the vanilla biomes.
Mob Spawning Using BiomeDictionary
First of all, I want to apologize if anything I say in this section isn't quite correct. I'm not as familiar with how mob spawning works as I am with world generation and biomes, so please feel free to correct me if I make a mistake.
As with world generation, BiomeDictionary will make it much easier to support all biome mods when adding mobs that have their spawn restricted by biome. In this tutorial, I assume that you already have a mob, and know the basics of how to register it to spawn in a specific biome.
First of all, while you can do any initialization of your mobs in your mod's load() method, actually using BiomeDictionary to register them for biomes that have a specific tag applied to them must be done in your mod's postInit() method. This is to ensure that all biomes have already been registered in the master biome list using FML.
The first thing you have to do within postInit() is add the following line of code
This method only needs to be called once within postInit() (and shouldn't be called anywhere else in your code). All it does is loop through the master biome list in BiomeGenBase, and automatically register any biomes that were not manually registered with BiomeDictionary by their creators. Even if your mod is not the first to call it, you don't have to worry, as the method will just loop through all the biomes, and not do anything if the method has already been called. Since there are a maximum of 256 biomes, this isn't going to be that costly while the game is loading.
Now that you've done that, you want to get a list of all the biomes that have the tag you're interested in applied to them. You do this as follows:
At this point, you can simply loop through the list and register your mobs to spawn in that biome as you normally would.
This example adds vanilla ocelots to all biomes registered as FROZEN. However, there are a few problems. First of all, what if you want to spawn the mob only in biomes that are both FROZEN and FOREST. Easy:
As I explained in the world generation section, you can use BiomeDictionary.isBiomeOfType() to check if an individual biome has a specific tag applied to it. You can of course, use &&, ||, and ! to create any combination you want. If you want to add it to biomes of one tag, or another, you should check before adding to the second tag (and any subsequent tags) to make sure it does not also have the first tag applied to it to avoid duplicate entries.
To see the full list of available tags, either look in the section on manual biome registration, or look at BiomeDictionary.Type.
Feel free to ask any questions, or point out any mistakes I've made.
Also: GasCraft, and Defense.
I'm not actually doing coding / moding, but working with a mod's config and trying to find the biome dictionary equivalent of the "Extreme hills", without triggering on every type of hill
* Promoting this week: Captive Minecraft 4, Winter Realm. Aka: Vertical Vanilla Viewing. Clicky!
* My channel with Mystcraft, and general Minecraft Let's Plays: http://www.youtube.com/user/Keybounce.
* See all my video series: http://www.minecraftforum.net/forums/minecraft-editions/minecraft-editions-show-your/2865421-keybounces-list-of-creation-threads
(In regard to a mod that gives realistic animal genetics):
Would you really rather have bees that make diamonds and oil with magical genetic blocks?
... did I really ask that?
As you can see, extreme hills is registered as MOUNTAIN and only MOUNTAIN.
As for biomes added by mods, biomes can either have tags registered manually by a mod author, or they are registered automatically by Forge during postinit if they have not been registered manually. Different mod authors might interpret the tags differently, but in most cases, biomes will be registered in the same way as the closest vanilla biome.
For reference, this is the code that does the automatic registration:
The rest of the code can be found here: https://github.com/MinecraftForge/MinecraftForge/blob/master/common/net/minecraftforge/common/BiomeDictionary.java
Also: GasCraft, and Defense.
More than one tag per biome?!? YEISH, that explains a bit ...
EDIT:
Does that mean "Max height over 96 == mountain"?
* Promoting this week: Captive Minecraft 4, Winter Realm. Aka: Vertical Vanilla Viewing. Clicky!
* My channel with Mystcraft, and general Minecraft Let's Plays: http://www.youtube.com/user/Keybounce.
* See all my video series: http://www.minecraftforum.net/forums/minecraft-editions/minecraft-editions-show-your/2865421-keybounces-list-of-creation-threads
(In regard to a mod that gives realistic animal genetics):
Would you really rather have bees that make diamonds and oil with magical genetic blocks?
... did I really ask that?
~~~~~~~~
Fall into the hands of sorrow
Drawn by the darkest bay
Walk into the pit of silence
I am the one calling your name
~~~~~~~~
BiomeDictionary.registerBiomeType(this);
...doesn't seem to work, I get plains mobs spawning when they should be not.
Edit: Never mind I figured out Biomelist has what I need.. Sorry to answer my own question..
The code segment shown above for auto registration is way out of date.
The current code can be found at
https://raw.githubusercontent.com/MinecraftForge/MinecraftForge/master/src/main/java/net/minecraftforge/common/BiomeDictionary.java
* Promoting this week: Captive Minecraft 4, Winter Realm. Aka: Vertical Vanilla Viewing. Clicky!
* My channel with Mystcraft, and general Minecraft Let's Plays: http://www.youtube.com/user/Keybounce.
* See all my video series: http://www.minecraftforum.net/forums/minecraft-editions/minecraft-editions-show-your/2865421-keybounces-list-of-creation-threads
(In regard to a mod that gives realistic animal genetics):
Would you really rather have bees that make diamonds and oil with magical genetic blocks?
... did I really ask that?
IIRC, 8 is the general default for most monsters. So, 2 makes the ocelot fairly rare, which we know to be true.