From 082573771f469cfaef03d22e4281f207beef36c8 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 14 Nov 2013 15:37:09 +0100 Subject: Added cSignEntity into API, added cChunkDesc:GetBlockEntity(). This fixes both #228 and #347. --- source/BlockEntities/SignEntity.cpp | 62 +++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'source/BlockEntities/SignEntity.cpp') diff --git a/source/BlockEntities/SignEntity.cpp b/source/BlockEntities/SignEntity.cpp index 2c160e603..8b335651d 100644 --- a/source/BlockEntities/SignEntity.cpp +++ b/source/BlockEntities/SignEntity.cpp @@ -1,21 +1,19 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +// SignEntity.cpp -#include "SignEntity.h" - -#include "../Entities/Player.h" -// #include "ClientHandle.h" -// #include "World.h" -// #include "Root.h" +// Implements the cSignEntity class representing a single sign in the world +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include +#include "SignEntity.h" +#include "../Entities/Player.h" -cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World) - : cBlockEntity(a_BlockType, a_X, a_Y, a_Z, a_World) +cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ) : + super(a_BlockType, a_BlockX, a_BlockY, a_BlockZ, NULL) { } @@ -23,7 +21,8 @@ cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorl -cSignEntity::~cSignEntity() +cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World) : + super(a_BlockType, a_X, a_Y, a_Z, a_World) { } @@ -32,16 +31,16 @@ cSignEntity::~cSignEntity() // It don't do anything when 'used' -void cSignEntity::UsedBy( cPlayer * a_Player ) +void cSignEntity::UsedBy(cPlayer * a_Player) { - (void)a_Player; + UNUSED(a_Player); } -void cSignEntity::SetLines( const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4 ) +void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) { m_Line[0] = a_Line1; m_Line[1] = a_Line2; @@ -53,25 +52,28 @@ void cSignEntity::SetLines( const AString & a_Line1, const AString & a_Line2, co -void cSignEntity::SetLine( int a_Index, const AString & a_Line ) +void cSignEntity::SetLine(int a_Index, const AString & a_Line) { - if( a_Index < 4 && a_Index > -1 ) + if ((a_Index < 0) || (a_Index >= ARRAYCOUNT(m_Line))) { - m_Line[a_Index] = a_Line; + LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str()); + return; } + m_Line[a_Index] = a_Line; } -AString cSignEntity::GetLine( int a_Index ) const +AString cSignEntity::GetLine(int a_Index) const { - if( a_Index < 4 && a_Index > -1 ) + if ((a_Index < 0) || (a_Index >= ARRAYCOUNT(m_Line))) { - return m_Line[a_Index]; + LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index); + return ""; } - return ""; + return m_Line[a_Index]; } @@ -87,19 +89,7 @@ void cSignEntity::SendTo(cClientHandle & a_Client) -#define READ(File, Var) \ - if (File.Read(&Var, sizeof(Var)) != sizeof(Var)) \ - { \ - LOGERROR("ERROR READING cSignEntity %s FROM FILE (line %d)", #Var, __LINE__); \ - return false; \ - } - - - - - - -bool cSignEntity::LoadFromJson( const Json::Value & a_Value ) +bool cSignEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); m_PosY = a_Value.get("y", 0).asInt(); @@ -113,7 +103,11 @@ bool cSignEntity::LoadFromJson( const Json::Value & a_Value ) return true; } -void cSignEntity::SaveToJson( Json::Value & a_Value ) + + + + +void cSignEntity::SaveToJson(Json::Value & a_Value) { a_Value["x"] = m_PosX; a_Value["y"] = m_PosY; -- cgit v1.2.3 From ebb2ccaa267116106002f358e18c5af58e13ec34 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 15 Nov 2013 09:36:43 +0100 Subject: Removed BlockEntities' constructors from the API. Plugins shouldn't construct block entities, rather, they will query them either from the cWorld (while playing), or from cChunkDesc (while generating). --- source/BlockEntities/SignEntity.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source/BlockEntities/SignEntity.cpp') diff --git a/source/BlockEntities/SignEntity.cpp b/source/BlockEntities/SignEntity.cpp index 8b335651d..81f6f6d77 100644 --- a/source/BlockEntities/SignEntity.cpp +++ b/source/BlockEntities/SignEntity.cpp @@ -12,15 +12,6 @@ -cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ) : - super(a_BlockType, a_BlockX, a_BlockY, a_BlockZ, NULL) -{ -} - - - - - cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World) : super(a_BlockType, a_X, a_Y, a_Z, a_World) { -- cgit v1.2.3 From 675b4aa878f16291ce33fced48a2bc7425f635ae Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 24 Nov 2013 14:19:41 +0000 Subject: Moved source to src --- source/BlockEntities/SignEntity.cpp | 115 ------------------------------------ 1 file changed, 115 deletions(-) delete mode 100644 source/BlockEntities/SignEntity.cpp (limited to 'source/BlockEntities/SignEntity.cpp') diff --git a/source/BlockEntities/SignEntity.cpp b/source/BlockEntities/SignEntity.cpp deleted file mode 100644 index 81f6f6d77..000000000 --- a/source/BlockEntities/SignEntity.cpp +++ /dev/null @@ -1,115 +0,0 @@ - -// SignEntity.cpp - -// Implements the cSignEntity class representing a single sign in the world - -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules -#include -#include "SignEntity.h" -#include "../Entities/Player.h" - - - - - -cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World) : - super(a_BlockType, a_X, a_Y, a_Z, a_World) -{ -} - - - - - -// It don't do anything when 'used' -void cSignEntity::UsedBy(cPlayer * a_Player) -{ - UNUSED(a_Player); -} - - - - - -void cSignEntity::SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) -{ - m_Line[0] = a_Line1; - m_Line[1] = a_Line2; - m_Line[2] = a_Line3; - m_Line[3] = a_Line4; -} - - - - - -void cSignEntity::SetLine(int a_Index, const AString & a_Line) -{ - if ((a_Index < 0) || (a_Index >= ARRAYCOUNT(m_Line))) - { - LOGWARNING("%s: setting a non-existent line %d (value \"%s\"", __FUNCTION__, a_Index, a_Line.c_str()); - return; - } - m_Line[a_Index] = a_Line; -} - - - - - -AString cSignEntity::GetLine(int a_Index) const -{ - if ((a_Index < 0) || (a_Index >= ARRAYCOUNT(m_Line))) - { - LOGWARNING("%s: requesting a non-existent line %d", __FUNCTION__, a_Index); - return ""; - } - return m_Line[a_Index]; -} - - - - - -void cSignEntity::SendTo(cClientHandle & a_Client) -{ - a_Client.SendUpdateSign(m_PosX, m_PosY, m_PosZ, m_Line[0], m_Line[1], m_Line[2], m_Line[3]); -} - - - - - -bool cSignEntity::LoadFromJson(const Json::Value & a_Value) -{ - m_PosX = a_Value.get("x", 0).asInt(); - m_PosY = a_Value.get("y", 0).asInt(); - m_PosZ = a_Value.get("z", 0).asInt(); - - m_Line[0] = a_Value.get("Line1", "").asString(); - m_Line[1] = a_Value.get("Line2", "").asString(); - m_Line[2] = a_Value.get("Line3", "").asString(); - m_Line[3] = a_Value.get("Line4", "").asString(); - - return true; -} - - - - - -void cSignEntity::SaveToJson(Json::Value & a_Value) -{ - a_Value["x"] = m_PosX; - a_Value["y"] = m_PosY; - a_Value["z"] = m_PosZ; - - a_Value["Line1"] = m_Line[0]; - a_Value["Line2"] = m_Line[1]; - a_Value["Line3"] = m_Line[2]; - a_Value["Line4"] = m_Line[3]; -} - - - - -- cgit v1.2.3