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 
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 
62 
63 void cCraftingWindow::LoadRecipe(cPlayer & a_Player, UInt32 a_RecipeId)
64 {
65  auto slotAreaCrafting = static_cast<cSlotAreaCrafting *>(m_SlotAreas[0]);
66  slotAreaCrafting->LoadRecipe(a_Player, a_RecipeId);
67 }
unsigned int UInt32
Definition: Globals.h:157
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
Definition: Player.h:29
Definition: Item.h:37
void LoadRecipe(cPlayer &a_Player, UInt32 a_RecipeId)
Loads the given Recipe into the crafting grid.
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
void LoadRecipe(cPlayer &a_Player, UInt32 a_RecipeId)
Loads the given Recipe into the crafting grid.
Definition: SlotArea.cpp:784
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