summaryrefslogtreecommitdiffstats
path: root/src/Block.cpp
blob: 41199de2e065e75ef6495efe598222ce8aed6519 (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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "Block.hpp"

#include <string>

Block::~Block() {}

Block::Block(unsigned short id, unsigned char state,
	         unsigned char light, unsigned char sky)
        : id(id), state(state), light(light), sky (sky) {}

Block::Block() : id(0), state(0), light(0), sky(0) {}

bool operator==(const BlockId& lhs, const BlockId &rhs) {
    return (lhs.id == rhs.id) && (lhs.state == rhs.state);
}

bool operator<(const BlockId& lhs, const BlockId &rhs) {
	if (lhs.id < rhs.id)
		return true;
    return lhs.state < rhs.state;
}

std::pair<std::string, std::string> TransformBlockIdToBlockStateName(BlockId blockId) {
	switch (blockId.id) {
	case 1: {
		if (blockId.state > 6)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("stone", "normal"),
			std::pair<std::string,std::string>("granite", "normal"),
			std::pair<std::string,std::string>("smooth_granite", "normal"),
			std::pair<std::string,std::string>("diorite", "normal"),
			std::pair<std::string,std::string>("smooth_diorite", "normal"),
			std::pair<std::string,std::string>("andesite", "normal"),
			std::pair<std::string,std::string>("smooth_andesite", "normal"),
		};
		return ids[blockId.state];
	}
	case 2: {
		return std::make_pair("grass", "snowy=false");
	}
	case 3: {
		if (blockId.state > 1)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("dirt", "normal"),
			std::pair<std::string,std::string>("coarse_dirt", "normal"),
		};
		return ids[blockId.state];
	}
	case 4: {
		return std::make_pair("cobblestone", "normal");
	}
	case 5: {
		if (blockId.state > 5)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("oak_planks", "normal"),
			std::pair<std::string,std::string>("spruce_planks", "normal"),
			std::pair<std::string,std::string>("birch_panks", "normal"),
			std::pair<std::string,std::string>("jungle_planks", "normal"),
			std::pair<std::string,std::string>("acacia_planks", "normal"),
			std::pair<std::string,std::string>("dark_oak_panks", "normal"),
		};
		return ids[blockId.state];
	}
	case 12: {
		if (blockId.state > 1)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("sand", "normal"),
			std::pair<std::string,std::string>("red_sand", "normal"),
		};
		return ids[blockId.state];
	}
	case 17: {
		unsigned char type = blockId.state & 0x3;
		unsigned char dir = (blockId.state & 0xC) >> 2;
		static const std::string types[] = {
			"oak_log",
			"spruce_log",
			"birch_log",
			"jungle_log",
		};
		static const std::string dirs[] = {
			"axis=y",
			"axis=x",
			"axis=z",
			"axis=none",
		};
		return std::make_pair(types[type], dirs[dir]);
	}
	case 18: {
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("oak_leaves", "normal"),
			std::pair<std::string,std::string>("spruce_leaves", "normal"),
			std::pair<std::string,std::string>("birch_leaves", "normal"),
			std::pair<std::string,std::string>("jungle_leaves", "normal"),
		};
		return ids[blockId.state & 0x3];
	}
	case 31: {
		if (blockId.state > 2)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("dead_bush", "normal"),
			std::pair<std::string,std::string>("tall_grass", "normal"),
			std::pair<std::string,std::string>("fern", "normal"),
		};
		return ids[blockId.state];
	}
	case 35: {
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("white_wool", "normal"),
			std::pair<std::string,std::string>("orange_wool", "normal"),
			std::pair<std::string,std::string>("magenta_wool", "normal"),
			std::pair<std::string,std::string>("light_blue_wool", "normal"),
			std::pair<std::string,std::string>("yellow_wool", "normal"),
			std::pair<std::string,std::string>("lime_wool", "normal"),
			std::pair<std::string,std::string>("pink_wool", "normal"),
			std::pair<std::string,std::string>("gray_wool", "normal"),
			std::pair<std::string,std::string>("light_gray_wool", "normal"),
			std::pair<std::string,std::string>("cyan_wool", "normal"),
			std::pair<std::string,std::string>("purple_wool", "normal"),
			std::pair<std::string,std::string>("blue_wool", "normal"),
			std::pair<std::string,std::string>("green_wool", "normal"),
			std::pair<std::string,std::string>("red_wool", "normal"),
			std::pair<std::string,std::string>("black_wool", "normal"),
		};
		return ids[blockId.state];
	}
	case 37: {
		return std::make_pair("dandelion", "normal");
	}
	case 38: {
		if (blockId.state > 8)
			break;
		static const std::pair<std::string, std::string> ids[] = {
			std::pair<std::string,std::string>("poppy", "normal"),
			std::pair<std::string,std::string>("blue_orchid", "normal"),
			std::pair<std::string,std::string>("allium", "normal"),
			std::pair<std::string,std::string>("Azure Bluet", "normal"),
			std::pair<std::string,std::string>("red_tulip", "normal"),
			std::pair<std::string,std::string>("orange_tulip", "normal"),
			std::pair<std::string,std::string>("white_tulip", "normal"),
			std::pair<std::string,std::string>("pink_tulip", "normal"),
			std::pair<std::string,std::string>("oxeye_daisy", "normal"),	
		};
		return ids[blockId.state];
	}
	case 175: {
		bool high = ((blockId.state >> 3) & 0x1);
		unsigned char type = blockId.state & 0x7;

		static const std::string types[] = {
			"sunflower",
			"Lilac",
			"double_grass",
			"double_fern",
			"double_rose",
			"Peony",
		};

		static const std::string isHigh[] = {
			"half=lower",
			"half=upper",
		};
		return std::make_pair(types[type], isHigh[high]);
	}
	default:
		break;
	}
	
	return std::make_pair("", "");
}