2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
};
|
|
|
|
|
2014-09-26 13:13:19 -04:00
|
|
|
class cChunk;
|
2012-06-14 09:06:06 -04:00
|
|
|
class cPlayer;
|
2014-09-26 13:13:19 -04:00
|
|
|
class cWorld;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-07-22 18:36:13 -04:00
|
|
|
virtual ~cBlockEntity() {} // force a virtual destructor in all descendants
|
2013-04-06 17:21:57 -04:00
|
|
|
|
2014-07-22 18:36:13 -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-05-28 14:50:44 -04:00
|
|
|
/// Called when a player uses this entity; should open the UI window
|
2014-07-21 09:19:48 -04:00
|
|
|
virtual void UsedBy( cPlayer * a_Player) = 0;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
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-12-30 11:41:59 -05:00
|
|
|
virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */)
|
2013-12-22 08:46:55 -05:00
|
|
|
{
|
|
|
|
UNUSED(a_Dt);
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|