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
362
363
364
365
366
367
|
#pragma once
#include "BlockID.h"
//tolua_begin
// emissive blocks
extern unsigned char g_BlockLightValue[];
// whether blocks allow spreading
extern unsigned char g_BlockSpreadLightFalloff[];
// whether blocks are transparent (light can shine though)
extern bool g_BlockTransparent[];
// one hit break blocks
extern bool g_BlockOneHitDig[];
//tolua_end
//--DO NOT DELETE THIS COMMENT-- //tolua_export
enum
{
BLOCK_FACE_BOTTOM = 0, // Interacting with the bottom face of the block
BLOCK_FACE_TOP = 1, // Interacting with the top face of the block
BLOCK_FACE_EAST = 2, // Interacting with the eastern face of the block
BLOCK_FACE_WEST = 3, // Interacting with the western face of the block
BLOCK_FACE_NORTH = 4, // Interacting with the northern face of the block
BLOCK_FACE_SOUTH = 5, // Interacting with the southern face of the block
} ;
inline bool IsValidBlock( int a_BlockID ) //tolua_export
{ //tolua_export
if( a_BlockID > -1 &&
a_BlockID <= 126 && //items to 109 are valid for Beta1.8.1.. 1.2.5 is up to 126
//a_BlockID != 29 && allow pistons
//a_BlockID != 33 && allow pistons
a_BlockID != 34 &&
a_BlockID != 36 )
{
return true;
}
return false;
} //tolua_export
// Was old :o
// Changed to fit the style ;)
inline bool IsValidItem( int a_ItemID ) //tolua_export
{ //tolua_export
if( (a_ItemID >= 256 && a_ItemID <= 388)
|| (a_ItemID >= 2256 && a_ItemID <= 2266) )
{
return true;
}
if( a_ItemID == 0 )
return false;
return IsValidBlock( a_ItemID );
} //tolua_export
inline bool IsBlockWater(char a_BlockID)
{
return (a_BlockID == E_BLOCK_WATER || a_BlockID == E_BLOCK_STATIONARY_WATER);
}
inline bool IsBlockLava(char a_BlockID)
{
return (a_BlockID == E_BLOCK_LAVA || a_BlockID == E_BLOCK_STATIONARY_LAVA);
}
inline bool IsBlockLiquid(char a_BlockID)
{
return IsBlockWater(a_BlockID) || IsBlockLava(a_BlockID);
}
inline bool IsBlockTypeOfDirt(char a_BlockID)
{
switch (a_BlockID)
{
case E_BLOCK_DIRT:
case E_BLOCK_GRASS:
case E_BLOCK_FARMLAND:
return true;
}
return false;
}
inline void AddDirection( int & a_X, int & a_Y, int & a_Z, char a_Direction, bool a_bInverse = false )
{
if (!a_bInverse)
{
switch (a_Direction)
{
case BLOCK_FACE_BOTTOM: a_Y--; break;
case BLOCK_FACE_TOP: a_Y++; break;
case BLOCK_FACE_EAST: a_Z--; break;
case BLOCK_FACE_WEST: a_Z++; break;
case BLOCK_FACE_NORTH: a_X--; break;
case BLOCK_FACE_SOUTH: a_X++; break;
default:
{
ASSERT(!"Unknown direction");
break;
}
}
}
else
{
switch( a_Direction ) // other way around
{
case BLOCK_FACE_BOTTOM: a_Y++; break;
case BLOCK_FACE_TOP: a_Y--; break;
case BLOCK_FACE_EAST: a_Z++; break;
case BLOCK_FACE_WEST: a_Z--; break;
case BLOCK_FACE_NORTH: a_X++; break;
case BLOCK_FACE_SOUTH: a_X--; break;
default:
{
ASSERT(!"Unknown direction");
break;
}
}
}
}
inline void AddDirection( int & a_X, unsigned char & a_Y, int & a_Z, char a_Direction, bool a_bInverse = false ) //tolua_export
{//tolua_export
int Y = a_Y;
AddDirection( a_X, Y, a_Z, a_Direction, a_bInverse );
if( Y < 0 ) a_Y = 0;
else if( Y > 255 ) a_Y = 255;
else a_Y = (unsigned char)Y;
}//tolua_export
#include <math.h>
#define PI 3.14159265358979323846264338327950288419716939937510582097494459072381640628620899862803482534211706798f
#define MIN(a,b) (((a)>(b))?(b):(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
inline void EulerToVector( float a_Pan, float a_Pitch, float & a_X, float & a_Y, float & a_Z )
{
// a_X = sinf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
// a_Y = -sinf ( a_Pitch / 180 * PI );
// a_Z = -cosf ( a_Pan / 180 * PI ) * cosf ( a_Pitch / 180 * PI );
a_X = cos(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
a_Y = sin(a_Pan / 180 * PI)*cos(a_Pitch / 180 * PI);
a_Z = sin(a_Pitch / 180 * PI);
}
inline void VectorToEuler( float a_X, float a_Y, float a_Z, float & a_Pan, float & a_Pitch )
{
if( a_X != 0 )
a_Pan = atan2( a_Z, a_X ) * 180 / PI - 90;
else
a_Pan = 0;
a_Pitch = atan2(a_Y, sqrtf((a_X * a_X) + (a_Z * a_Z))) * 180 / PI;
}
inline float GetSignf( float a_Val )
{
return (a_Val < 0.f)?-1.f:1.f;
}
inline float GetSpecialSignf( float a_Val )
{
return (a_Val <= 0.f)?-1.f:1.f;
}
//tolua_begin
namespace ItemCategory
{
inline bool IsPickaxe(ENUM_ITEM_ID a_ItemID)
{
return (a_ItemID == E_ITEM_WOODEN_PICKAXE)
|| (a_ItemID == E_ITEM_STONE_PICKAXE)
|| (a_ItemID == E_ITEM_IRON_PICKAXE)
|| (a_ItemID == E_ITEM_GOLD_PICKAXE)
|| (a_ItemID == E_ITEM_DIAMOND_PICKAXE);
}
inline bool IsAxe(ENUM_ITEM_ID a_ItemID)
{
return (a_ItemID == E_ITEM_WOODEN_AXE)
|| (a_ItemID == E_ITEM_STONE_AXE)
|| (a_ItemID == E_ITEM_IRON_AXE)
|| (a_ItemID == E_ITEM_GOLD_AXE)
|| (a_ItemID == E_ITEM_DIAMOND_AXE);
}
inline bool IsSword(ENUM_ITEM_ID a_ItemID)
{
return (a_ItemID == E_ITEM_WOODEN_SWORD)
|| (a_ItemID == E_ITEM_STONE_SWORD)
|| (a_ItemID == E_ITEM_IRON_SWORD)
|| (a_ItemID == E_ITEM_GOLD_SWORD)
|| (a_ItemID == E_ITEM_DIAMOND_SWORD);
}
inline bool IsHoe(ENUM_ITEM_ID a_ItemID)
{
return (a_ItemID == E_ITEM_WOODEN_HOE)
|| (a_ItemID == E_ITEM_STONE_HOE)
|| (a_ItemID == E_ITEM_IRON_HOE)
|| (a_ItemID == E_ITEM_GOLD_HOE)
|| (a_ItemID == E_ITEM_DIAMOND_HOE);
}
inline bool IsShovel(ENUM_ITEM_ID a_ItemID)
{
return (a_ItemID == E_ITEM_WOODEN_SHOVEL)
|| (a_ItemID == E_ITEM_STONE_SHOVEL)
|| (a_ItemID == E_ITEM_IRON_SHOVEL)
|| (a_ItemID == E_ITEM_GOLD_SHOVEL)
|| (a_ItemID == E_ITEM_DIAMOND_SHOVEL);
}
inline bool IsTool(ENUM_ITEM_ID a_ItemID)
{
return IsPickaxe( a_ItemID )
|| IsAxe ( a_ItemID )
|| IsSword ( a_ItemID )
|| IsHoe ( a_ItemID )
|| IsShovel ( a_ItemID );
}
inline bool IsHelmet(ENUM_ITEM_ID a_ItemType)
{
return (
(a_ItemType == E_ITEM_LEATHER_CAP) ||
(a_ItemType == E_ITEM_GOLD_HELMET) ||
(a_ItemType == E_ITEM_CHAIN_HELMET) ||
(a_ItemType == E_ITEM_IRON_HELMET) ||
(a_ItemType == E_ITEM_DIAMOND_HELMET)
);
}
inline bool IsChestPlate(ENUM_ITEM_ID a_ItemType)
{
return (
(a_ItemType == E_ITEM_LEATHER_TUNIC) ||
(a_ItemType == E_ITEM_GOLD_CHESTPLATE) ||
(a_ItemType == E_ITEM_CHAIN_CHESTPLATE) ||
(a_ItemType == E_ITEM_IRON_CHESTPLATE) ||
(a_ItemType == E_ITEM_DIAMOND_CHESTPLATE)
);
}
inline bool IsLeggings(ENUM_ITEM_ID a_ItemType)
{
return (
(a_ItemType == E_ITEM_LEATHER_PANTS) ||
(a_ItemType == E_ITEM_GOLD_LEGGINGS) ||
(a_ItemType == E_ITEM_CHAIN_LEGGINGS) ||
(a_ItemType == E_ITEM_IRON_LEGGINGS) ||
(a_ItemType == E_ITEM_DIAMOND_LEGGINGS)
);
}
inline bool IsBoots(ENUM_ITEM_ID a_ItemType)
{
return (
(a_ItemType == E_ITEM_LEATHER_BOOTS) ||
(a_ItemType == E_ITEM_GOLD_BOOTS) ||
(a_ItemType == E_ITEM_CHAIN_BOOTS) ||
(a_ItemType == E_ITEM_IRON_BOOTS) ||
(a_ItemType == E_ITEM_DIAMOND_BOOTS)
);
}
}
//tolua_end
inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockID)
{
if(!IsValidBlock(a_BlockID)) return false;
return g_BlockRequiresSpecialTool[a_BlockID];
}
//tolua_begin
enum eGameMode
{
eGameMode_NotSet = -1,
eGameMode_Survival = 0,
eGameMode_Creative = 1
};
enum eWeather
{
eWeather_Sunny = 0,
eWeather_Rain = 1,
eWeather_ThunderStorm = 2
};
//tolua_end
|