diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-02 23:44:24 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-06-02 23:44:24 +0200 |
commit | d2b3011c05890652b0aa09f6e128004056a98258 (patch) | |
tree | 8297f8386096a624f7762f6bb36d7170742952d5 /source | |
parent | Enchantments are now stored in Anvil world and in player inventory (diff) | |
download | cuberite-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/Bindings.cpp | 34 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/Enchantments.cpp | 51 | ||||
-rw-r--r-- | source/Enchantments.h | 7 |
4 files changed, 89 insertions, 5 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 50f417cc1..f4d24529d 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/02/13 12:36:50. +** Generated automatically by tolua++-1.0.92 on 06/02/13 23:42:02. */ #ifndef __cplusplus @@ -14145,6 +14145,37 @@ static int tolua_AllToLua_cEnchantments_IsEmpty00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: StringToEnchantmentID of class cEnchantments */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cEnchantments_StringToEnchantmentID00 +static int tolua_AllToLua_cEnchantments_StringToEnchantmentID00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cEnchantments",0,&tolua_err) || + !tolua_iscppstring(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const AString a_EnchantmentName = ((const AString) tolua_tocppstring(tolua_S,2,0)); + { + int tolua_ret = (int) cEnchantments::StringToEnchantmentID(a_EnchantmentName); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + tolua_pushcppstring(tolua_S,(const char*)a_EnchantmentName); + } + } + return 2; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'StringToEnchantmentID'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: new of class cItem */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_new00 static int tolua_AllToLua_cItem_new00(lua_State* tolua_S) @@ -27701,6 +27732,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"SetLevel",tolua_AllToLua_cEnchantments_SetLevel00); tolua_function(tolua_S,"Clear",tolua_AllToLua_cEnchantments_Clear00); tolua_function(tolua_S,"IsEmpty",tolua_AllToLua_cEnchantments_IsEmpty00); + tolua_function(tolua_S,"StringToEnchantmentID",tolua_AllToLua_cEnchantments_StringToEnchantmentID00); tolua_endmodule(tolua_S); #ifdef __cplusplus tolua_cclass(tolua_S,"cItem","cItem","",tolua_collect_cItem); diff --git a/source/Bindings.h b/source/Bindings.h index 1c7aa7261..3c6433f8c 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 06/02/13 12:36:50. +** Generated automatically by tolua++-1.0.92 on 06/02/13 23:42:02. */ /* Exported function */ 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
diff --git a/source/Enchantments.h b/source/Enchantments.h index 96ebc1880..002626413 100644 --- a/source/Enchantments.h +++ b/source/Enchantments.h @@ -26,9 +26,9 @@ class cParsedNBT; /** Class that stores item enchantments or stored-enchantments
The enchantments may be serialized to a stringspec and read back from such stringspec.
The format for the stringspec is "id=lvl;id=lvl;id=lvl...", with an optional semicolon at the end,
-mapping each enchantment's id onto its level.
+mapping each enchantment's id onto its level. ID may be either a number or the enchantment name.
Level value of 0 means no such enchantment, and it will not be stored in the m_Enchantments.
-Serialization will never put zero-level enchantments into the stringspec.
+Serialization will never put zero-level enchantments into the stringspec and will always use numeric IDs.
*/
class cEnchantments
{
@@ -84,6 +84,9 @@ public: /// Returns true if there are no enchantments
bool IsEmpty(void) const;
+ /// Converts enchantment name to the numeric representation; returns -1 if enchantment name not found; case insensitive
+ static int StringToEnchantmentID(const AString & a_EnchantmentName);
+
// tolua_end
/// Writes the enchantments into the specified NBT writer; begins with the LIST tag of the specified name ("ench" or "StoredEnchantments")
|