Cuberite
A lightweight, fast and extensible game server for Minecraft
BeaconWindow.cpp
Go to the documentation of this file.
1 
2 // BeaconWindow.cpp
3 
4 // Representing the UI window for the beacon block
5 
6 #include "Globals.h"
7 #include "BeaconWindow.h"
8 #include "SlotArea.h"
9 #include "../BlockEntities/BeaconEntity.h"
10 #include "../ClientHandle.h"
11 
12 
13 
14 
15 
17  cWindow(wtBeacon, "Beacon"),
18  m_Beacon(a_Beacon)
19 {
20  m_SlotAreas.push_back(new cSlotAreaBeacon(m_Beacon, *this));
21  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
22  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
23 }
24 
25 
26 
27 
28 
29 void cBeaconWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
30 {
31  cSlotAreas AreasInOrder;
32 
33  if (a_ClickedArea == m_SlotAreas[0])
34  {
35  // Beacon Area
36  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
37  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
38  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
39  }
40  else
41  {
42  if (cSlotAreaBeacon::IsPlaceableItem(a_ItemStack.m_ItemType) && (a_ItemStack.m_ItemCount == 1))
43  {
44  AreasInOrder.push_back(m_SlotAreas[0]); /* Beacon */
45  }
46 
47  if (a_ClickedArea == m_SlotAreas[1])
48  {
49  // Inventory Area
50  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
51  }
52  else
53  {
54  // Hotbar Area
55  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
56  }
57  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
58  }
59 }
60 
61 
62 
63 
64 
66 {
67  Super::OpenedByPlayer(a_Player);
68 
70  a_Player.GetClientHandle()->SendWindowProperty(*this, 1, static_cast<short>(m_Beacon->GetPrimaryEffect()));
71  a_Player.GetClientHandle()->SendWindowProperty(*this, 2, static_cast<short>(m_Beacon->GetSecondaryEffect()));
72 }
73 
74 
75 
76 
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
cEntityEffect::eType GetPrimaryEffect(void) const
Definition: BeaconEntity.h:48
char GetBeaconLevel(void) const
Returns the beacon level.
Definition: BeaconEntity.h:46
cEntityEffect::eType GetSecondaryEffect(void) const
Definition: BeaconEntity.h:49
void SendWindowProperty(const cWindow &a_Window, size_t a_Property, short a_Value)
Definition: Player.h:29
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
Definition: Item.h:37
char m_ItemCount
Definition: Item.h:164
short m_ItemType
Definition: Item.h:163
virtual void OpenedByPlayer(cPlayer &a_Player) override
cBeaconEntity * m_Beacon
Definition: BeaconWindow.h:35
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...
cBeaconWindow(cBeaconEntity *a_Beacon)
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
static bool IsPlaceableItem(short a_ItemType)
Definition: SlotArea.cpp:1311
Represents a UI window.
Definition: Window.h:54
virtual void OpenedByPlayer(cPlayer &a_Player)
Definition: Window.cpp:284
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