2012-02-13 16:47:03 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#pragma once
|
|
|
|
|
2012-03-05 11:41:57 -05:00
|
|
|
#include "cClientHandle.h"
|
|
|
|
#include "cWorld.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include "BlockID.h"
|
|
|
|
#else
|
|
|
|
enum ENUM_BLOCK_ID;
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
};
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
class cPlayer;
|
2012-02-13 16:47:03 -05:00
|
|
|
class cWorld;
|
2012-03-05 11:41:57 -05:00
|
|
|
class cPacket;
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
class cBlockEntity
|
|
|
|
{
|
|
|
|
protected:
|
2012-02-13 16:47:03 -05:00
|
|
|
cBlockEntity(ENUM_BLOCK_ID a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World)
|
2011-10-30 20:52:20 -04:00
|
|
|
: m_PosX( a_X )
|
|
|
|
, m_PosY( a_Y )
|
|
|
|
, m_PosZ( a_Z )
|
|
|
|
, m_BlockType( a_BlockType )
|
2012-02-14 08:15:09 -05:00
|
|
|
, m_World( a_World )
|
2011-10-30 20:52:20 -04:00
|
|
|
{}
|
2011-10-03 14:41:19 -04:00
|
|
|
public:
|
|
|
|
virtual ~cBlockEntity() {};
|
|
|
|
virtual void Destroy() {};
|
2011-11-06 04:23:20 -05:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
int GetPosX() { return m_PosX; }
|
|
|
|
int GetPosY() { return m_PosY; }
|
|
|
|
int GetPosZ() { return m_PosZ; }
|
|
|
|
|
|
|
|
ENUM_BLOCK_ID GetBlockType() { return m_BlockType; }
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
cWorld * GetWorld(void) const {return m_World; }
|
2011-10-03 14:41:19 -04:00
|
|
|
|
2012-02-16 08:42:35 -05:00
|
|
|
virtual void SaveToJson (Json::Value & a_Value ) = 0;
|
|
|
|
|
2012-02-15 09:22:44 -05:00
|
|
|
virtual void UsedBy( cPlayer * a_Player ) = 0;
|
2012-03-05 11:41:57 -05:00
|
|
|
|
|
|
|
void SendTo( cClientHandle* a_Client )
|
|
|
|
{
|
|
|
|
std::auto_ptr<cPacket> Packet(GetPacket());
|
|
|
|
if (Packet.get() == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( a_Client != NULL )
|
|
|
|
{
|
2012-03-10 16:34:47 -05:00
|
|
|
a_Client->Send(*(Packet.get()));
|
2012-03-05 11:41:57 -05:00
|
|
|
}
|
|
|
|
else // broadcast to all chunk clients
|
|
|
|
{
|
|
|
|
m_World->BroadcastToChunkOfBlock(m_PosX, m_PosY, m_PosZ, Packet.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the packet to send to clients to represent this entity; NULL if no packet needed; caller is supposed to delete the packet
|
|
|
|
virtual cPacket * GetPacket(void) {return NULL; }
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
int m_PosX; // Position in block coordinates
|
|
|
|
int m_PosY;
|
|
|
|
int m_PosZ;
|
|
|
|
|
|
|
|
ENUM_BLOCK_ID m_BlockType;
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
cWorld * m_World;
|
2011-10-03 14:41:19 -04:00
|
|
|
};
|
2012-02-13 16:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|