forked from Plethora777/mcpe_viz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcpe_viz.h
361 lines (284 loc) · 8.86 KB
/
mcpe_viz.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*
Minecraft Pocket Edition (MCPE) World File Visualization & Reporting Tool
(c) Plethora777, 2015.9.26
GPL'ed code - see LICENSE
Main classes for mcpe_viz
*/
#ifndef __MCPE_VIZ_H__
#define __MCPE_VIZ_H__
#include <map>
namespace mcpe_viz {
//todozooz - MAX_BLOCK_ID MAX_ITEM_ID etc
const int32_t kColorDefault = 0xff00ff;
// todo ugly globals
extern std::string dirExec;
extern Logger logger;
extern double playerPositionImageX, playerPositionImageY;
extern int32_t playerPositionDimensionId;
extern std::vector<std::string> listGeoJSON;
extern int32_t globalIconImageId;
// dimensions
enum DimensionType : int32_t {
kDimIdOverworld = 0,
kDimIdNether = 1,
kDimIdTheEnd = 2,
// todobig - this is very brittle - consider that add-ons may one day add custome dimensions
kDimIdCount = 3
};
void worldPointToImagePoint(int32_t dimId, double wx, double wz, double &ix, double &iy, bool geoJsonFlag);
void worldPointToGeoJSONPoint(int32_t dimId, double wx, double wz, double &ix, double &iy);
class BlockInfo {
public:
int32_t id;
std::string name;
std::vector<std::string> unameList;
int32_t color;
bool colorSetFlag;
bool solidFlag;
bool opaqueFlag;
bool liquidFlag;
bool spawnableFlag;
int32_t colorSetNeedCount;
int32_t blockdata;
std::vector< std::unique_ptr<BlockInfo> > variantList;
bool valid;
int32_t userVar1;
std::string userString1;
BlockInfo() {
id = -1;
name = "(unknown)";
unameList.clear();
setColor(kColorDefault); // purple
solidFlag = true;
opaqueFlag = true;
liquidFlag = false;
spawnableFlag = true;
colorSetFlag = false;
colorSetNeedCount = 0;
variantList.clear();
valid = false;
userVar1 = 0;
userString1 = "";
}
BlockInfo& setId(int32_t i) {
id = i;
return *this;
}
BlockInfo& setName(const std::string& s) {
name = std::string(s);
valid = true;
return *this;
}
BlockInfo& setUname(const std::string& s) {
unameList = mysplit(s,';');
// todonow - update a dictionary for unames?
return *this;
}
bool isValid() { return valid; }
void setUserVar1(int32_t v) { userVar1 = v; }
void deltaUserVar1(int32_t d) { userVar1 += d; }
int32_t getUserVar1() { return userVar1; }
void setUserString1(const std::string& s) { userString1 = s; }
std::string& getUserString1() { return userString1; }
BlockInfo& setColor(int32_t rgb) {
// note: we convert color storage to big endian so that we can memcpy when creating images
color = htobe32(rgb);
colorSetFlag = true;
return *this;
}
BlockInfo& setSolidFlag(bool f) {
solidFlag = f;
return *this;
}
bool isSolid() { return solidFlag; }
BlockInfo& setOpaqueFlag(bool f) {
opaqueFlag = f;
return *this;
}
bool isOpaque() { return opaqueFlag; }
BlockInfo& setLiquidFlag(bool f) {
liquidFlag = f;
return *this;
}
bool isLiquid() { return liquidFlag; }
BlockInfo& setSpawnableFlag(bool f) {
spawnableFlag = f;
return *this;
}
bool isSpawnable(int32_t bd) {
if (hasVariants()) {
for (const auto& itbv : variantList) {
if ( itbv->blockdata == bd ) {
return itbv->spawnableFlag;
}
}
fprintf(stderr, "WARNING: did not find bd=%d (0x%x) for block='%s'\n", bd, bd, name.c_str());
}
return spawnableFlag;
}
bool hasVariants() {
return (variantList.size() > 0);
}
void setBlockData(int32_t bd) {
blockdata = bd;
}
BlockInfo& addVariant(int32_t bd, const std::string& n) {
std::unique_ptr<BlockInfo> bv(new BlockInfo());
bv->setName(n);
bv->setBlockData(bd);
variantList.push_back( std::move(bv) );
return *(variantList.back());
}
std::string toString() {
char tmpstring[1024];
sprintf(tmpstring,"Block: name=%s color=0x%06x solid=%d opaque=%d liquid=%d spawnable=%d"
, name.c_str()
, color
, (int)solidFlag
, (int)opaqueFlag
, (int)liquidFlag
, (int)spawnableFlag
);
// todo variants?
return std::string(tmpstring);
}
};
extern BlockInfo blockInfoList[512];
//BlockInfo* getBlockInfo(int32_t id, int32_t blockData);
std::string getBlockName(int32_t id, int32_t blockdata);
int32_t getBlockByUname(const std::string& uname, int32_t& blockId, int32_t& blockData);
class ItemInfo {
public:
std::string name;
std::vector<std::string> unameList;
int32_t extraData;
std::vector< std::unique_ptr<ItemInfo> > variantList;
int32_t userVar1;
std::string userString1;
ItemInfo(const char* n, const char* un) {
setName(n);
setUname(un);
extraData = 0;
variantList.clear();
userVar1 = 0;
userString1 = "";
}
ItemInfo& setName (const std::string& s) {
name = std::string(s);
return *this;
}
ItemInfo& setUname (const std::string& un) {
unameList = mysplit(un,';');
// todonow - update a dictionary for unames?
return *this;
}
void setUserVar1(int32_t v) { userVar1 = v; }
void deltaUserVar1(int32_t d) { userVar1 += d; }
int32_t getUserVar1() { return userVar1; }
void setUserString1(const std::string& s) { userString1 = s; }
std::string& getUserString1() { return userString1; }
bool hasVariants() {
return (variantList.size() > 0);
}
void setExtraData(int32_t ed) {
extraData = ed;
}
ItemInfo& addVariant(int32_t ed, const std::string& n, const std::string& un) {
std::unique_ptr<ItemInfo> iv(new ItemInfo(n.c_str(), un.c_str()));
iv->setExtraData(ed);
variantList.push_back( std::move(iv) );
return *(variantList.back());
}
};
typedef std::map<int, std::unique_ptr<ItemInfo> > ItemInfoList;
extern ItemInfoList itemInfoList;
bool has_key(const ItemInfoList &m, int32_t k);
std::string getItemName(int32_t id, int32_t extraData, bool nameBasedFlag);
class EntityInfo {
public:
std::string name;
std::vector<std::string> unameList;
std::string etype;
EntityInfo(const std::string& n, const std::string& un, const std::string& e ) {
setName(n);
setUname(un);
setEtype(e);
}
EntityInfo& setName (const std::string& s) {
name = std::string(s);
return *this;
}
EntityInfo& setUname (const std::string& s) {
unameList = mysplit(s,';');
return *this;
}
EntityInfo& setEtype (const std::string& e) {
etype = std::string(e);
return *this;
}
};
typedef std::map<int, std::unique_ptr<EntityInfo> > EntityInfoList;
extern EntityInfoList entityInfoList;
bool has_key(const EntityInfoList &m, int32_t k);
int32_t findEntityByUname(const EntityInfoList &m, std::string& un);
int32_t findIdByItemName(std::string& uname);
int32_t findIdByBlockName(std::string& uname);
class BiomeInfo {
public:
std::string name;
int32_t color;
bool colorSetFlag;
BiomeInfo(const char* n) {
setName(n);
setColor(kColorDefault);
colorSetFlag = false;
}
BiomeInfo(const char* n, int32_t rgb) {
setName(n);
setColor(rgb);
}
BiomeInfo& setName (const std::string& s) {
name = std::string(s);
return *this;
}
BiomeInfo& setColor(int32_t rgb) {
// note: we convert color storage to big endian so that we can memcpy when creating images
color = htobe32(rgb);
colorSetFlag=true;
return *this;
}
};
typedef std::map<int, std::unique_ptr<BiomeInfo> > BiomeInfoList;
extern BiomeInfoList biomeInfoList;
bool has_key(const BiomeInfoList &m, int32_t k);
class EnchantmentInfo {
public:
std::string name;
std::string officialName;
EnchantmentInfo(const char* n) {
setName(n);
officialName="";
}
EnchantmentInfo& setName (const std::string& s) {
name = std::string(s);
return *this;
}
EnchantmentInfo& setOfficialName (const std::string& s) {
officialName = std::string(s);
return *this;
}
};
typedef std::map<int, std::unique_ptr<EnchantmentInfo> > EnchantmentInfoList;
extern EnchantmentInfoList enchantmentInfoList;
bool has_key(const EnchantmentInfoList &m, int32_t k);
typedef std::map<int32_t, int32_t> IntIntMap;
extern IntIntMap mcpcToMcpeBlock;
extern IntIntMap mcpeToMcpcBlock;
extern IntIntMap mcpcToMcpeItem;
extern IntIntMap mcpeToMcpcItem;
bool has_key(const IntIntMap &m, int32_t k);
typedef std::map<std::string, int32_t> StringIntMap;
extern StringIntMap imageFileMap;
bool has_key(const StringIntMap &m, const std::string& k);
} // namespace mcpe_viz
#endif // __MCPE_VIZ_H__