How does Minecraft generate it's texture (ex. which block is grass and which one is stone)?
-
now it sounds like you're asking how textures are made. Can you be more specific? Are you asking how Textures are linked to block types? As in applying a texture on block? Or do you want know how textures are made? Your title doesn't match your question either. – Sidar Jul 09 '13 at 02:01
-
I need to know how to generate the IDs for each block to make it be a certain material. – Spynaz Jul 09 '13 at 02:13
-
So do you actually have a basic procedural generation algorithm? – Sidar Jul 09 '13 at 03:57
-
I already have 2d perlin noise height map with 3d perlin noise to make the map better. But right now it just generates the whole map out of stone. – Spynaz Jul 09 '13 at 05:22
-
It should also be noted that you can get the source code for Minecraft directly from Mojang. – UnderscoreZero Jul 09 '13 at 16:56
-
Why does it matter? What problem does are you trying to solve? Please include that in your question. Otherwise, it's off-topic, because "how does game X do Y" is considered off-topic: http://meta.gamedev.stackexchange.com/questions/1063/why-should-how-was-the-technique-in-x-done-be-considered-off-topic – Jul 24 '13 at 16:05
2 Answers
It's a texture atlas. Each block has a particular type. The code then takes the type, the face index (top, side, etc.) and finds an index into a texture atlas (which is basically just the theme file).
The triangles are then generated using the UVs from that atlas. For instance, if grass is at (128,64)
in a texture sized (256,256)
then the UV coordinate is (0.5,0.25)
. This coordinate and the per-tile size (0.25,0.25)
in that made-up example are used to texture the four corners of that face of the block. The face's vertices are generated relative to the block's location, the UVs are slapped on, normals are output, and the vertices are stuffed into a cached mesh for later rendering.
Similar techniques are used in 2D, both for tiled and non-tiled games, and to some extent in more traditional 3D engines.

- 41,807
- 4
- 89
- 132
-
Um....I still don't get how it decides what material a certain block is. – Spynaz Jul 09 '13 at 00:58
-
@Spynaz each block has an ID which dictates the type ( grass, ground, lava, etc ) These ID's can actually be used to identify the region of a texture atlas. The Minecraft textures are actually very small and then blown out of proportion. Hence the reason why it's all so pixelated. – Sidar Jul 09 '13 at 01:09
-
@Sidar, Yes I know that each block has an ID. But how do I generate those IDs so that caves will be stone and hills can be grass and etc.? – Spynaz Jul 09 '13 at 01:23
-
2Aah, that is a very different question than how I interpreted your question since you asked about "rendering" rather than "generation." You should refine your question to ask about "procedural world generation," and make sure that question isn't already on the site (I'd be surprised if it wasn't). – Sean Middleditch Jul 09 '13 at 01:41
-
@Spynaz that depends on your tooling and datastructure. You just need link ID's to texture mapping. Just keep in mind that your block ID will also be useful for other things. It's best to keep them as abstract as possible. Well just read Seans second comment, I'm not entirely sure what you're asking now. – Sidar Jul 09 '13 at 01:41
-
The simple answer is : with more perlin noise maps.
First, there are the biome maps. These maps are 2D, and if my memory serves me correct, they represent heat and humidity. Together with the height map, they divide the world in "Biomes"
For instance, areas that are "wet", "low" and "teppid" are swamps,
areas that are "dry", "hot" and "high" are mountains,
areas that are "moist", "hot" and "average" are jungle, etc.
Based on the biomes, minecraft uses a different set of rules for generating its surface world (which trees grow there, etc) and uses a different set of blocks and texture color filter.
Then, there is a 3D noise map built on top of the 2d noise map that determines where the rock starts, and where to spawn ore veins (and of which kind those veins are).
You can read up on an old post Notch made on his blog.
By now, the world generation code of minecraft has changed a lot, and a bunch of it probably no longer applies though.

- 374
- 1
- 11
-
(do keep in mind that if you use the same seed to generate all these maps, you end up with something that doesn't work, or doesn't seem right. you'll probably need to offset the seeds from each other) – Timothy Groote Jul 09 '13 at 09:48