Cuberite
A lightweight, fast and extensible game server for Minecraft
SignEntity.cpp
Go to the documentation of this file.
1 
2 // SignEntity.cpp
3 
4 // Implements the cSignEntity class representing a single sign in the world
5 
6 #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
7 #include "json/value.h"
8 #include "SignEntity.h"
9 #include "../ClientHandle.h"
10 
11 
12 
13 
14 
15 cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World):
16  super(a_BlockType, a_BlockMeta, a_Pos, a_World)
17 {
18  ASSERT((a_BlockType == E_BLOCK_WALLSIGN) || (a_BlockType == E_BLOCK_SIGN_POST));
20 }
21 
22 
23 
24 
25 
27 {
28  super::CopyFrom(a_Src);
29  auto & src = static_cast<const cSignEntity &>(a_Src);
30  for (size_t i = 0; i < ARRAYCOUNT(m_Line); ++i)
31  {
32  m_Line[i] = src.m_Line[i];
33  }
34 }
35 
36 
37 
38 
39 
40 bool cSignEntity::UsedBy(cPlayer * a_Player)
41 {
42  UNUSED(a_Player);
43  return true;
44 }
45 
46 
47 
48 
49 
50 void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
51 {
52  m_Line[0] = a_Line1;
53  m_Line[1] = a_Line2;
54  m_Line[2] = a_Line3;
55  m_Line[3] = a_Line4;
56 }
57 
58 
59 
60 
61 
62 void cSignEntity::SetLine(int a_Index, const AString & a_Line)
63 {
64  if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
65  {
66  LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str());
67  return;
68  }
69  m_Line[a_Index] = a_Line;
70 }
71 
72 
73 
74 
75 
76 AString cSignEntity::GetLine(int a_Index) const
77 {
78  if ((a_Index < 0) || (a_Index >= static_cast<int>(ARRAYCOUNT(m_Line))))
79  {
80  LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index);
81  return "";
82  }
83  return m_Line[a_Index];
84 }
85 
86 
87 
88 
89 
91 {
92  a_Client.SendUpdateSign(m_Pos.x, m_Pos.y, m_Pos.z, m_Line[0], m_Line[1], m_Line[2], m_Line[3]);
93 }
T x
Definition: Vector3.h:17
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
Definition: SignEntity.cpp:90
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
static bool IsValidHeight(int a_Height)
Validates a height-coordinate.
Definition: ChunkDef.h:212
Definition: Player.h:27
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
T y
Definition: Vector3.h:17
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
Definition: SignEntity.cpp:26
AString GetLine(int a_Index) const
Retrieves individual line (zero-based index)
Definition: SignEntity.cpp:76
T z
Definition: Vector3.h:17
void SetLines(const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
Sets all the sign&#39;s lines.
Definition: SignEntity.cpp:50
cSignEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Creates a new empty sign entity at the specified block coords and block type (wall or standing)...
Definition: SignEntity.cpp:15
void SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
Definition: World.h:65
#define ASSERT(x)
Definition: Globals.h:335
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:174
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:142
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
#define UNUSED
Definition: Globals.h:152
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
Definition: SignEntity.cpp:40
std::string AString
Definition: StringUtils.h:13
void SetLine(int a_Index, const AString &a_Line)
Sets individual line (zero-based index)
Definition: SignEntity.cpp:62
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:290
AString m_Line[4]
Definition: SignEntity.h:53