-
Notifications
You must be signed in to change notification settings - Fork 8
/
BlockType.h
105 lines (79 loc) · 2.78 KB
/
BlockType.h
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef BLOCK_TYPE_HH
#define BLOCK_TYPE_HH
#include <string>
#include <map>
#include <sstream>
#include <NBTObject.h>
#if 0
// this was an attempt to do a map with block_type as a lookup key. It didn't work. don't know
// why. didn't feel like debugging, but it bugs me that I don't know why it didn't work.
struct cmpPalettes {
bool operator()(const BlockType& a, const BlockType& b) const {
if (a.name != b.name) { return a.name.compare(b.name); }
int c = map_compare(a.byte_properties, b.byte_properties);
if (c != 0) { return c==-1; }
c = map_compare(a.int_properties, b.int_properties);
if (c != 0) { return c==-1; }
c = map_compare(a.string_properties, b.string_properties);
if (c != 0) { return c==-1; }
return false;
}
};
#endif
class BlockType : public NBTObject {
public:
BlockType() : id(-1), count(0), earthly(false), liquid(false), air(false) { /* empty */ };
const std::string &get_name() const { return name; }
bool is_earthly() { return earthly; }
bool is_liquid() { return liquid; }
bool is_air() { return air; }
std::string get_string() const;
std::string lookup_string() const;
void add_byte(std::string tagname, uint8_t value) override {
if (tagname == "infiniburn_bit") {
infiniburn_bit = value;
} else {
NBTObject::add_byte(tagname, value);
}
};
void add_short(std::string tagname, int16_t value) override {
if (tagname == "val") {
// don't know what val is but I have this here to supress the stdout
short_properties[tagname] = value;
} else {
NBTObject::add_short(tagname, value);
}
}
void add_string(std::string tagname, std::string value) override;
void add_int(std::string tagname, int32_t value) override {
if (tagname == "version") {
version = value;
} else if (tagname == "liquid_depth") {
liquid_depth = value;
} else {
NBTObject::add_int(tagname, value);
}
}
void incr_count() { count++; };
static int get_block_type_id(BlockType &bt);
static void add_block_type(BlockType &bt);
static void print_block_types();
static BlockType &get_block_type_by_id(unsigned int id);
static int get_block_type_id_by_name(std::string name);
private:
int id;
int count;
std::string name;
std::string stone_dirt_type;
uint8_t infiniburn_bit;
int version;
int liquid_depth;
// this represents whether this is a solid block type.
// but not just any solid block. one that's part of the ground.
// dirt, stone,...
bool earthly;
bool liquid;
bool air;
};
std::ostream& operator << (std::ostream& o, const BlockType &bt);
#endif