Minecraft Modding: Dimensions, WorldGen, Biomes, Trees

Definitions: Dimension, World, Chunk, Biome

Each of the "Overworld", the "Nether", and the "End" are called "dimensions".

Key Point: In terms of modding, each dimension is run in a separate instance of the World class. This is important as it means that you may have to think carefully if you need certain data across all the dimensions.

Due to the huge size of a world (a 256 by 256 area of the world has 17 million block positions!), the code manages data about the world in "chunks", saving them and loading them as needed. This is the reason for Minecraft's recognizable way that the world in the distance is often missing parts until you get closer. A chunk is 16 x 256 x 16 in size. "Chunk coordinates" are used in various places in the code and refer to x, y, z within the chunk.

Tip: To get chunk coordinates from world coordinates, you can use the modulo operator: chunkX = worldX%16.

When a chunk is loaded for the first time it is generated. This is done with a "chunk provider" that is called from the "world provider". There is a certain degree of randomness used by the code to make things interesting, but there are still "themes" for the area of the world which are called "biomes". These are things like "taiga" and "plains". The biome is used to determine the types of blocks, types of trees, and types of entities to generate.

Biomes consist of a number of chunks, but the shape and size can vary randomly.

Getting A List Of All Biomes

Prior to 1.10.2 the built-in biomeList contains null entries and so it was useful to clean up that list.

Thanks to diesieben07 for this tip. You can get a proper list of all biomes with:

BiomeGenBase[] allBiomes = Iterators.toArray(Iterators.filter(Iterators.forArray(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()), BiomeGenBase.class);

How To Delete A Biome

In earlier versions of Forge there was a GameRegistry.removeBiome() method which no longer exists.  Now you can work directly with the List in the BiomeManager, using normal List methods to remove (or add).

Detecting What Biome Is At A Given Location

If you ever want your code to do something special based on being in a biome, like maybe if you want it to play different background sounds in your custom biome, you can check using the following: worldObj.getChunkFromBlockCoords(blockpos).getBiome(blockpos, worldObj.getWorldChunkManager()).biomeName

Creating Your Own Dimension

See Jimmy04Creeper's Custom Dimensions Tutorial.

Creating An Empty Dimension

You can do this by simply following the steps to make a custom dimension, but in your custom ChunkProvider class @Override the ChunkProvider#provideChunk() method to return an empty chunk.

For example:

public Chunk provideChunk(int parChunkXIndex, int parChunkYIndex)
Chunk chunk = new Chunk(this.worldObj, parChunkXIndex, parChunkYIndex);
return chunk;

Changing How Fast The Day Progresses

You cannot (easily) change the pace of the day in the vanilla because the duration of a day is a fixed value in the WorldProvider#calculateCelestialAngle() method, but you can easily do this in your own dimension. In other words make a custom WorldProvider.

Custom Tree Generation

See Jimmy04Creeper's Custom Trees Tutorial (see second post in thread).

Preventing And Changing Generation Of Decorations (Trees, Cactus, Etc.)

You can handle the DecorateBiomeEvent.decorate event and check for the EventType. If you don't understand how to handle an event, check out Jabelar's Event Handling Tutorial.

Based on the EventType you can do your own thing and use the event.setResult(Result.DENY) to prevent the standard decoration.

Possible EventTypes you can intercept are:

  • CLAY
  • LAKE
  • REED
  • SAND
  • TREE
  • CUSTOM -- it seems this is to allow you to post custom event that can then be handled.

Changing The Contents Of Generated Chests

The ChestGenHooks class has categories BONUS_CHEST and VILLAGE_BLACKSMITH. Register your loot there.

No comments:

Post a Comment