Cuberite
A lightweight, fast and extensible game server for Minecraft
MinecartWithChestWindow.h
Go to the documentation of this file.
1 
2 // MinecartWithChestWindow.h
3 
4 // Representing the UI window for the minecart chest entity
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "Window.h"
13 #include "../Entities/Minecart.h"
14 
15 
16 
17 
18 
20  public cWindow
21 {
22  using Super = cWindow;
23 
24 public:
25 
27  cWindow(wtChest, "Minecart with Chest"),
28  m_ChestCart(a_ChestCart)
29  {
30  m_SlotAreas.push_back(new cSlotAreaMinecartWithChest(a_ChestCart, *this));
31  m_SlotAreas.push_back(new cSlotAreaInventory(*this));
32  m_SlotAreas.push_back(new cSlotAreaHotBar(*this));
33 
34  a_ChestCart->GetWorld()->BroadcastSoundEffect("block.chest.open", a_ChestCart->GetPosition(), 1, 1);
35  }
36 
37  virtual void DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply) override
38  {
39  cSlotAreas AreasInOrder;
40 
41  if (a_ClickedArea == m_SlotAreas[0])
42  {
43  // Chest Area
44  AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
45  AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
46  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
47  }
48  else
49  {
50  // Hotbar or Inventory
51  AreasInOrder.push_back(m_SlotAreas[0]); /* Chest */
52  Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
53  }
54  }
55 
56 
57  virtual ~cMinecartWithChestWindow() override
58  {
59  m_ChestCart->GetWorld()->BroadcastSoundEffect("block.chest.close", m_ChestCart->GetPosition(), 1, 1);
60  }
61 
62 private:
64 };
65 
66 
67 
68 
std::vector< cSlotArea * > cSlotAreas
Definition: Window.h:34
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
Definition: Item.h:37
cMinecartWithChest * m_ChestCart
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...
cMinecartWithChestWindow(cMinecartWithChest *a_ChestCart)
virtual ~cMinecartWithChestWindow() override
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
@ wtChest
Definition: Window.h:59
cWindow(WindowType a_WindowType, const AString &a_WindowTitle)
Definition: Window.cpp:30
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 BroadcastSoundEffect(const AString &a_SoundName, Vector3d a_Position, float a_Volume, float a_Pitch, const cClientHandle *a_Exclude=nullptr) override