Cuberite
A lightweight, fast and extensible game server for Minecraft
HopperWindow.cpp
Go to the documentation of this file.
1 
2 // HopperWindow.cpp
3 
4 // Representing the UI window for the hopper block
5 
6 #include "Globals.h"
7 #include "../BlockEntities/HopperEntity.h"
8 #include "HopperWindow.h"
9 #include "../BlockEntities/DropperEntity.h"
10 #include "SlotArea.h"
11 
12 
13 
14 
15 
17  Super(wtHopper, "Hopper")
18 {
19  m_SlotAreas.push_back(new cSlotAreaItemGrid(a_Hopper->GetContents(), *this));
20  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
21  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
22 }
23 
24 
25 
26 
27 
28 void cHopperWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
29 {
30  cSlotAreas AreasInOrder;
31 
32  if (a_ClickedArea == m_SlotAreas[0])
33  {
34  // Hopper Area
35  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
36  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
37  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
38  }
39  else
40  {
41  // Inventory or Hotbar
42  AreasInOrder.push_back(m_SlotAreas[0]); /* Hopper */
43  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
44  }
45 }
46 
47 
48 
49 
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
cItemGrid & GetContents(void)
Returns the ItemGrid used for storing the contents.
Definition: Player.h:29
Definition: Item.h:37
cHopperWindow(cHopperEntity *a_Hopper)
virtual void DistributeStack(cItem &a_ItemStack, int a_Slot, cPlayer &a_Player, cSlotArea *a_ClickedArea, bool a_ShouldApply) override
Called on shift-clicking to distribute the stack into other areas; Modifies a_ItemStack as it is dist...
Handles the main inventory of each player, excluding the armor and hotbar.
Definition: SlotArea.h:120
Handles the hotbar of each player.
Definition: SlotArea.h:138
Handles any slot area that is representing a cItemGrid; same items for all the players.
Definition: SlotArea.h:200
Represents a UI window.
Definition: Window.h:54
void DistributeStackToAreas(cItem &a_ItemStack, cPlayer &a_Player, cSlotAreas &a_AreasInOrder, bool a_ShouldApply, bool a_BackFill)
Called from DistributeStack() to distribute the stack into a_AreasInOrder; Modifies a_ItemStack as it...
Definition: Window.cpp:467
cSlotAreas m_SlotAreas
Definition: Window.h:179