summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-07 14:05:35 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-07 14:05:35 +0200
commitb53b40b5610c456176f4b7962e1af1cc49562930 (patch)
treef3e24c0f4d063d9c8c59f8b3c56745fd0da041c8
parentRemoved the build folder (diff)
downloadcuberite-b53b40b5610c456176f4b7962e1af1cc49562930.tar
cuberite-b53b40b5610c456176f4b7962e1af1cc49562930.tar.gz
cuberite-b53b40b5610c456176f4b7962e1af1cc49562930.tar.bz2
cuberite-b53b40b5610c456176f4b7962e1af1cc49562930.tar.lz
cuberite-b53b40b5610c456176f4b7962e1af1cc49562930.tar.xz
cuberite-b53b40b5610c456176f4b7962e1af1cc49562930.tar.zst
cuberite-b53b40b5610c456176f4b7962e1af1cc49562930.zip
-rw-r--r--source/cChestEntity.cpp2
-rw-r--r--source/cChestEntity.h2
-rw-r--r--source/cFurnaceEntity.cpp4
-rw-r--r--source/cFurnaceEntity.h2
-rw-r--r--source/cInventory.h3
-rw-r--r--source/cWindowOwner.h99
6 files changed, 94 insertions, 18 deletions
diff --git a/source/cChestEntity.cpp b/source/cChestEntity.cpp
index 4a46167c0..5d015f42e 100644
--- a/source/cChestEntity.cpp
+++ b/source/cChestEntity.cpp
@@ -28,6 +28,7 @@ cChestEntity::cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
, m_JoinedChest( NULL )
{
m_Content = new cItem[ c_ChestHeight * c_ChestWidth ];
+ SetBlockEntity(this); // cBlockEntityWindowOwner
}
@@ -173,7 +174,6 @@ void cChestEntity::UsedBy(cPlayer * a_Player)
cWindow * Window = new cWindow(this, true, cWindow::Chest, 1);
Window->SetSlots(GetContents(), GetChestHeight() * c_ChestWidth);
Window->SetWindowTitle("UberChest");
- Window->GetOwner()->SetEntity(this);
OpenWindow( Window );
}
if ( GetWindow() )
diff --git a/source/cChestEntity.h b/source/cChestEntity.h
index b24533d76..0f37bdc81 100644
--- a/source/cChestEntity.h
+++ b/source/cChestEntity.h
@@ -25,7 +25,7 @@ class cNBTData;
class cChestEntity :
public cBlockEntity,
- public cWindowOwner
+ public cBlockEntityWindowOwner
{
public:
cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
diff --git a/source/cFurnaceEntity.cpp b/source/cFurnaceEntity.cpp
index f127e05e8..6fe1936e9 100644
--- a/source/cFurnaceEntity.cpp
+++ b/source/cFurnaceEntity.cpp
@@ -22,7 +22,7 @@
cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
- : cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_World )
+ : cBlockEntity( E_BLOCK_FURNACE, a_X, a_Y, a_Z, a_World )
, m_Items( new cItem[3] )
, m_CookingItem( 0 )
, m_CookTime( 0 )
@@ -30,6 +30,7 @@ cFurnaceEntity::cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World)
, m_BurnTime( 0 )
, m_TimeBurned( 0 )
{
+ SetBlockEntity(this); // cBlockEntityWindowOwner
}
@@ -83,7 +84,6 @@ void cFurnaceEntity::UsedBy( cPlayer * a_Player )
cWindow* Window = new cFurnaceWindow( this );
Window->SetSlots( m_Items, 3 );
Window->SetWindowTitle("UberFurnace");
- Window->GetOwner()->SetEntity(this);
OpenWindow( Window );
}
if( GetWindow() )
diff --git a/source/cFurnaceEntity.h b/source/cFurnaceEntity.h
index 7fc090bee..2a8581eb9 100644
--- a/source/cFurnaceEntity.h
+++ b/source/cFurnaceEntity.h
@@ -23,7 +23,7 @@ class cServer;
class cFurnaceEntity :
public cBlockEntity,
- public cWindowOwner
+ public cBlockEntityWindowOwner
{
public:
cFurnaceEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
diff --git a/source/cInventory.h b/source/cInventory.h
index 0b4220b32..f795a9898 100644
--- a/source/cInventory.h
+++ b/source/cInventory.h
@@ -75,6 +75,9 @@ protected:
short m_EquippedSlot;
cPlayer* m_Owner;
+
+ // cWindowOwner override:
+ virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override {} // UNUSED for an inventory
}; //tolua_export
diff --git a/source/cWindowOwner.h b/source/cWindowOwner.h
index ef08bbe44..6c9a15a45 100644
--- a/source/cWindowOwner.h
+++ b/source/cWindowOwner.h
@@ -2,6 +2,7 @@
#pragma once
#include "cBlockEntity.h"
+#include "cEntity.h"
@@ -14,29 +15,101 @@ class cWindow;
/**
-Implements the base behavior expected from a class that can handle UI windows for block entities.
+Base class for the behavior expected from a class that can handle UI windows for block entities.
*/
class cWindowOwner
{
public:
- cWindowOwner() : m_Window( NULL ) {}
- void CloseWindow() { m_Window = NULL; }
- void OpenWindow( cWindow* a_Window ) { m_Window = a_Window; }
+ cWindowOwner() :
+ m_Window(NULL)
+ {
+ }
+
+ void CloseWindow(void)
+ {
+ m_Window = NULL;
+ }
+
+ void OpenWindow(cWindow * a_Window)
+ {
+ m_Window = a_Window;
+ }
+
+ cWindow * GetWindow(void) const
+ {
+ return m_Window;
+ }
+
+ /// Returns the block position at which the element owning the window is
+ virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) = 0;
+
+private:
+ cWindow * m_Window;
+} ;
+
+
+
+
+
+/**
+Window owner that is associated with a block entity (chest, furnace, ...)
+*/
+class cBlockEntityWindowOwner :
+ public cWindowOwner
+{
+public:
+ cBlockEntityWindowOwner(void) :
+ m_BlockEntity(NULL)
+ {
+ }
+
+ void SetBlockEntity(cBlockEntity * a_BlockEntity)
+ {
+ m_BlockEntity = a_BlockEntity;
+ }
+
+ virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override
+ {
+ a_BlockX = m_BlockEntity->GetPosX();
+ a_BlockY = m_BlockEntity->GetPosY();
+ a_BlockZ = m_BlockEntity->GetPosZ();
+ }
+
+private:
+ cBlockEntity * m_BlockEntity;
+} ;
+
+
- cWindow* GetWindow() { return m_Window; }
- void SetEntity(cBlockEntity * a_Entity) { m_Entity = a_Entity; }
- void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+
+/**
+Window owner that is associated with an entity (chest minecart)
+*/
+class cEntityWindowOwner :
+ public cWindowOwner
+{
+public:
+ cEntityWindowOwner(void) :
+ m_Entity(NULL)
+ {
+ }
+
+ void SetEntity(cEntity * a_Entity)
+ {
+ m_Entity = a_Entity;
+ }
+
+ virtual void GetBlockPos(int & a_BlockX, int & a_BlockY, int & a_BlockZ) override
{
- a_BlockX = m_Entity->GetPosX();
- a_BlockY = m_Entity->GetPosY();
- a_BlockZ = m_Entity->GetPosZ();
+ a_BlockX = (int)(m_Entity->GetPosX());
+ a_BlockY = (int)(m_Entity->GetPosY());
+ a_BlockZ = (int)(m_Entity->GetPosZ());
}
private:
- cWindow * m_Window;
- cBlockEntity * m_Entity;
-};
+ cEntity * m_Entity;
+} ;