2012-02-13 13:47:03 -08:00
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
#pragma once
|
|
|
|
|
2012-03-05 08:41:57 -08:00
|
|
|
#include "cClientHandle.h"
|
|
|
|
#include "cWorld.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include "BlockID.h"
|
|
|
|
#else
|
|
|
|
enum ENUM_BLOCK_ID;
|
|
|
|
#endif
|
|
|
|
|
2012-02-13 13:47:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-16 05:42:35 -08:00
|
|
|
namespace Json
|
|
|
|
{
|
|
|
|
class Value;
|
|
|
|
};
|
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
class cPlayer;
|
2012-02-13 13:47:03 -08:00
|
|
|
class cWorld;
|
2012-03-05 08:41:57 -08:00
|
|
|
class cPacket;
|
2012-02-13 13:47:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
class cBlockEntity
|
|
|
|
{
|
|
|
|
protected:
|
2012-04-23 14:20:32 -07:00
|
|
|
cBlockEntity(ENUM_BLOCK_ID 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 )
|
2011-10-30 17:52:20 -07:00
|
|
|
, m_BlockType( a_BlockType )
|
2012-02-14 05:15:09 -08:00
|
|
|
, m_World( a_World )
|
2011-10-30 17:52:20 -07:00
|
|
|
{}
|
2011-10-03 11:41:19 -07:00
|
|
|
public:
|
|
|
|
virtual ~cBlockEntity() {};
|
|
|
|
virtual void Destroy() {};
|
2011-11-06 01:23:20 -08:00
|
|
|
|
2012-04-23 14:20:32 -07:00
|
|
|
// Position, in absolute block coordinates:
|
2011-10-03 11:41:19 -07: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 13:47:03 -08:00
|
|
|
|
|
|
|
cWorld * GetWorld(void) const {return m_World; }
|
2011-10-03 11:41:19 -07:00
|
|
|
|
2012-02-16 05:42:35 -08:00
|
|
|
virtual void SaveToJson (Json::Value & a_Value ) = 0;
|
|
|
|
|
2012-02-15 06:22:44 -08:00
|
|
|
virtual void UsedBy( cPlayer * a_Player ) = 0;
|
2012-03-05 08:41:57 -08:00
|
|
|
|
|
|
|
void SendTo( cClientHandle* a_Client )
|
|
|
|
{
|
|
|
|
std::auto_ptr<cPacket> Packet(GetPacket());
|
|
|
|
if (Packet.get() == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( a_Client != NULL )
|
|
|
|
{
|
2012-03-10 13:34:47 -08:00
|
|
|
a_Client->Send(*(Packet.get()));
|
2012-03-05 08:41:57 -08: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 11:41:19 -07:00
|
|
|
|
|
|
|
protected:
|
2012-04-23 14:20:32 -07:00
|
|
|
int m_PosX; // Position in absolute block coordinates
|
2011-10-03 11:41:19 -07:00
|
|
|
int m_PosY;
|
|
|
|
int m_PosZ;
|
|
|
|
|
|
|
|
ENUM_BLOCK_ID m_BlockType;
|
2012-02-13 13:47:03 -08:00
|
|
|
|
|
|
|
cWorld * m_World;
|
2011-10-03 11:41:19 -07:00
|
|
|
};
|
2012-02-13 13:47:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|