From d2b3011c05890652b0aa09f6e128004056a98258 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 2 Jun 2013 21:44:24 +0000 Subject: Added the possibility to specify enchantments by name in the constructor and AddFromString() function git-svn-id: http://mc-server.googlecode.com/svn/trunk@1542 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Enchantments.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'source/Enchantments.cpp') diff --git a/source/Enchantments.cpp b/source/Enchantments.cpp index d0bf8c731..4802db3f7 100644 --- a/source/Enchantments.cpp +++ b/source/Enchantments.cpp @@ -51,9 +51,13 @@ void cEnchantments::AddFromString(const AString & a_StringSpec) continue; } int id = atoi(Split[0].c_str()); + if ((id == 0) && (Split[0] != "0")) + { + id = StringToEnchantmentID(Split[0]); + } int lvl = atoi(Split[1].c_str()); if ( - ((id == 0) && (Split[0] != "0")) || + ((id <= 0) && (Split[0] != "0")) || ((lvl == 0) && (Split[1] != "0")) ) { @@ -145,6 +149,51 @@ bool cEnchantments::IsEmpty(void) const +int cEnchantments::StringToEnchantmentID(const AString & a_EnchantmentName) +{ + struct + { + int m_Value; + const char * m_Name; + } EnchantmentNames[] = + { + { enchProtection, "Protection"}, + { enchFireProtection, "FireProtection"}, + { enchFeatherFalling, "FeatherFalling"}, + { enchBlastProtection, "BlastProtection"}, + { enchProjectileProtection, "ProjectileProtection"}, + { enchRespiration, "Respiration"}, + { enchAquaAffinity, "AquaAffinity"}, + { enchThorns, "Thorns"}, + { enchSharpness, "Sharpness"}, + { enchSmite, "Smite"}, + { enchBaneOfArthropods, "BaneOfArthropods"}, + { enchKnockback, "Knockback"}, + { enchFireAspect, "FireAspect"}, + { enchLooting, "Looting"}, + { enchEfficiency, "Efficiency"}, + { enchSilkTouch, "SilkTouch"}, + { enchUnbreaking, "Unbreaking"}, + { enchFortune, "Fortune"}, + { enchPower, "Power"}, + { enchPunch, "Punch"}, + { enchFlame, "Flame"}, + { enchInfinity, "Infinity"}, + } ; + for (int i = 0; i < ARRAYCOUNT(EnchantmentNames); i++) + { + if (NoCaseCompare(EnchantmentNames[i].m_Name, a_EnchantmentName) == 0) + { + return EnchantmentNames[i].m_Value; + } + } // for i - EnchantmentNames[] + return -1; +} + + + + + void cEnchantments::WriteToNBTCompound(cFastNBTWriter & a_Writer, const AString & a_ListTagName) const { // Write the enchantments into the specified NBT writer -- cgit v1.2.3