summaryrefslogtreecommitdiffstats
path: root/source/Enchantments.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-02 23:44:24 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-06-02 23:44:24 +0200
commitd2b3011c05890652b0aa09f6e128004056a98258 (patch)
tree8297f8386096a624f7762f6bb36d7170742952d5 /source/Enchantments.cpp
parentEnchantments are now stored in Anvil world and in player inventory (diff)
downloadcuberite-d2b3011c05890652b0aa09f6e128004056a98258.tar
cuberite-d2b3011c05890652b0aa09f6e128004056a98258.tar.gz
cuberite-d2b3011c05890652b0aa09f6e128004056a98258.tar.bz2
cuberite-d2b3011c05890652b0aa09f6e128004056a98258.tar.lz
cuberite-d2b3011c05890652b0aa09f6e128004056a98258.tar.xz
cuberite-d2b3011c05890652b0aa09f6e128004056a98258.tar.zst
cuberite-d2b3011c05890652b0aa09f6e128004056a98258.zip
Diffstat (limited to '')
-rw-r--r--source/Enchantments.cpp51
1 files changed, 50 insertions, 1 deletions
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