Added hopper entity, it can suck items out of chests, dispensers, droppers and other hopppers above it.
git-svn-id: http://mc-server.googlecode.com/svn/trunk@1587 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
@@ -665,6 +665,16 @@ cSlotAreaItemGrid::cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentW
|
||||
super(a_ItemGrid.GetNumSlots(), a_ParentWindow),
|
||||
m_ItemGrid(a_ItemGrid)
|
||||
{
|
||||
m_ItemGrid.AddListener(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cSlotAreaItemGrid::~cSlotAreaItemGrid()
|
||||
{
|
||||
m_ItemGrid.RemoveListener(*this);
|
||||
}
|
||||
|
||||
|
||||
@@ -689,6 +699,16 @@ void cSlotAreaItemGrid::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem &
|
||||
|
||||
|
||||
|
||||
void cSlotAreaItemGrid::OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum)
|
||||
{
|
||||
ASSERT(a_ItemGrid == &m_ItemGrid);
|
||||
m_ParentWindow.BroadcastSlot(this, a_SlotNum);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cSlotAreaTemporary:
|
||||
|
||||
|
||||
@@ -143,18 +143,24 @@ public:
|
||||
|
||||
/// Handles any slot area that is representing a cItemGrid; same items for all the players
|
||||
class cSlotAreaItemGrid :
|
||||
public cSlotArea
|
||||
public cSlotArea,
|
||||
public cItemGrid::cListener
|
||||
{
|
||||
typedef cSlotArea super;
|
||||
|
||||
public:
|
||||
cSlotAreaItemGrid(cItemGrid & a_ItemGrid, cWindow & a_ParentWindow);
|
||||
|
||||
virtual ~cSlotAreaItemGrid();
|
||||
|
||||
virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override;
|
||||
virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override;
|
||||
|
||||
protected:
|
||||
cItemGrid & m_ItemGrid;
|
||||
|
||||
// cItemGrid::cListener overrides:
|
||||
virtual void OnSlotChanged(cItemGrid * a_ItemGrid, int a_SlotNum) override;
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "../Inventory.h"
|
||||
#include "../Items/ItemHandler.h"
|
||||
#include "../BlockEntities/ChestEntity.h"
|
||||
#include "../BlockEntities/HopperEntity.h"
|
||||
|
||||
|
||||
|
||||
@@ -607,6 +608,40 @@ int cWindow::DistributeItemToSlots(cPlayer & a_Player, const cItem & a_Item, int
|
||||
|
||||
|
||||
|
||||
void cWindow::BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum)
|
||||
{
|
||||
// Translate local slot num into global slot num:
|
||||
int SlotNum = 0;
|
||||
bool HasFound = false;
|
||||
for (cSlotAreas::const_iterator itr = m_SlotAreas.begin(), end = m_SlotAreas.end(); itr != end; ++itr)
|
||||
{
|
||||
if (a_Area == *itr)
|
||||
{
|
||||
SlotNum += a_LocalSlotNum;
|
||||
HasFound = true;
|
||||
break;
|
||||
}
|
||||
SlotNum += (*itr)->GetNumSlots();
|
||||
} // for itr - m_SlotAreas[]
|
||||
if (!HasFound)
|
||||
{
|
||||
LOGWARNING("%s: Invalid slot area parameter", __FUNCTION__);
|
||||
ASSERT(!"Invalid slot area");
|
||||
return;
|
||||
}
|
||||
|
||||
// Broadcast the update packet:
|
||||
cCSLock Lock(m_CS);
|
||||
for (cPlayerList::iterator itr = m_OpenedBy.begin(); itr != m_OpenedBy.end(); ++itr)
|
||||
{
|
||||
(*itr)->GetClientHandle()->SendInventorySlot(m_WindowID, SlotNum, *a_Area->GetSlot(a_LocalSlotNum, **itr));
|
||||
} // for itr - m_OpenedBy[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cWindow::SendWholeWindow(cClientHandle & a_Client)
|
||||
{
|
||||
a_Client.SendWholeInventory(*this);
|
||||
@@ -741,6 +776,7 @@ cChestWindow::~cChestWindow()
|
||||
cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserEntity * a_DropSpenser) :
|
||||
cWindow(cWindow::DropSpenser, "MCS-DropSpenser")
|
||||
{
|
||||
m_ShouldDistributeToHotbarFirst = false;
|
||||
m_SlotAreas.push_back(new cSlotAreaDropSpenser(a_DropSpenser, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
@@ -750,12 +786,29 @@ cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ,
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cHopperWindow:
|
||||
|
||||
cHopperWindow::cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper) :
|
||||
super(cWindow::Hopper, "MCS-Hopper")
|
||||
{
|
||||
m_ShouldDistributeToHotbarFirst = false;
|
||||
m_SlotAreas.push_back(new cSlotAreaItemGrid(a_Hopper->GetContents(), *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cFurnaceWindow:
|
||||
|
||||
cFurnaceWindow::cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceEntity * a_Furnace) :
|
||||
cWindow(cWindow::Furnace, "MCS-Furnace")
|
||||
{
|
||||
m_ShouldDistributeToHotbarFirst = false;
|
||||
m_SlotAreas.push_back(new cSlotAreaFurnace(a_Furnace, *this));
|
||||
m_SlotAreas.push_back(new cSlotAreaInventory(*this));
|
||||
m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
|
||||
|
||||
@@ -21,6 +21,7 @@ class cClientHandle;
|
||||
class cChestEntity;
|
||||
class cDropSpenserEntity;
|
||||
class cFurnaceEntity;
|
||||
class cHopperEntity;
|
||||
class cSlotArea;
|
||||
class cWorld;
|
||||
|
||||
@@ -110,8 +111,16 @@ public:
|
||||
/// Called when a player closes this window; notifies all slot areas. Returns true if close accepted
|
||||
virtual bool ClosedByPlayer(cPlayer & a_Player, bool a_CanRefuse);
|
||||
|
||||
/// Sends the specified slot's contents to all clients of this window; the slot is specified as local in an area
|
||||
void BroadcastSlot(cSlotArea * a_Area, int a_LocalSlotNum);
|
||||
|
||||
/// Sends the contents of the whole window to the specified client
|
||||
void SendWholeWindow(cClientHandle & a_Client);
|
||||
|
||||
/// Sends the contents of the whole window to all clients of this window.
|
||||
void BroadcastWholeWindow(void);
|
||||
|
||||
/// Sends the progressbar to all clients of this window
|
||||
void BroadcastInventoryProgress(short a_Progressbar, short a_Value);
|
||||
|
||||
// tolua_begin
|
||||
@@ -194,6 +203,7 @@ protected:
|
||||
class cCraftingWindow :
|
||||
public cWindow
|
||||
{
|
||||
typedef cWindow super;
|
||||
public:
|
||||
cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||
} ;
|
||||
@@ -205,6 +215,7 @@ public:
|
||||
class cFurnaceWindow :
|
||||
public cWindow
|
||||
{
|
||||
typedef cWindow super;
|
||||
public:
|
||||
cFurnaceWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cFurnaceEntity * a_Furnace);
|
||||
} ;
|
||||
@@ -216,6 +227,7 @@ public:
|
||||
class cDropSpenserWindow :
|
||||
public cWindow
|
||||
{
|
||||
typedef cWindow super;
|
||||
public:
|
||||
cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cDropSpenserEntity * a_Dispenser);
|
||||
} ;
|
||||
@@ -224,6 +236,18 @@ public:
|
||||
|
||||
|
||||
|
||||
class cHopperWindow :
|
||||
public cWindow
|
||||
{
|
||||
typedef cWindow super;
|
||||
public:
|
||||
cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper);
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cChestWindow :
|
||||
public cWindow
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user