summaryrefslogtreecommitdiffstats
path: root/src/Block.hpp
blob: c922adf5cd1c8643478b8605f5a942b081b50903 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include <functional>
#include <utility>

struct Block {
    Block();
    Block(unsigned short id, unsigned char state,
          unsigned char light, unsigned char sky);
    ~Block();

    unsigned short id : 13;
    unsigned char state : 4;
    unsigned char light : 4;
    unsigned char sky : 4;
};

struct BlockId {
    unsigned short id : 13;
    unsigned char state : 4;
};

enum BlockFacing {
    Bottom = 0,
    Top,
    North,
    South,
    West,
    East
};

bool operator==(const BlockId& lhs, const BlockId &rhs);

bool operator<(const BlockId& lhs, const BlockId &rhs);

namespace std {
    template <>
    struct hash<BlockId> {
        std::size_t operator()(const BlockId& k) const {
            size_t id = std::hash<unsigned short>()(k.id);
            size_t state = std::hash<unsigned char>()(k.state);

            return (id & state << 1);
        }
    };
}

//returns name of blockstate and name of variant
std::pair<std::string, std::string> TransformBlockIdToBlockStateName(BlockId blockId);