Cuberite
A lightweight, fast and extensible game server for Minecraft
FurnaceWindow.cpp
Go to the documentation of this file.
1 
2 // FurnaceWindow.cpp
3 
4 // Representing the UI window for the furnace block
5 
6 #include "Globals.h"
7 #include "FurnaceWindow.h"
8 #include "SlotArea.h"
9 #include "../FurnaceRecipe.h"
10 #include "../Root.h"
11 
12 
13 
14 
15 
17  cWindow(wtFurnace, "Furnace")
18 {
19  m_SlotAreas.push_back(new cSlotAreaFurnace(a_Furnace, *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 cFurnaceWindow::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  // Furnace Area
35  if (a_Slot == 2)
36  {
37  // Result Slot
38  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
39  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
40  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
41  }
42  else
43  {
44  // Furnace Input / Fuel Slot
45  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
46  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
47  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
48  }
49  }
50  else
51  {
52  cFurnaceRecipe * FurnaceRecipes = cRoot::Get()->GetFurnaceRecipe();
53  if ((FurnaceRecipes->GetRecipeFrom(a_ItemStack) != nullptr) || (FurnaceRecipes->IsFuel(a_ItemStack)))
54  {
55  // The item is a valid input item or fuel
56  AreasInOrder.push_back(m_SlotAreas[0]); /* Furnace Area */
57  }
58  else if (a_ClickedArea == m_SlotAreas[1])
59  {
60  // Inventory Area
61  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
62  }
63  else
64  {
65  // Hotbar Area
66  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
67  }
68  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
69  }
70 }
71 
72 
73 
74 
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
Definition: Player.h:29
const cRecipe * GetRecipeFrom(const cItem &a_Ingredient) const
Returns a recipe for the specified input, nullptr if no recipe found.
bool IsFuel(const cItem &a_Item) const
Returns true if the item is a fuel, false if not.
Definition: Item.h:37
static cRoot * Get()
Definition: Root.h:52
cFurnaceRecipe * GetFurnaceRecipe(void)
Definition: Root.h:94
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...
cFurnaceWindow(cFurnaceEntity *a_Furnace)
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
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