summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorx12xx12x <44411062+12xx12@users.noreply.github.com>2022-01-16 11:03:24 +0100
committerAlexander Harkness <me@bearbin.net>2022-04-12 01:06:40 +0200
commit0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22 (patch)
tree0941facbffc2f4143a0091255b9e2ad2ff5262cd
parentRemoved an implicit cast from int to char. (diff)
downloadcuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.tar
cuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.tar.gz
cuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.tar.bz2
cuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.tar.lz
cuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.tar.xz
cuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.tar.zst
cuberite-0c04c5aaedcae6a0fc91df3f1f83746ff5eafd22.zip
-rw-r--r--src/Entities/Entity.cpp4
-rw-r--r--src/WorldStorage/NamespaceSerializer.cpp28
-rw-r--r--src/WorldStorage/NamespaceSerializer.h3
3 files changed, 22 insertions, 13 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 000a7715a..8788a8ce5 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -2365,7 +2365,7 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
}
else
{
- Name = NamespaceSerializer::Prettify(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
+ Name = NamespaceSerializer::PrettifyEntityName(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
}
}
else
@@ -2431,7 +2431,7 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
}
else
{
- AString KillerName = NamespaceSerializer::Prettify(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
+ AString KillerName = NamespaceSerializer::PrettifyEntityName(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
DeathMessage = Printf("%s was killed by a %s", Name.c_str(), KillerName.c_str());
}
diff --git a/src/WorldStorage/NamespaceSerializer.cpp b/src/WorldStorage/NamespaceSerializer.cpp
index 910054ff7..fd02fec68 100644
--- a/src/WorldStorage/NamespaceSerializer.cpp
+++ b/src/WorldStorage/NamespaceSerializer.cpp
@@ -1,7 +1,6 @@
#include "Globals.h"
#include "NamespaceSerializer.h"
-#include <cctype>
@@ -552,17 +551,11 @@ eMonsterType NamespaceSerializer::ToMonsterType(const std::string_view a_ID)
-AString NamespaceSerializer::Prettify(AString a_Name, const bool a_IsTamed)
+AString NamespaceSerializer::Prettify(AString a_ID)
{
- // In older vanilla Minecraft version (before 1.14) ocelots and cats were the same mob.
- // So after killing a tamed ocelot without a custom name the message will say "Cat was slain by [PlayerName]".
- if ((a_Name == "ocelot") && a_IsTamed)
- {
- return "Cat";
- }
bool NextLetterCapitalized = true;
- std::for_each(a_Name.begin(), a_Name.end(), [&](char & a_Letter)
+ std::for_each(a_ID.begin(), a_ID.end(), [&](char & a_Letter)
{
if (NextLetterCapitalized)
{
@@ -575,5 +568,20 @@ AString NamespaceSerializer::Prettify(AString a_Name, const bool a_IsTamed)
NextLetterCapitalized = true;
}
});
- return a_Name;
+ return a_ID;
+}
+
+
+
+
+
+AString NamespaceSerializer::PrettifyEntityName(const AString & a_ID, const bool a_IsTamed)
+{
+ // In older vanilla Minecraft version (before 1.14) ocelots and cats were the same mob.
+ // So after killing a tamed ocelot without a custom name the message will say "Cat was slain by [PlayerName]".
+ if ((a_ID == "ocelot") && a_IsTamed)
+ {
+ return "Cat";
+ }
+ return Prettify(a_ID);
}
diff --git a/src/WorldStorage/NamespaceSerializer.h b/src/WorldStorage/NamespaceSerializer.h
index 64739a7cd..625d348be 100644
--- a/src/WorldStorage/NamespaceSerializer.h
+++ b/src/WorldStorage/NamespaceSerializer.h
@@ -25,5 +25,6 @@ namespace NamespaceSerializer
std::pair<Namespace, std::string_view> SplitNamespacedID(std::string_view ID);
// Examples: Input: "wolf" -> Output: "Wolf", Input: "iron_golem" -> Output: "Iron Golem"
- AString Prettify(AString a_Name, const bool a_IsTamed = false);
+ AString Prettify(AString a_ID);
+ AString PrettifyEntityName(const AString & a_ID, const bool a_IsTamed = false);
}