feat: add dirt and stone

This commit is contained in:
2026-04-16 15:05:52 +08:00
parent 6362536daa
commit cf9aaa62a7
20 changed files with 23 additions and 8 deletions

View File

@@ -6,6 +6,13 @@
std::unordered_map<unsigned, std::string> MapTable::id_to_name_map;
std::unordered_map<size_t, unsigned> MapTable::name_to_id_map;
constexpr std::array<std::string, MAX_BLOCK_NUM> BLOCK_REISTER{
"air",
"grass_block",
"dirt",
"stone"
};
const std::string& MapTable::get_name_from_id(unsigned id) {
auto it = id_to_name_map.find(id);
@@ -17,13 +24,16 @@ const unsigned MapTable::get_id_from_name(const std::string& name) {
CUBED_ASSERT_MSG(it != name_to_id_map.end(), "Name " + name + " is not exist");
return it->second;
}
void MapTable::init_map() {
id_to_name_map.reserve(MAX_BLOCK_NUM);
name_to_id_map.reserve(MAX_BLOCK_NUM);
id_to_name_map[0] = "air";
name_to_id_map[HASH::str("air")] = 0;
id_to_name_map[1] = "grass_block";
name_to_id_map[HASH::str("grass_block")] = 1;
for (int i = 0; i < MAX_BLOCK_NUM; i++) {
id_to_name_map[i] = BLOCK_REISTER[i];
name_to_id_map[HASH::str(BLOCK_REISTER[i])] = i;
}
}