2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-05-28 15:12:47 -04:00
|
|
|
#include "../ClientHandle.h"
|
|
|
|
#include "../World.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cPlayer;
|
|
|
|
class cPacket;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-25 07:59:13 -04:00
|
|
|
// tolua_begin
|
2012-06-14 09:06:06 -04:00
|
|
|
class cBlockEntity
|
|
|
|
{
|
|
|
|
protected:
|
2013-04-06 17:21:57 -04:00
|
|
|
cBlockEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
|
|
|
|
m_PosX(a_BlockX),
|
|
|
|
m_PosY(a_BlockY),
|
|
|
|
m_PosZ(a_BlockZ),
|
2013-05-28 14:50:44 -04:00
|
|
|
m_RelX(a_BlockX - cChunkDef::Width * FAST_FLOOR_DIV(a_BlockX, cChunkDef::Width)),
|
|
|
|
m_RelZ(a_BlockZ - cChunkDef::Width * FAST_FLOOR_DIV(a_BlockZ, cChunkDef::Width)),
|
2013-04-06 17:21:57 -04:00
|
|
|
m_BlockType(a_BlockType),
|
|
|
|
m_World(a_World)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
2013-05-25 07:59:13 -04:00
|
|
|
// tolua_end
|
|
|
|
|
2013-04-06 17:21:57 -04:00
|
|
|
virtual ~cBlockEntity() {}; // force a virtual destructor in all descendants
|
|
|
|
|
2013-04-01 16:56:25 -04:00
|
|
|
virtual void Destroy(void) {};
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-06 17:21:57 -04:00
|
|
|
void SetWorld(cWorld * a_World)
|
|
|
|
{
|
|
|
|
m_World = a_World;
|
|
|
|
}
|
|
|
|
|
2013-11-14 09:37:09 -05:00
|
|
|
/// Creates a new block entity for the specified block type
|
|
|
|
/// If a_World is valid, then the entity is created bound to that world
|
|
|
|
/// Returns NULL for unknown block types
|
|
|
|
static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World = NULL);
|
|
|
|
|
2013-11-20 15:53:29 -05:00
|
|
|
static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
|
|
|
|
{
|
|
|
|
return "cBlockEntity";
|
|
|
|
}
|
|
|
|
|
2013-11-15 04:15:27 -05:00
|
|
|
// tolua_begin
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// Position, in absolute block coordinates:
|
2013-04-01 16:56:25 -04:00
|
|
|
int GetPosX(void) const { return m_PosX; }
|
|
|
|
int GetPosY(void) const { return m_PosY; }
|
|
|
|
int GetPosZ(void) const { return m_PosZ; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-06 17:21:57 -04:00
|
|
|
BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cWorld * GetWorld(void) const {return m_World; }
|
2013-05-25 07:59:13 -04:00
|
|
|
|
2013-05-26 11:29:43 -04:00
|
|
|
int GetChunkX(void) const { return FAST_FLOOR_DIV(m_PosX, cChunkDef::Width); }
|
|
|
|
int GetChunkZ(void) const { return FAST_FLOOR_DIV(m_PosZ, cChunkDef::Width); }
|
|
|
|
|
2013-05-28 14:50:44 -04:00
|
|
|
int GetRelX(void) const { return m_RelX; }
|
|
|
|
int GetRelZ(void) const { return m_RelZ; }
|
|
|
|
|
2013-05-25 07:59:13 -04:00
|
|
|
// tolua_end
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-01 16:56:25 -04:00
|
|
|
virtual void SaveToJson (Json::Value & a_Value) = 0;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-05-28 14:50:44 -04:00
|
|
|
/// Called when a player uses this entity; should open the UI window
|
2012-06-14 09:06:06 -04:00
|
|
|
virtual void UsedBy( cPlayer * a_Player ) = 0;
|
|
|
|
|
2012-08-24 03:58:26 -04:00
|
|
|
/** Sends the packet defining the block entity to the client specified.
|
|
|
|
To send to all eligible clients, use cWorld::BroadcastBlockEntity()
|
|
|
|
*/
|
|
|
|
virtual void SendTo(cClientHandle & a_Client) = 0;
|
2013-04-01 16:56:25 -04:00
|
|
|
|
|
|
|
/// Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing.
|
2013-05-28 14:50:44 -04:00
|
|
|
virtual bool Tick(float a_Dt, cChunk & a_Chunk) { return false; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
2013-05-28 14:50:44 -04:00
|
|
|
/// Position in absolute block coordinates
|
|
|
|
int m_PosX, m_PosY, m_PosZ;
|
|
|
|
|
|
|
|
/// Position relative to the chunk, used to speed up ticking
|
|
|
|
int m_RelX, m_RelZ;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-04-06 17:21:57 -04:00
|
|
|
BLOCKTYPE m_BlockType;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cWorld * m_World;
|
2013-05-25 07:59:13 -04:00
|
|
|
} ; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|