summaryrefslogtreecommitdiffstats
path: root/source/cChestEntity.cpp
diff options
context:
space:
mode:
authormtilden@gmail.com <mtilden@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-29 14:16:23 +0100
committermtilden@gmail.com <mtilden@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-29 14:16:23 +0100
commitc4f4ae5c7122c58af239a01328c168627ed68e27 (patch)
treea14c16b0e2b270caa465892a0d2a60adf2e3d78e /source/cChestEntity.cpp
parent- Pickups should now burn in fire (diff)
downloadcuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.tar
cuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.tar.gz
cuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.tar.bz2
cuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.tar.lz
cuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.tar.xz
cuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.tar.zst
cuberite-c4f4ae5c7122c58af239a01328c168627ed68e27.zip
Diffstat (limited to 'source/cChestEntity.cpp')
-rw-r--r--source/cChestEntity.cpp52
1 files changed, 48 insertions, 4 deletions
diff --git a/source/cChestEntity.cpp b/source/cChestEntity.cpp
index d0cd85536..ee70a6fb8 100644
--- a/source/cChestEntity.cpp
+++ b/source/cChestEntity.cpp
@@ -5,14 +5,21 @@
#include "cMCLogger.h"
#include "cPlayer.h"
#include "cWindow.h"
+#include "cWorld.h"
+#include "cRoot.h"
#include "cPickup.h"
#include "cMCLogger.h"
#include "cChunk.h"
+class cWorld;
+class cRoot;
+
#include <json/json.h>
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 )
+ , m_TopChest( false )
+ , m_JoinedChest( 0 )
{
m_Content = new cItem[ c_ChestHeight*c_ChestWidth ];
}
@@ -33,7 +40,7 @@ cChestEntity::~cChestEntity()
void cChestEntity::Destroy()
{
// Drop items
- for( int i = 0; i < c_ChestHeight*c_ChestWidth; ++i )
+ for( int i = 0; i < c_ChestHeight * c_ChestWidth; ++i )
{
if( !m_Content[i].IsEmpty() )
{
@@ -42,6 +49,8 @@ void cChestEntity::Destroy()
m_Content[i].Empty();
}
}
+ if (m_JoinedChest)
+ m_JoinedChest->RemoveJoinedChest(this);
}
cItem * cChestEntity::GetSlot( int a_Slot )
@@ -154,19 +163,54 @@ void cChestEntity::UsedBy( cPlayer & a_Player )
if( !GetWindow() )
{
cWindow* Window = new cWindow( this, true );
- Window->SetSlots( m_Content, c_ChestHeight*c_ChestWidth );
+ Window->SetSlots( GetContents(), GetChestHeight()*c_ChestWidth );
Window->SetWindowID( 1 );
Window->SetWindowType( cWindow::Chest );
Window->SetWindowTitle("UberChest");
+ Window->GetOwner()->SetEntity(this);
OpenWindow( Window );
}
- if( GetWindow() )
+ if ( GetWindow() )
{
if( a_Player.GetWindow() != GetWindow() )
{
a_Player.OpenWindow( GetWindow() );
-
GetWindow()->SendWholeWindow( a_Player.GetClientHandle() );
}
}
+ cPacket_BlockAction ChestOpen;
+ ChestOpen.m_PosX = GetPosX();
+ ChestOpen.m_PosY = (short)GetPosY();
+ 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 );
+ }
+ }
+}
+
+cItem *cChestEntity::GetContents(bool a_OnlyThis)
+{
+ if (m_JoinedChest && !a_OnlyThis)
+ {
+ cItem *Combined = new cItem[GetChestHeight()*c_ChestWidth];
+ int i;
+ cItem *first = (m_TopChest) ? GetContents(true) : m_JoinedChest->GetContents(true);
+ cItem *second = (!m_TopChest) ? GetContents(true) : m_JoinedChest->GetContents(true);
+ for (i=0; i < GetChestHeight()*c_ChestWidth; i++)
+ {
+ int index = i % c_ChestHeight*c_ChestWidth;
+ if (i < c_ChestHeight*c_ChestWidth)
+ Combined[index] = first[index];
+ else
+ Combined[index] = second[index];
+ }
+ return Combined;
+ }
+ else
+ return m_Content;
}