Cuberite
A lightweight, fast and extensible game server for Minecraft
WindowOwner.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../BlockEntities/BlockEntity.h"
4 #include "../Entities/Entity.h"
5 #include "Window.h"
6 
7 /* Being a descendant of cWindowOwner means that the class can own one window. That window can be
8 queried, opened by other players, closed by players and finally destroyed.
9 Also, a cWindowOwner can be queried for the block coords where the window is displayed. That will be used
10 for entities / players in motion to close their windows when they get too far away from the window "source". */
11 
12 
13 
14 
15 
18 {
19 public:
21  m_Window(nullptr)
22  {
23  }
24 
25  virtual ~cWindowOwner()
26  {
27  }
28 
29  void CloseWindow(void)
30  {
31  m_Window = nullptr;
32  }
33 
34  void OpenWindow(cWindow * a_Window)
35  {
36  m_Window = a_Window;
37  m_Window->SetOwner(this);
38  }
39 
40  cWindow * GetWindow(void) const
41  {
42  return m_Window;
43  }
44 
46  virtual Vector3i GetBlockPos(void) = 0;
47 
48 private:
50 };
51 
52 
53 
54 
55 
58  public cWindowOwner
59 {
60 public:
62  m_BlockEntity(a_BlockEntity)
63  {
64  }
65 
66  virtual Vector3i GetBlockPos(void) override
67  {
69  }
70 
71 private:
73 };
74 
75 
76 
77 
78 
81  public cWindowOwner
82 {
83 public:
85  m_Entity(a_Entity)
86  {
87  }
88 
89  virtual Vector3i GetBlockPos(void) override
90  {
91  return m_Entity->GetPosition().Floor();
92  }
93 
94 private:
96 };
97 
98 
99 
100 
Vector3< int > Vector3i
Definition: Vector3.h:487
int GetPosZ() const
Definition: BlockEntity.h:93
int GetPosY() const
Definition: BlockEntity.h:92
int GetPosX() const
Definition: BlockEntity.h:91
Definition: Entity.h:76
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
Represents a UI window.
Definition: Window.h:54
void SetOwner(cWindowOwner *a_Owner)
Definition: Window.h:87
Base class for the window owning.
Definition: WindowOwner.h:18
cWindow * m_Window
Definition: WindowOwner.h:49
cWindow * GetWindow(void) const
Definition: WindowOwner.h:40
void CloseWindow(void)
Definition: WindowOwner.h:29
virtual ~cWindowOwner()
Definition: WindowOwner.h:25
void OpenWindow(cWindow *a_Window)
Definition: WindowOwner.h:34
virtual Vector3i GetBlockPos(void)=0
Returns the block position at which the element owning the window is.
Window owner that is associated with a block entity (chest, furnace, ...)
Definition: WindowOwner.h:59
cBlockEntity * m_BlockEntity
Definition: WindowOwner.h:72
cBlockEntityWindowOwner(cBlockEntity *a_BlockEntity)
Definition: WindowOwner.h:61
virtual Vector3i GetBlockPos(void) override
Returns the block position at which the element owning the window is.
Definition: WindowOwner.h:66
Window owner that is associated with an entity (chest minecart etc.)
Definition: WindowOwner.h:82
virtual Vector3i GetBlockPos(void) override
Returns the block position at which the element owning the window is.
Definition: WindowOwner.h:89
cEntity * m_Entity
Definition: WindowOwner.h:95
cEntityWindowOwner(cEntity *a_Entity)
Definition: WindowOwner.h:84
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
Definition: Vector3.h:177