summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheHyper45 <dawid.priv@o2.pl>2021-06-20 13:12:12 +0200
committerAlexander Harkness <me@bearbin.net>2022-04-12 01:06:40 +0200
commit5500314fbea50f6200a7e3d045541224e3d9bb78 (patch)
treeb5ae4912c9a054c6a1f862b52b1bf32ccff55f5e
parentThe proper style fix (diff)
downloadcuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.tar
cuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.tar.gz
cuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.tar.bz2
cuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.tar.lz
cuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.tar.xz
cuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.tar.zst
cuberite-5500314fbea50f6200a7e3d045541224e3d9bb78.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp4
-rw-r--r--src/WorldStorage/NamespaceSerializer.cpp103
-rw-r--r--src/WorldStorage/NamespaceSerializer.h2
3 files changed, 31 insertions, 78 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 175851a21..000a7715a 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -2365,7 +2365,7 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
}
else
{
- Name = AString(NamespaceSerializer::Prettify(Monster->GetMobType(), Monster->IsTame()));
+ Name = NamespaceSerializer::Prettify(AString(NamespaceSerializer::From(Monster->GetMobType())), Monster->IsTame());
}
}
else
@@ -2431,7 +2431,7 @@ void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI)
}
else
{
- AString KillerName = AString(NamespaceSerializer::Prettify(Monster->GetMobType(), Monster->IsTame()));
+ AString KillerName = NamespaceSerializer::Prettify(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 969f9b5de..52a2973a0 100644
--- a/src/WorldStorage/NamespaceSerializer.cpp
+++ b/src/WorldStorage/NamespaceSerializer.cpp
@@ -551,82 +551,35 @@ eMonsterType NamespaceSerializer::ToMonsterType(const std::string_view a_ID)
-std::string_view NamespaceSerializer::Prettify(const eMonsterType a_ID, const bool a_IsTamed)
+AString NamespaceSerializer::Prettify(AString a_Name, const bool a_IsTamed)
{
- switch (a_ID)
+ /**
+ Examples:
+ Input: "wolf", Output: "Wolf"
+ Input: "snow_golem", Output: "Snow Golem"
+ Input: "skeleton_horse", Output: "Skeleton Horse"
+ */
+
+ // 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)
{
- case mtBat: return "Bat";
- case mtBlaze: return "Blaze";
- case mtCat: return "Cat";
- case mtCaveSpider: return "Cave Spider";
- case mtChicken: return "Chicken";
- case mtCod: return "Cod";
- case mtCow: return "Cow";
- case mtCreeper: return "Creeper";
- case mtDolphin: return "Dolphin";
- case mtDonkey: return "Donkey";
- case mtDrowned: return "Drowned";
- case mtElderGuardian: return "Elder Guardian";
- case mtEnderDragon: return "Ender Dragon";
- case mtEnderman: return "Enderman";
- case mtEndermite: return "Endermite";
- case mtEvoker: return "Evoker";
- case mtFox: return "Fox";
- case mtGhast: return "Ghast";
- case mtGiant: return "Giant";
- case mtGuardian: return "Guardian";
- case mtHorse: return "Horse";
- case mtHoglin: return "Hoglin";
- case mtHusk: return "Husk";
- case mtIllusioner: return "Illusioner";
- case mtIronGolem: return "Iron Golem";
- case mtLlama: return "Llama";
- case mtMagmaCube: return "Magma Cube";
- case mtMooshroom: return "Mooshroom";
- case mtMule: return "Mule";
- // 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]".
- case mtOcelot: return (a_IsTamed ? "Cat" : "Ocelot");
- case mtPanda: return "Panda";
- case mtParrot: return "Parrot";
- case mtPhantom: return "Phantom";
- case mtPig: return "Pig";
- case mtPiglin: return "Piglin";
- case mtPiglinBrute: return "Piglin_brute";
- case mtPillager: return "Pillager";
- case mtPolarBear: return "Polar Bear";
- case mtPufferfish: return "Pufferfish";
- case mtRabbit: return "Rabbit";
- case mtRavager: return "Ravager";
- case mtSalmon: return "Salmon";
- case mtSheep: return "Sheep";
- case mtShulker: return "Shulker";
- case mtSilverfish: return "Silverfish";
- case mtSkeleton: return "Skeleton";
- case mtSkeletonHorse: return "Skeleton Horse";
- case mtSlime: return "Slime";
- case mtSnowGolem: return "Snow Golem";
- case mtSpider: return "Spider";
- case mtSquid: return "Squid";
- case mtStray: return "Stray";
- case mtStrider: return "Strider";
- case mtTraderLlama: return "Trader Llama";
- case mtTropicalFish: return "Tropical Fish";
- case mtTurtle: return "Turtle";
- case mtVex: return "Vex";
- case mtVillager: return "Villager";
- case mtVindicator: return "Vindicator";
- case mtWanderingTrader:return "Wandering Trader";
- case mtWitch: return "Witch";
- case mtWither: return "Wither";
- case mtWitherSkeleton: return "Wither Skeleton";
- case mtWolf: return "Wolf";
- case mtZoglin: return "Zoglin";
- case mtZombie: return "Zombie";
- case mtZombieHorse: return "Zombie Horse";
- case mtZombiePigman: return "Zombified Piglin";
- case mtZombieVillager: return "Zombie Villager";
- case mtInvalidType: break;
+ return "Cat";
}
- UNREACHABLE("Tried to save unknown monster type");
+
+ bool NextLetterCapitalized = true;
+ std::for_each(a_Name.begin(), a_Name.end(), [&](char & a_Letter)
+ {
+ if (NextLetterCapitalized)
+ {
+ a_Letter = std::toupper(a_Letter);
+ NextLetterCapitalized = false;
+ }
+ else if (a_Letter == '_')
+ {
+ a_Letter = ' ';
+ NextLetterCapitalized = true;
+ }
+ });
+ return a_Name;
}
diff --git a/src/WorldStorage/NamespaceSerializer.h b/src/WorldStorage/NamespaceSerializer.h
index f6095519b..e21b487d7 100644
--- a/src/WorldStorage/NamespaceSerializer.h
+++ b/src/WorldStorage/NamespaceSerializer.h
@@ -24,5 +24,5 @@ namespace NamespaceSerializer
std::pair<Namespace, std::string_view> SplitNamespacedID(std::string_view ID);
- std::string_view Prettify(eMonsterType a_ID, bool a_IsTamed = false);
+ AString Prettify(AString a_Name, const bool a_IsTamed = false);
}