diff options
Diffstat (limited to '')
-rw-r--r-- | source/BlockEntities/BlockEntity.cpp | 44 | ||||
-rw-r--r-- | source/BlockEntities/BlockEntity.h | 5 | ||||
-rw-r--r-- | source/BlockEntities/ChestEntity.cpp | 10 | ||||
-rw-r--r-- | source/BlockEntities/ChestEntity.h | 4 | ||||
-rw-r--r-- | source/BlockEntities/DispenserEntity.cpp | 10 | ||||
-rw-r--r-- | source/BlockEntities/DispenserEntity.h | 3 | ||||
-rw-r--r-- | source/BlockEntities/DropperEntity.cpp | 10 | ||||
-rw-r--r-- | source/BlockEntities/DropperEntity.h | 3 | ||||
-rw-r--r-- | source/BlockEntities/FurnaceEntity.cpp | 23 | ||||
-rw-r--r-- | source/BlockEntities/FurnaceEntity.h | 3 | ||||
-rw-r--r-- | source/BlockEntities/HopperEntity.cpp | 11 | ||||
-rw-r--r-- | source/BlockEntities/HopperEntity.h | 3 | ||||
-rw-r--r-- | source/BlockEntities/JukeboxEntity.cpp | 34 | ||||
-rw-r--r-- | source/BlockEntities/JukeboxEntity.h | 31 | ||||
-rw-r--r-- | source/BlockEntities/NoteEntity.cpp | 27 | ||||
-rw-r--r-- | source/BlockEntities/NoteEntity.h | 33 | ||||
-rw-r--r-- | source/BlockEntities/SignEntity.cpp | 67 | ||||
-rw-r--r-- | source/BlockEntities/SignEntity.h | 40 |
18 files changed, 182 insertions, 179 deletions
diff --git a/source/BlockEntities/BlockEntity.cpp b/source/BlockEntities/BlockEntity.cpp new file mode 100644 index 000000000..41a488717 --- /dev/null +++ b/source/BlockEntities/BlockEntity.cpp @@ -0,0 +1,44 @@ + +// BlockEntity.cpp + +// Implements the cBlockEntity class that is the common ancestor for all block entities + +#include "Globals.h" +#include "BlockEntity.h" +#include "ChestEntity.h" +#include "DispenserEntity.h" +#include "DropperEntity.h" +#include "FurnaceEntity.h" +#include "HopperEntity.h" +#include "JukeboxEntity.h" +#include "NoteEntity.h" +#include "SignEntity.h" + + + + + +cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) +{ + switch (a_BlockType) + { + case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_DISPENSER: return new cDispenserEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World); + case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_SIGN_POST: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_WALLSIGN: return new cSignEntity (a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_NOTE_BLOCK: return new cNoteEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + case E_BLOCK_JUKEBOX: return new cJukeboxEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); + } + LOGD("%s: Requesting creation of an unknown block entity - block type %d (%s)", + __FUNCTION__, a_BlockType, ItemTypeToString(a_BlockType).c_str() + ); + return NULL; +} + + + + diff --git a/source/BlockEntities/BlockEntity.h b/source/BlockEntities/BlockEntity.h index ab7d7f5dc..a2de3160a 100644 --- a/source/BlockEntities/BlockEntity.h +++ b/source/BlockEntities/BlockEntity.h @@ -47,6 +47,11 @@ public: m_World = a_World; } + /// Creates a new block entity for the specified block type + /// If a_World is valid, then the entity is created bound to that world + /// Returns NULL for unknown block types + static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World = NULL); + // tolua_begin // Position, in absolute block coordinates: diff --git a/source/BlockEntities/ChestEntity.cpp b/source/BlockEntities/ChestEntity.cpp index 59193829d..ca2626bc9 100644 --- a/source/BlockEntities/ChestEntity.cpp +++ b/source/BlockEntities/ChestEntity.cpp @@ -11,16 +11,6 @@ -cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ) : - super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, NULL) -{ - cBlockEntityWindowOwner::SetBlockEntity(this); -} - - - - - cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_CHEST, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World) { diff --git a/source/BlockEntities/ChestEntity.h b/source/BlockEntities/ChestEntity.h index c6676894f..4f2c21e91 100644 --- a/source/BlockEntities/ChestEntity.h +++ b/source/BlockEntities/ChestEntity.h @@ -34,10 +34,6 @@ public: ContentsWidth = 9, } ; - - /// Constructor used while generating a chunk; sets m_World to NULL - cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ); - // tolua_end /// Constructor used for normal operation diff --git a/source/BlockEntities/DispenserEntity.cpp b/source/BlockEntities/DispenserEntity.cpp index 7edaa8a14..374f3d6e3 100644 --- a/source/BlockEntities/DispenserEntity.cpp +++ b/source/BlockEntities/DispenserEntity.cpp @@ -10,16 +10,6 @@ -cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ) : - super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, NULL) -{ - SetBlockEntity(this); // cBlockEntityWindowOwner -} - - - - - cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, a_World) { diff --git a/source/BlockEntities/DispenserEntity.h b/source/BlockEntities/DispenserEntity.h index 5e3327f18..fdfe4e5b4 100644 --- a/source/BlockEntities/DispenserEntity.h +++ b/source/BlockEntities/DispenserEntity.h @@ -15,9 +15,6 @@ class cDispenserEntity : public: - /// Constructor used while generating a chunk; sets m_World to NULL - cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ); - // tolua_end /// Constructor used for normal operation diff --git a/source/BlockEntities/DropperEntity.cpp b/source/BlockEntities/DropperEntity.cpp index 61127cec1..5d4a8ad97 100644 --- a/source/BlockEntities/DropperEntity.cpp +++ b/source/BlockEntities/DropperEntity.cpp @@ -12,16 +12,6 @@ -cDropperEntity::cDropperEntity(int a_BlockX, int a_BlockY, int a_BlockZ) : - super(E_BLOCK_DROPPER, a_BlockX, a_BlockY, a_BlockZ, NULL) -{ - SetBlockEntity(this); // cBlockEntityWindowOwner -} - - - - - cDropperEntity::cDropperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_DROPPER, a_BlockX, a_BlockY, a_BlockZ, a_World) { diff --git a/source/BlockEntities/DropperEntity.h b/source/BlockEntities/DropperEntity.h index af74e7f7c..8e07bc6f8 100644 --- a/source/BlockEntities/DropperEntity.h +++ b/source/BlockEntities/DropperEntity.h @@ -23,9 +23,6 @@ class cDropperEntity : public: - /// Constructor used while generating a chunk; sets m_World to NULL - cDropperEntity(int a_BlockX, int a_BlockY, int a_BlockZ); - // tolua_end /// Constructor used for normal operation diff --git a/source/BlockEntities/FurnaceEntity.cpp b/source/BlockEntities/FurnaceEntity.cpp index 2f548d003..ec5ebe8b9 100644 --- a/source/BlockEntities/FurnaceEntity.cpp +++ b/source/BlockEntities/FurnaceEntity.cpp @@ -23,27 +23,6 @@ enum -cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) : - super(E_BLOCK_FURNACE, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, NULL), - m_BlockType(a_BlockType), - m_BlockMeta(a_BlockMeta), - m_CurrentRecipe(NULL), - m_IsCooking(false), - m_NeedCookTime(0), - m_TimeCooked(0), - m_FuelBurnTime(0), - m_TimeBurned(0), - m_LastProgressFuel(0), - m_LastProgressCook(0) -{ - SetBlockEntity(this); // cBlockEntityWindowOwner - m_Contents.AddListener(*this); -} - - - - - cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cWorld * a_World) : super(E_BLOCK_FURNACE, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World), m_BlockType(a_BlockType), @@ -57,7 +36,7 @@ cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY m_LastProgressFuel(0), m_LastProgressCook(0) { - SetBlockEntity(this); // cBlockEntityWindowOwner + cBlockEntityWindowOwner::SetBlockEntity(this); m_Contents.AddListener(*this); } diff --git a/source/BlockEntities/FurnaceEntity.h b/source/BlockEntities/FurnaceEntity.h index 038f60600..9464fd175 100644 --- a/source/BlockEntities/FurnaceEntity.h +++ b/source/BlockEntities/FurnaceEntity.h @@ -39,9 +39,6 @@ public: ContentsHeight = 1, }; - /// Constructor used while generating a chunk; sets m_World to NULL - cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); - // tolua_end /// Constructor used for normal operation diff --git a/source/BlockEntities/HopperEntity.cpp b/source/BlockEntities/HopperEntity.cpp index c3d7ed3ba..41849b1b3 100644 --- a/source/BlockEntities/HopperEntity.cpp +++ b/source/BlockEntities/HopperEntity.cpp @@ -16,17 +16,6 @@ -cHopperEntity::cHopperEntity(int a_BlockX, int a_BlockY, int a_BlockZ) : - super(E_BLOCK_HOPPER, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, NULL), - m_LastMoveItemsInTick(0), - m_LastMoveItemsOutTick(0) -{ -} - - - - - cHopperEntity::cHopperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : super(E_BLOCK_HOPPER, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World), m_LastMoveItemsInTick(0), diff --git a/source/BlockEntities/HopperEntity.h b/source/BlockEntities/HopperEntity.h index 1a7650581..3eaa05b7c 100644 --- a/source/BlockEntities/HopperEntity.h +++ b/source/BlockEntities/HopperEntity.h @@ -30,9 +30,6 @@ public: TICKS_PER_TRANSFER = 8, ///< How many ticks at minimum between two item transfers to or from the hopper } ; - /// Constructor used while generating a chunk; sets m_World to NULL - cHopperEntity(int a_BlockX, int a_BlockY, int a_BlockZ); - // tolua_end /// Constructor used for normal operation diff --git a/source/BlockEntities/JukeboxEntity.cpp b/source/BlockEntities/JukeboxEntity.cpp index 1288719f6..aca376dd3 100644 --- a/source/BlockEntities/JukeboxEntity.cpp +++ b/source/BlockEntities/JukeboxEntity.cpp @@ -9,9 +9,9 @@ -cJukeboxEntity::cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) - : cBlockEntity(E_BLOCK_JUKEBOX, a_BlockX, a_BlockY, a_BlockZ, a_World) - , m_Record( 0 ) +cJukeboxEntity::cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_JUKEBOX, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Record(0) { } @@ -21,11 +21,7 @@ cJukeboxEntity::cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld cJukeboxEntity::~cJukeboxEntity() { - if (m_Record >= 2256 && m_Record <= 2267) - { - EjectRecord(); - m_Record = 0; - } + EjectRecord(); } @@ -44,10 +40,9 @@ void cJukeboxEntity::UsedBy(cPlayer * a_Player) PlayRecord(); } } - else if (m_Record >= 2256 && m_Record <= 2267) + else { EjectRecord(); - m_Record = 0; } } @@ -55,7 +50,7 @@ void cJukeboxEntity::UsedBy(cPlayer * a_Player) -void cJukeboxEntity::PlayRecord( void ) +void cJukeboxEntity::PlayRecord(void) { m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, m_Record); } @@ -64,19 +59,26 @@ void cJukeboxEntity::PlayRecord( void ) -void cJukeboxEntity::EjectRecord( void ) +void cJukeboxEntity::EjectRecord(void) { + if ((m_Record < E_ITEM_FIRST_DISC) || (m_Record > E_ITEM_LAST_DISC)) + { + // There's no record here + return; + } + cItems Drops; Drops.push_back(cItem(m_Record, 1, 0)); m_World->SpawnItemPickups(Drops, m_PosX + 0.5, m_PosY + 1, m_PosZ + 0.5, 8); m_World->BroadcastSoundParticleEffect(1005, m_PosX, m_PosY, m_PosZ, 0); + m_Record = 0; } -int cJukeboxEntity::GetRecord( void ) +int cJukeboxEntity::GetRecord(void) { return m_Record; } @@ -85,7 +87,7 @@ int cJukeboxEntity::GetRecord( void ) -void cJukeboxEntity::SetRecord( int a_Record ) +void cJukeboxEntity::SetRecord(int a_Record) { m_Record = a_Record; } @@ -94,7 +96,7 @@ void cJukeboxEntity::SetRecord( int a_Record ) -bool cJukeboxEntity::LoadFromJson( const Json::Value & a_Value ) +bool cJukeboxEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); m_PosY = a_Value.get("y", 0).asInt(); @@ -109,7 +111,7 @@ bool cJukeboxEntity::LoadFromJson( const Json::Value & a_Value ) -void cJukeboxEntity::SaveToJson( Json::Value & a_Value ) +void cJukeboxEntity::SaveToJson(Json::Value & a_Value) { a_Value["x"] = m_PosX; a_Value["y"] = m_PosY; diff --git a/source/BlockEntities/JukeboxEntity.h b/source/BlockEntities/JukeboxEntity.h index 38574c945..fcafdc479 100644 --- a/source/BlockEntities/JukeboxEntity.h +++ b/source/BlockEntities/JukeboxEntity.h @@ -17,26 +17,39 @@ namespace Json +// tolua_begin + class cJukeboxEntity : public cBlockEntity { + typedef cBlockEntity super; public: + + // tolua_end + cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); virtual ~cJukeboxEntity(); - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson( Json::Value& a_Value ) override; - - int GetRecord( void ); - void SetRecord( int a_Record ); - void PlayRecord( void ); - void EjectRecord( void ); - virtual void UsedBy( cPlayer * a_Player ) override; + bool LoadFromJson(const Json::Value & a_Value); + virtual void SaveToJson(Json::Value & a_Value) override; + + // tolua_begin + + int GetRecord(void); + void SetRecord(int a_Record); + void PlayRecord(void); + + /// Ejects the currently held record as a pickup. Does nothing when no record inserted. + void EjectRecord(void); + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override { }; private: int m_Record; -}; +} ; // tolua_end diff --git a/source/BlockEntities/NoteEntity.cpp b/source/BlockEntities/NoteEntity.cpp index 6dc0e20a1..1b0620299 100644 --- a/source/BlockEntities/NoteEntity.cpp +++ b/source/BlockEntities/NoteEntity.cpp @@ -6,17 +6,12 @@ #include <json/json.h> -cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) - : cBlockEntity(E_BLOCK_NOTE_BLOCK, a_BlockX, a_BlockY, a_BlockZ, a_World) - , m_Pitch( 0 ) -{ -} - - -cNoteEntity::~cNoteEntity() +cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) : + super(E_BLOCK_NOTE_BLOCK, a_BlockX, a_BlockY, a_BlockZ, a_World), + m_Pitch(0) { } @@ -24,7 +19,7 @@ cNoteEntity::~cNoteEntity() -void cNoteEntity::UsedBy( cPlayer * a_Player ) +void cNoteEntity::UsedBy(cPlayer * a_Player) { IncrementPitch(); MakeSound(); @@ -34,7 +29,7 @@ void cNoteEntity::UsedBy( cPlayer * a_Player ) -void cNoteEntity::MakeSound( void ) +void cNoteEntity::MakeSound(void) { char instrument; AString sampleName; @@ -102,7 +97,7 @@ void cNoteEntity::MakeSound( void ) -char cNoteEntity::GetPitch( void ) +char cNoteEntity::GetPitch(void) { return m_Pitch; } @@ -111,7 +106,7 @@ char cNoteEntity::GetPitch( void ) -void cNoteEntity::SetPitch( char a_Pitch ) +void cNoteEntity::SetPitch(char a_Pitch) { m_Pitch = a_Pitch % 25; } @@ -120,16 +115,16 @@ void cNoteEntity::SetPitch( char a_Pitch ) -void cNoteEntity::IncrementPitch( void ) +void cNoteEntity::IncrementPitch(void) { - SetPitch( m_Pitch + 1 ); + SetPitch(m_Pitch + 1); } -bool cNoteEntity::LoadFromJson( const Json::Value & a_Value ) +bool cNoteEntity::LoadFromJson(const Json::Value & a_Value) { m_PosX = a_Value.get("x", 0).asInt(); @@ -145,7 +140,7 @@ bool cNoteEntity::LoadFromJson( const Json::Value & a_Value ) -void cNoteEntity::SaveToJson( Json::Value & a_Value ) +void cNoteEntity::SaveToJson(Json::Value & a_Value) { a_Value["x"] = m_PosX; a_Value["y"] = m_PosY; diff --git a/source/BlockEntities/NoteEntity.h b/source/BlockEntities/NoteEntity.h index 385591df6..e2d088f44 100644 --- a/source/BlockEntities/NoteEntity.h +++ b/source/BlockEntities/NoteEntity.h @@ -26,26 +26,37 @@ enum ENUM_NOTE_INSTRUMENTS +// tolua_begin + class cNoteEntity : public cBlockEntity { + typedef cBlockEntity super; public: - cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World); - virtual ~cNoteEntity(); - bool LoadFromJson( const Json::Value& a_Value ); - virtual void SaveToJson( Json::Value& a_Value ) override; + // tolua_end - char GetPitch( void ); - void SetPitch( char a_Pitch ); - void IncrementPitch( void ); - void MakeSound( void ); - virtual void UsedBy( cPlayer * a_Player ) override; + /// Creates a new note entity. a_World may be NULL + cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World); + + bool LoadFromJson(const Json::Value & a_Value); + virtual void SaveToJson(Json::Value & a_Value) override; + + // tolua_begin + + char GetPitch(void); + void SetPitch(char a_Pitch); + void IncrementPitch(void); + void MakeSound(void); + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override { }; private: - unsigned char m_Pitch; -}; + char m_Pitch; +} ; // tolua_export diff --git a/source/BlockEntities/SignEntity.cpp b/source/BlockEntities/SignEntity.cpp index 2c160e603..81f6f6d77 100644 --- a/source/BlockEntities/SignEntity.cpp +++ b/source/BlockEntities/SignEntity.cpp @@ -1,29 +1,19 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules - -#include "SignEntity.h" +// SignEntity.cpp -#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 <json/json.h> +#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() +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 +22,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 +43,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 +80,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 +94,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; diff --git a/source/BlockEntities/SignEntity.h b/source/BlockEntities/SignEntity.h index b4e7a141f..d998ff1e8 100644 --- a/source/BlockEntities/SignEntity.h +++ b/source/BlockEntities/SignEntity.h @@ -1,4 +1,12 @@ +// SignEntity.h + +// Declares the cSignEntity class representing a single sign in the world + + + + + #pragma once #include "BlockEntity.h" @@ -13,28 +21,46 @@ namespace Json } + + + +// tolua_begin + class cSignEntity : public cBlockEntity { + typedef cBlockEntity super; + public: + + // tolua_end + + /// Creates a new empty sign entity at the specified block coords and block type (wall or standing). a_World may be NULL cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World); - virtual ~cSignEntity(); bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; - void SetLines( const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4 ); - void SetLine( int a_Index, const AString & a_Line ); - - AString GetLine( int a_Index ) const; + // tolua_begin + + /// Sets all the sign's lines + void SetLines(const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); + + /// Sets individual line (zero-based index) + void SetLine(int a_Index, const AString & a_Line); - virtual void UsedBy( cPlayer * a_Player ) override; + /// Retrieves individual line (zero-based index) + AString GetLine(int a_Index) const; + + // tolua_end + + virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override; private: AString m_Line[4]; -}; +} ; // tolua_export |