CubicMC/cubic-server

BlockStates code generation

emneo-dev opened this issue · 2 comments

We need to generate some code to translate protocol ids to internal structures and vice versa, something like this :

#include <cstdint>
#include <unordered_map>
#include <string>

using namespace std;

enum class Blocks {
    MINECRAFT_ACACIA_PRESSURE_PLATE,
};

struct Block {
    Blocks type;
    SomeMapType properties;
    constexpr string toName() const {
        switch (this->type) {
        case Blocks::MINECRAFT_ACACIA_PRESSURE_PLATE:
            return "minecraft:acacia_pressure_plate";
        }
    }

    constexpr uint64_t toProtocol() const {
        switch (this->type) {
        case Blocks::MINECRAFT_ACACIA_PRESSURE_PLATE:
            if constexpr (this->properties == SomeMapType({
                {"powered", "true"}
                }))
                return 4186;
            if constexpr (this->properties == SomeMapType({
                {"powered", "false"}
                }))
                return 4187;
        }
    }
};

// "minecraft:acacia_pressure_plate": {
//     "properties": {
//       "powered": [
//         "true",
//         "false"
//       ]
//     },
//     "states": [
//       {
//         "id": 4186,
//         "properties": {
//           "powered": "true"
//         }
//       },
//       {
//         "default": true,
//         "id": 4187,
//         "properties": {
//           "powered": "false"
//         }
//       }
//     ]
//   },

Should be done next sprint

We need to have a compile time thing to be more efficient.
For now, it cannot be build because of RAM usage.

please refer to #108 PR for more info / code