diff options
Diffstat (limited to 'source/cChestEntity.cpp')
-rw-r--r-- | source/cChestEntity.cpp | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/source/cChestEntity.cpp b/source/cChestEntity.cpp index b30800700..e96d4bbb2 100644 --- a/source/cChestEntity.cpp +++ b/source/cChestEntity.cpp @@ -23,14 +23,18 @@ class cRoot; -cChestEntity::cChestEntity(int a_X, int a_Y, int a_Z, cChunk* a_Chunk)
- : cBlockEntity( E_BLOCK_CHEST, a_X, a_Y, a_Z, a_Chunk )
+cChestEntity::cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
+ : cBlockEntity( E_BLOCK_CHEST, a_X, a_Y, a_Z, a_World)
, m_TopChest( false )
- , m_JoinedChest( 0 )
+ , m_JoinedChest( NULL )
{
m_Content = new cItem[ c_ChestHeight*c_ChestWidth ];
}
+
+
+
+
cChestEntity::~cChestEntity()
{
if( GetWindow() )
@@ -44,6 +48,10 @@ cChestEntity::~cChestEntity() }
}
+
+
+
+
void cChestEntity::Destroy()
{
// Drop items
@@ -51,15 +59,21 @@ void cChestEntity::Destroy() {
if( !m_Content[i].IsEmpty() )
{
- cPickup* Pickup = new cPickup( m_PosX*32 + 16, m_PosY*32 + 16, m_PosZ*32 + 16, m_Content[i], 0, 1.f, 0 );
- Pickup->Initialize( GetChunk()->GetWorld() );
+ cPickup * Pickup = new cPickup( m_PosX * 32 + 16, m_PosY * 32 + 16, m_PosZ * 32 + 16, m_Content[i], 0, 1.f, 0 );
+ Pickup->Initialize(m_World);
m_Content[i].Empty();
}
}
if (m_JoinedChest)
+ {
m_JoinedChest->RemoveJoinedChest(this);
+ }
}
+
+
+
+
cItem * cChestEntity::GetSlot( int a_Slot )
{
if( a_Slot > -1 && a_Slot < c_ChestHeight*c_ChestWidth )
@@ -69,6 +83,10 @@ cItem * cChestEntity::GetSlot( int a_Slot ) return 0;
}
+
+
+
+
void cChestEntity::SetSlot( int a_Slot, cItem & a_Item )
{
if( a_Slot > -1 && a_Slot < c_ChestHeight*c_ChestWidth )
@@ -129,6 +147,10 @@ bool cChestEntity::LoadFromJson( const Json::Value& a_Value ) return true;
}
+
+
+
+
void cChestEntity::SaveToJson( Json::Value& a_Value )
{
a_Value["x"] = m_PosX;
@@ -147,6 +169,10 @@ void cChestEntity::SaveToJson( Json::Value& a_Value ) a_Value["Slots"] = AllSlots;
}
+
+
+
+
void cChestEntity::SendTo( cClientHandle* a_Client, cServer* a_Server )
{
(void)a_Client;
@@ -154,6 +180,10 @@ void cChestEntity::SendTo( cClientHandle* a_Client, cServer* a_Server ) return;
}
+
+
+
+
void cChestEntity::UsedBy( cPlayer & a_Player )
{
LOG("Used a chest");
@@ -185,15 +215,13 @@ void cChestEntity::UsedBy( cPlayer & a_Player ) ChestOpen.m_PosZ = GetPosZ();
ChestOpen.m_Byte1 = (char)1;
ChestOpen.m_Byte2 = (char)1;
- cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers();
- for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
- {
- if ((*itr) && (*itr)->GetClientHandle() && !((*itr)->GetClientHandle()->IsDestroyed())) {
- (*itr)->GetClientHandle()->Send( ChestOpen );
- }
- }
+ m_World->GetChunkOfBlock(m_PosX, m_PosY, m_PosZ)->Broadcast(&ChestOpen);
}
+
+
+
+
cItem *cChestEntity::GetContents(bool a_OnlyThis)
{
if (m_JoinedChest && !a_OnlyThis)
@@ -215,3 +243,7 @@ cItem *cChestEntity::GetContents(bool a_OnlyThis) else
return m_Content;
}
+
+
+
+
|