diff options
author | Franz Reiter <franzi.moos@googlemail.com> | 2014-09-23 15:54:07 +0200 |
---|---|---|
committer | Franz Reiter <franzi.moos@googlemail.com> | 2014-09-23 15:54:07 +0200 |
commit | 33f8091d5f550a91b1fbe24f07a397aa5a336093 (patch) | |
tree | 4fe1be83dd4212e010fed749cd444c4deecc64e6 /src/Mobs | |
parent | QtBiomeVisualiser: Fixed confusion about Globals.h. (diff) | |
parent | Fixed SQLiteCpp downgrade (diff) | |
download | cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.tar cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.tar.gz cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.tar.bz2 cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.tar.lz cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.tar.xz cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.tar.zst cuberite-33f8091d5f550a91b1fbe24f07a397aa5a336093.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Monster.cpp | 54 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 23 | ||||
-rw-r--r-- | src/Mobs/Sheep.cpp | 2 |
3 files changed, 78 insertions, 1 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 81acf1a93..339367f47 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -75,6 +75,8 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_IdleInterval(0) , m_DestroyTimer(0) , m_MobType(a_MobType) + , m_CustomName("") + , m_CustomNameAlwaysVisible(false) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) , m_AttackRate(3) @@ -555,6 +557,25 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI) +void cMonster::OnRightClicked(cPlayer & a_Player) +{ + super::OnRightClicked(a_Player); + + const cItem & EquippedItem = a_Player.GetEquippedItem(); + if ((EquippedItem.m_ItemType == E_ITEM_NAME_TAG) && !EquippedItem.m_CustomName.empty()) + { + SetCustomName(EquippedItem.m_CustomName); + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + } +} + + + + + // Checks to see if EventSeePlayer should be fired // monster sez: Do I see the player void cMonster::CheckEventSeePlayer(void) @@ -683,6 +704,39 @@ void cMonster::InStateEscaping(float a_Dt) +void cMonster::SetCustomName(const AString & a_CustomName) +{ + m_CustomName = a_CustomName; + + // The maximal length is 64 + if (a_CustomName.length() > 64) + { + m_CustomName = a_CustomName.substr(0, 64); + } + + if (m_World != NULL) + { + m_World->BroadcastEntityMetadata(*this); + } +} + + + + + +void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible) +{ + m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible; + if (m_World != NULL) + { + m_World->BroadcastEntityMetadata(*this); + } +} + + + + + void cMonster::GetMonsterConfig(const AString & a_Name) { cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name); diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index ca3c04c23..4865cb99e 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -92,6 +92,8 @@ public: virtual void KilledBy(TakeDamageInfo & a_TDI) override; + virtual void OnRightClicked(cPlayer & a_Player) override; + virtual void MoveToPosition(const Vector3d & a_Position); // tolua_export virtual bool ReachedDestination(void); @@ -147,7 +149,24 @@ public: virtual bool IsSitting (void) const { return false; } // tolua_begin - + + /** Returns true if the monster has a custom name. */ + bool HasCustomName(void) const { return !m_CustomName.empty(); } + + /** Gets the custom name of the monster. If no custom name is set, the function returns an empty string. */ + const AString & GetCustomName(void) const { return m_CustomName; } + + /** Sets the custom name of the monster. You see the name over the monster. + If you want to disable the custom name, simply set an empty string. */ + void SetCustomName(const AString & a_CustomName); + + /** Is the custom name of this monster always visible? If not, you only see the name when you sight the mob. */ + bool IsCustomNameAlwaysVisible(void) const { return m_CustomNameAlwaysVisible; } + + /** Sets the custom name visiblity of this monster. + If it's false, you only see the name when you sight the mob. If it's true, you always see the custom name. */ + void SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible); + /// Translates MobType enum to a string, empty string if unknown static AString MobTypeToString(eType a_MobType); @@ -231,6 +250,8 @@ protected: float m_DestroyTimer; eType m_MobType; + AString m_CustomName; + bool m_CustomNameAlwaysVisible; AString m_SoundHurt; AString m_SoundDeath; diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 1a82115d2..c12e8d786 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -54,6 +54,8 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSheep::OnRightClicked(cPlayer & a_Player) { + super::OnRightClicked(a_Player); + const cItem & EquippedItem = a_Player.GetEquippedItem(); if ((EquippedItem.m_ItemType == E_ITEM_SHEARS) && !IsSheared() && !IsBaby()) { |