Cuberite
A lightweight, fast and extensible game server for Minecraft
EnderChestWindow.cpp
Go to the documentation of this file.
1 
2 // EnderChestWindow.cpp
3 
4 // Representing the UI window for the enderchest block
5 
6 #include "Globals.h"
7 #include "../World.h"
8 #include "EnderChestWindow.h"
9 #include "SlotArea.h"
10 
11 
12 
13 
14 
16  cWindow(wtChest, "Ender Chest"),
17  m_World(a_EnderChest->GetWorld()),
18  m_BlockPos(a_EnderChest->GetPos())
19 {
20  m_SlotAreas.push_back(new cSlotAreaEnderChest(a_EnderChest, *this));
21  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
22  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
23 
24  // Play the opening sound:
26  "block.enderchest.open",
27  m_BlockPos,
28  1,
29  1
30  );
31 
32  // Send out the chest-open packet:
34 }
35 
36 
37 
38 
39 
41 {
42  // Send out the chest-close packet:
44 
45  // Play the closing sound
47  "block.enderchest.close",
48  m_BlockPos,
49  1, 1
50  );
51 }
52 
53 
54 
55 
56 
57 void cEnderChestWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
58 {
59  cSlotAreas AreasInOrder;
60 
61  if (a_ClickedArea == m_SlotAreas[0])
62  {
63  // Chest Area
64  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
65  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
66  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
67  }
68  else
69  {
70  // Hotbar or Inventory
71  AreasInOrder.push_back(m_SlotAreas[0]); /* Chest */
72  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
73  }
74 }
75 
76 
77 
78 
@ E_BLOCK_ENDER_CHEST
Definition: BlockType.h:145
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
Definition: Player.h:29
Definition: Item.h:37
virtual ~cEnderChestWindow() override
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...
cEnderChestWindow(cEnderChestEntity *a_EnderChest)
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
virtual void BroadcastBlockAction(Vector3i a_BlockPos, Byte a_Byte1, Byte a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override