2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "ClientHandle.h"
|
|
|
|
#include "World.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class cPlayer;
|
|
|
|
class cPacket;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cBlockEntity
|
|
|
|
{
|
|
|
|
protected:
|
2013-04-06 17:21:57 -04:00
|
|
|
cBlockEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ) : // Used when generating
|
|
|
|
m_PosX(a_BlockX),
|
|
|
|
m_PosY(a_BlockY),
|
|
|
|
m_PosZ(a_BlockZ),
|
|
|
|
m_BlockType(a_BlockType),
|
|
|
|
m_World(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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),
|
|
|
|
m_BlockType(a_BlockType),
|
|
|
|
m_World(a_World)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
public:
|
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;
|
|
|
|
}
|
|
|
|
|
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-04-01 16:56:25 -04:00
|
|
|
virtual void SaveToJson (Json::Value & a_Value) = 0;
|
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.
|
|
|
|
virtual bool Tick(float a_Dt) { return false; }
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_PosX; // Position in absolute block coordinates
|
|
|
|
int m_PosY;
|
|
|
|
int m_PosZ;
|
|
|
|
|
2013-04-06 17:21:57 -04:00
|
|
|
BLOCKTYPE m_BlockType;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
cWorld * m_World;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|