Skip to content

Block Name

Bluebotlabz edited this page Jul 2, 2022 · 2 revisions

Each regular block has a static, unchanged name the way in which this is actually quite simple, essentially, there are two main files which matter, the terrain.h and the terrain.cpp

In the terrain.h file, the block IDs are determined by what is set in this file:

typedef uint8_t BLOCK;
typedef uint16_t BLOCK_WDATA;

constexpr BLOCK BLOCK_AIR = 0;
constexpr BLOCK BLOCK_STONE = 1;
constexpr BLOCK BLOCK_DIRT = 2;
constexpr BLOCK BLOCK_SAND = 3;
constexpr BLOCK BLOCK_WOOD = 4;

...

// Regular blocks end here
constexpr BLOCK BLOCK_NORMAL_LAST = BLOCK_CACTUS;

and interestingly enough, the name of a block is determined in a similar way in terrain.cpp:

const char *block_names[BLOCK_NORMAL_LAST + 1] =
{
    "Air",
    "Stone",
    "Dirt",
    "Sand",
    "Wood",
  
    ...

};

You may notice the pattern, basically, the block name is directly determined by the array in terrain.cpp, as you can see, the 0th item in the array Air, corresponds to BLOCK_AIR which is, coincidentially, zero.

So essentially, the item index in the array, directly determiens the name of the block with the same ID

Clone this wiki locally