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  m_Line = src.m_Line;
31 }
32 
33 
34 
35 
36 
37 bool cSignEntity::UsedBy(cPlayer * a_Player)
38 {
39  UNUSED(a_Player);
40  return true;
41 }
42 
43 
44 
45 
46 
47 void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
48 {
49  m_Line[0] = a_Line1;
50  m_Line[1] = a_Line2;
51  m_Line[2] = a_Line3;
52  m_Line[3] = a_Line4;
53 }
54 
55 
56 
57 
58 
59 void cSignEntity::SetLine(size_t a_Index, const AString & a_Line)
60 {
61  if (a_Index >= m_Line.size())
62  {
63  LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str());
64  return;
65  }
66 
67  m_Line[a_Index] = a_Line;
68 }
69 
70 
71 
72 
73 
74 AString cSignEntity::GetLine(size_t a_Index) const
75 {
76  if (a_Index >= m_Line.size())
77  {
78  LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index);
79  return "";
80  }
81 
82  return m_Line[a_Index];
83 }
84 
85 
86 
87 
88 
90 {
91  a_Client.SendUpdateSign(m_Pos, m_Line[0], m_Line[1], m_Line[2], m_Line[3]);
92 }
@ E_BLOCK_SIGN_POST
Definition: BlockType.h:76
@ E_BLOCK_WALLSIGN
Definition: BlockType.h:82
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
std::string AString
Definition: StringUtils.h:11
Vector3i m_Pos
Position in absolute block coordinates.
Definition: BlockEntity.h:113
virtual void CopyFrom(const cBlockEntity &a_Src)
Copies all properties of a_Src into this entity, except for its m_World and location.
Definition: BlockEntity.cpp:66
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
std::array< AString, 4 > m_Line
Definition: SignEntity.h:51
void SetLine(size_t a_Index, const AString &a_Line)
Sets individual line (zero-based index)
Definition: SignEntity.cpp:59
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
Definition: SignEntity.cpp:37
void SetLines(const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
Sets all the sign's lines.
Definition: SignEntity.cpp:47
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
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
Definition: SignEntity.cpp:89
AString GetLine(size_t a_Index) const
Retrieves individual line (zero-based index)
Definition: SignEntity.cpp:74
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
Definition: ChunkDef.h:185
void SendUpdateSign(Vector3i a_BlockPos, const AString &a_Line1, const AString &a_Line2, const AString &a_Line3, const AString &a_Line4)
Definition: Player.h:29
Definition: World.h:53