summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-01 20:12:56 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-01 20:12:56 +0200
commit7c4cb9a3852e33d8bcc5f8283485e833c6eab93e (patch)
treea9f183b2ec527016f49da587e54641156db2a007
parentFixed Bindings regeneration under MSVC. (diff)
downloadcuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.tar
cuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.tar.gz
cuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.tar.bz2
cuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.tar.lz
cuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.tar.xz
cuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.tar.zst
cuberite-7c4cb9a3852e33d8bcc5f8283485e833c6eab93e.zip
-rw-r--r--src/Entities/Pawn.cpp9
-rw-r--r--src/Mobs/Monster.cpp29
-rw-r--r--src/Mobs/Monster.h20
-rw-r--r--src/Protocol/Protocol17x.cpp10
4 files changed, 64 insertions, 4 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index fe6c24a7a..fc8ca3d47 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -9,9 +9,9 @@
-cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height):
- super(a_EntityType, 0, 0, 0, a_Width, a_Height),
- m_EntityEffects(tEffectMap())
+cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) :
+ super(a_EntityType, 0, 0, 0, a_Width, a_Height)
+ , m_EntityEffects(tEffectMap())
{
}
@@ -111,3 +111,6 @@ void cPawn::ClearEntityEffects()
RemoveEntityEffect(EffectType);
}
}
+
+
+
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index f7ee0b0c0..6a477ca1c 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)
@@ -679,6 +681,33 @@ 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);
+ }
+
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
+void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible)
+{
+ m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible;
+ 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 cdbd26c09..ce4e36a46 100644
--- a/src/Mobs/Monster.h
+++ b/src/Mobs/Monster.h
@@ -144,7 +144,23 @@ 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 a empty string. */
+ const AString & GetCustomName(void) const { return m_CustomName; }
+
+ /** Sets the custom name of the monster. You see the name over the monster. */
+ 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 false, you only see the name when you sight the mob. If 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);
@@ -228,6 +244,8 @@ protected:
float m_DestroyTimer;
eType m_MobType;
+ AString m_CustomName;
+ bool m_CustomNameAlwaysVisible;
AString m_SoundHurt;
AString m_SoundDeath;
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 1091b877f..ed9812377 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1,3 +1,4 @@
+
// Protocol17x.cpp
/*
@@ -3021,6 +3022,15 @@ void cProtocol172::cPacketizer::WriteMobMetadata(const cMonster & a_Mob)
break;
}
} // switch (a_Mob.GetType())
+
+ // Custom name:
+ if (a_Mob.HasCustomName())
+ {
+ WriteByte(0x8a);
+ WriteString(a_Mob.GetCustomName());
+ WriteByte(0x0b);
+ WriteByte(a_Mob.IsCustomNameAlwaysVisible() ? 1 : 0);
+ }
}