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  {
68  return Vector3i(m_BlockEntity->GetPosX(), m_BlockEntity->GetPosY(), m_BlockEntity->GetPosZ());
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 > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector&#39;s coords.
Definition: Vector3.h:172
virtual Vector3i GetBlockPos(void)=0
Returns the block position at which the element owning the window is.
cBlockEntityWindowOwner(cBlockEntity *a_BlockEntity)
Definition: WindowOwner.h:61
cEntityWindowOwner(cEntity *a_Entity)
Definition: WindowOwner.h:84
void SetOwner(cWindowOwner *a_Owner)
Definition: Window.h:87
void CloseWindow(void)
Definition: WindowOwner.h:29
void OpenWindow(cWindow *a_Window)
Definition: WindowOwner.h:34
virtual ~cWindowOwner()
Definition: WindowOwner.h:25
cWindow * GetWindow(void) const
Definition: WindowOwner.h:40
Base class for the window owning.
Definition: WindowOwner.h:17
cBlockEntity * m_BlockEntity
Definition: WindowOwner.h:72
cEntity * m_Entity
Definition: WindowOwner.h:95
Window owner that is associated with a block entity (chest, furnace, ...)
Definition: WindowOwner.h:57
virtual Vector3i GetBlockPos(void) override
Returns the block position at which the element owning the window is.
Definition: WindowOwner.h:89
Definition: Entity.h:73
Represents a UI window.
Definition: Window.h:53
Vector3< int > Vector3i
Definition: Vector3.h:447
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:80
cWindow * m_Window
Definition: WindowOwner.h:49