2012-12-24 17:09:01 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockID.h"
|
|
|
|
|
2012-12-24 17:09:01 -05:00
|
|
|
typedef unsigned char Byte;
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
// tolua_begin
|
|
|
|
|
|
|
|
/// How much light do the blocks emit on their own?
|
2012-06-14 09:06:06 -04:00
|
|
|
extern unsigned char g_BlockLightValue[];
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
/// How much light do the block consume?
|
2012-06-14 09:06:06 -04:00
|
|
|
extern unsigned char g_BlockSpreadLightFalloff[];
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
/// Is a block completely transparent? (light doesn't get decreased(?))
|
2012-06-14 09:06:06 -04:00
|
|
|
extern bool g_BlockTransparent[];
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
/// Is a block destroyed after a single hit?
|
|
|
|
extern bool g_BlockOneHitDig[];
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
// Block face constants, used in PlayerDigging and PlayerBlockPlacement packets
|
2012-08-10 16:42:59 -04:00
|
|
|
enum
|
|
|
|
{
|
2012-10-03 03:23:39 -04:00
|
|
|
BLOCK_FACE_NONE = -1, // Interacting with no block face - swinging the item in the air
|
|
|
|
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_NORTH = 2, // Interacting with the northern face of the block
|
|
|
|
BLOCK_FACE_SOUTH = 3, // Interacting with the southern face of the block
|
|
|
|
BLOCK_FACE_WEST = 4, // Interacting with the western face of the block
|
|
|
|
BLOCK_FACE_EAST = 5, // Interacting with the eastern face of the block
|
2012-08-18 05:56:28 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
// PlayerDigging status constants:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
DIG_STATUS_STARTED = 0,
|
|
|
|
DIG_STATUS_FINISHED = 2,
|
|
|
|
DIG_STATUS_DROP_HELD = 4,
|
|
|
|
DIG_STATUS_SHOOT_EAT = 5,
|
2012-08-10 16:42:59 -04:00
|
|
|
} ;
|
2013-01-11 23:46:01 -05:00
|
|
|
// tolua_end
|
2012-08-10 16:42:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
inline bool IsValidBlock(int a_BlockType) // tolua_export
|
|
|
|
{ // tolua_export
|
|
|
|
if (
|
|
|
|
(a_BlockType > -1) &&
|
|
|
|
(a_BlockType <= E_BLOCK_MAX_TYPE_ID) &&
|
|
|
|
(a_BlockType != 34) && // Piston extension
|
|
|
|
(a_BlockType != 36) // Piston moved block
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
} // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
inline bool IsValidItem(int a_ItemType) // tolua_export
|
|
|
|
{ // tolua_export
|
|
|
|
if (
|
|
|
|
((a_ItemType >= E_ITEM_FIRST) && (a_ItemType <= E_ITEM_MAX_CONSECUTIVE_TYPE_ID)) || // Basic items range
|
|
|
|
((a_ItemType >= E_ITEM_FIRST_DISC) && (a_ItemType <= E_ITEM_LAST_DISC)) // Music discs' special range
|
|
|
|
)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
if (a_ItemType == 0)
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
return IsValidBlock(a_ItemType);
|
|
|
|
} // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
inline bool IsBlockWater(BLOCKTYPE a_BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return ((a_BlockType == E_BLOCK_WATER) || (a_BlockType == E_BLOCK_STATIONARY_WATER));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
inline bool IsBlockLava(BLOCKTYPE a_BlockType)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return ((a_BlockType == E_BLOCK_LAVA) || (a_BlockType == E_BLOCK_STATIONARY_LAVA));
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
inline bool IsBlockLiquid(BLOCKTYPE a_BlockType)
|
2012-07-12 13:26:00 -04:00
|
|
|
{
|
2012-10-03 04:52:11 -04:00
|
|
|
return IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType);
|
2012-07-12 13:26:00 -04:00
|
|
|
}
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
inline bool IsBlockTypeOfDirt(BLOCKTYPE a_BlockType)
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
2012-10-03 04:52:11 -04:00
|
|
|
switch (a_BlockType)
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
|
|
|
case E_BLOCK_DIRT:
|
|
|
|
case E_BLOCK_GRASS:
|
|
|
|
case E_BLOCK_FARMLAND:
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2012-07-15 16:36:34 -04:00
|
|
|
return true;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2012-07-15 16:36:34 -04:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-12 13:26:00 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
inline void AddFaceDirection(int & a_BlockX, int & a_BlockY, int & a_BlockZ, char a_BlockFace, bool a_bInverse = false) // tolua_export
|
|
|
|
{ // tolua_export
|
2012-08-10 16:42:59 -04:00
|
|
|
if (!a_bInverse)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
switch (a_BlockFace)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
case BLOCK_FACE_BOTTOM: a_BlockY--; break;
|
|
|
|
case BLOCK_FACE_TOP: a_BlockY++; break;
|
|
|
|
case BLOCK_FACE_EAST: a_BlockX++; break;
|
|
|
|
case BLOCK_FACE_WEST: a_BlockX--; break;
|
|
|
|
case BLOCK_FACE_NORTH: a_BlockZ--; break;
|
|
|
|
case BLOCK_FACE_SOUTH: a_BlockZ++; break;
|
2012-08-10 16:42:59 -04:00
|
|
|
default:
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGWARNING("%s: Unknown face: %d", __FUNCTION__, a_BlockFace);
|
|
|
|
ASSERT(!"AddFaceDirection(): Unknown face");
|
2012-08-10 16:42:59 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
switch (a_BlockFace)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
case BLOCK_FACE_BOTTOM: a_BlockY++; break;
|
|
|
|
case BLOCK_FACE_TOP: a_BlockY--; break;
|
|
|
|
case BLOCK_FACE_EAST: a_BlockX--; break;
|
|
|
|
case BLOCK_FACE_WEST: a_BlockX++; break;
|
|
|
|
case BLOCK_FACE_NORTH: a_BlockZ++; break;
|
|
|
|
case BLOCK_FACE_SOUTH: a_BlockZ--; break;
|
2012-08-10 16:42:59 -04:00
|
|
|
default:
|
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
LOGWARNING("%s: Unknown inv face: %d", __FUNCTION__, a_BlockFace);
|
|
|
|
ASSERT(!"AddFaceDirection(): Unknown face");
|
2012-08-10 16:42:59 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
} // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
inline void AddFaceDirection(int & a_BlockX, unsigned char & a_BlockY, int & a_BlockZ, char a_BlockFace, bool a_bInverse = false)
|
|
|
|
{
|
|
|
|
int Y = a_BlockY;
|
|
|
|
AddFaceDirection(a_BlockX, Y, a_BlockZ, a_BlockFace, a_bInverse);
|
|
|
|
if (Y < 0)
|
|
|
|
{
|
|
|
|
a_BlockY = 0;
|
|
|
|
}
|
|
|
|
else if (Y > 255)
|
|
|
|
{
|
|
|
|
a_BlockY = 255;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a_BlockY = (unsigned char)Y;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
// tolua_begin
|
2012-06-14 09:06:06 -04:00
|
|
|
namespace ItemCategory
|
|
|
|
{
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsPickaxe(short a_ItemID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsAxe(short a_ItemID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsSword(short a_ItemID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsHoe(short a_ItemID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsShovel(short a_ItemID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsTool(short a_ItemID)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
return IsPickaxe( a_ItemID )
|
|
|
|
|| IsAxe ( a_ItemID )
|
|
|
|
|| IsSword ( a_ItemID )
|
|
|
|
|| IsHoe ( a_ItemID )
|
|
|
|
|| IsShovel ( a_ItemID );
|
|
|
|
}
|
2012-08-11 15:43:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsHelmet(short a_ItemType)
|
2012-08-11 15:43:28 -04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsChestPlate(short a_ItemType)
|
2012-08-11 15:43:28 -04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsLeggings(short a_ItemType)
|
2012-08-11 15:43:28 -04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-08-19 07:51:17 -04:00
|
|
|
inline bool IsBoots(short a_ItemType)
|
2012-08-11 15:43:28 -04:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-10-03 04:52:11 -04:00
|
|
|
inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockType)
|
2012-07-15 16:36:34 -04:00
|
|
|
{
|
2012-10-03 04:52:11 -04:00
|
|
|
if(!IsValidBlock(a_BlockType)) return false;
|
|
|
|
return g_BlockRequiresSpecialTool[a_BlockType];
|
2012-07-15 16:36:34 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
// tolua_begin
|
2012-06-14 09:06:06 -04:00
|
|
|
enum eGameMode
|
|
|
|
{
|
2012-11-27 14:55:23 -05:00
|
|
|
eGameMode_NotSet = -1,
|
|
|
|
eGameMode_Survival = 0,
|
|
|
|
eGameMode_Creative = 1,
|
|
|
|
eGameMode_Adventure = 2
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum eWeather
|
|
|
|
{
|
2012-08-03 07:53:11 -04:00
|
|
|
eWeather_Sunny = 0,
|
|
|
|
eWeather_Rain = 1,
|
|
|
|
eWeather_ThunderStorm = 2
|
2012-06-14 09:06:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|