-3

So Minecraft uses procedural meshes, how do they address a specific block? How can they separate a stone block from a dirt block?

Minecraft is just an example. I want to now how it works technically.

MrLore
  • 3,759
  • 2
  • 28
  • 36

2 Answers2

2

If you are talking about the block models, as in how the textures are layered over them, Minecraft uses a .json file as a model as of the newest Minecraft version, 1.8. An example of the .json file is as follows:

{
    "ambientocclusion": false,
    "textures": {
        "particle": "blocks/glass",
        "glass": "blocks/glass",
        "obsidian": "blocks/obsidian",
        "beacon": "blocks/beacon"
    },
    "elements": [
        {   "__comment": "Glass shell",
            "from": [ 0, 0, 0 ],
            "to": [ 16, 16, 16 ],
            "faces": {
                "down":  { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" },
                "up":    { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" },
                "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" },
                "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" },
                "west":  { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" },
                "east":  { "uv": [ 0, 0, 16, 16 ], "texture": "#glass" }
            }
        },
        {   "__comment": "Obsidian base",
            "from": [ 2, 0.1, 2 ],
            "to": [ 14, 3, 14 ],
            "faces": {
                "down":  { "uv": [ 2,  2, 14, 14 ], "texture": "#obsidian" },
                "up":    { "uv": [ 2,  2, 14, 14 ], "texture": "#obsidian" },
                "north": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" },
                "south": { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" },
                "west":  { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" },
                "east":  { "uv": [ 2, 13, 14, 16 ], "texture": "#obsidian" }
            }
        },
        {   "__comment": "Inner beacon texture",
            "from": [ 3, 3, 3 ],
            "to": [ 13, 14, 13 ],
            "faces": {
                "down":  { "uv": [ 3, 3, 13, 13 ], "texture": "#beacon" },
                "up":    { "uv": [ 3, 3, 13, 13 ], "texture": "#beacon" },
                "north": { "uv": [ 3, 2, 13, 13 ], "texture": "#beacon" },
                "south": { "uv": [ 3, 2, 13, 13 ], "texture": "#beacon" },
                "west":  { "uv": [ 3, 2, 13, 13 ], "texture": "#beacon" },
                "east":  { "uv": [ 3, 2, 13, 13 ], "texture": "#beacon" }
            }
        }
    ]
}

All blocks models are made in files like this that can be modified by the player. The game then goes in and reads them, creating the models from the .json data. There are several 3rd party programs that assist in making of these files.

If you are interested in seeing how the .json file is read, a great program for decompiling Minecraft is the Minecraft Coder Pack, another 3rd party program.

James Taylor
  • 6,158
  • 8
  • 48
  • 74
PjRock
  • 88
  • 6
0

Well, if you want to see how Minecraft distinguishes a stone block, from a dirt block, for example, they do it like so:

  1. The actual blocks themselves are stored in a big class called Blocks (https://pastebin.com/ykjkBmxv), which are then registered, then if Minecraft wants to check what block you are looking at, it can just cast a raycast from the player towards the block, then Minecraft checks the loaded chunk data, to find the block at the position.
  2. Minecraft also has .json files for configuring how the block looks, which look like so:
{
    "parent": "block/cube_all",
    "textures": {
        "all": "blocks/dirt"
    }
}

Minecraft also has blockstate .json files, which are used to define variants of a block, for example, a saplings growth states.

Rohan
  • 5
  • 2