Cuberite
A lightweight, fast and extensible game server for Minecraft
CraftingWindow.cpp
Go to the documentation of this file.
1 
2 // CraftingWindow.cpp
3 
4 // Representing the UI window for the crafting block
5 
6 #include "Globals.h"
7 #include "CraftingWindow.h"
8 #include "SlotArea.h"
9 
10 
11 
12 
13 cCraftingWindow::cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ) :
14  cWindow(wtWorkbench, "Crafting Table")
15 {
16  m_SlotAreas.push_back(new cSlotAreaCrafting(3, *this));
17  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
18  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
19 }
20 
21 
22 
23 
24 
25 void cCraftingWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
26 {
27  cSlotAreas AreasInOrder;
28 
29  if (a_ClickedArea == m_SlotAreas[0])
30  {
31  // Crafting Area
32  if (a_Slot == 0)
33  {
34  // Result Slot
35  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
36  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
37  }
38  else
39  {
40  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
41  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
42  }
43  super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, (a_Slot == 0));
44  }
45  else if (a_ClickedArea == m_SlotAreas[1])
46  {
47  // Inventory Area
48  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
49  super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
50  }
51  else
52  {
53  // Hotbar
54  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
55  super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
56  }
57 }
58 
59 
60 
61 
Handles the main inventory of each player, excluding the armor and hotbar.
Definition: SlotArea.h:117
Definition: Player.h:27
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:401
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...
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
cCraftingWindow(int a_BlockX, int a_BlockY, int a_BlockZ)
Represents a UI window.
Definition: Window.h:53
cSlotAreas m_SlotAreas
Definition: Window.h:182
Handles the hotbar of each player.
Definition: SlotArea.h:134
Definition: Item.h:36