summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-04-11 12:05:53 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-04-11 12:05:53 +0200
commit58fb05980d0abaa955f7fcad672d9af76e679f76 (patch)
tree89665d735eb857ac84c5e7276224052a5dd75393
parentDispensers rewritten to use ItemGrid (diff)
downloadcuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.tar
cuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.tar.gz
cuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.tar.bz2
cuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.tar.lz
cuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.tar.xz
cuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.tar.zst
cuberite-58fb05980d0abaa955f7fcad672d9af76e679f76.zip
-rw-r--r--source/Bindings.cpp34
-rw-r--r--source/Bindings.h2
-rw-r--r--source/Item.cpp56
-rw-r--r--source/Item.h55
4 files changed, 80 insertions, 67 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 915e7110f..f459f57e2 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 04/10/13 23:35:42.
+** Generated automatically by tolua++-1.0.92 on 04/11/13 11:57:58.
*/
#ifndef __cplusplus
@@ -13106,9 +13106,9 @@ static int tolua_AllToLua_cItem_CopyOne00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: GetMaxDuration of class cItem */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetMaxDuration00
-static int tolua_AllToLua_cItem_GetMaxDuration00(lua_State* tolua_S)
+/* method: GetMaxDamage of class cItem */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_GetMaxDamage00
+static int tolua_AllToLua_cItem_GetMaxDamage00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@@ -13122,17 +13122,17 @@ static int tolua_AllToLua_cItem_GetMaxDuration00(lua_State* tolua_S)
{
const cItem* self = (const cItem*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxDuration'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetMaxDamage'", NULL);
#endif
{
- int tolua_ret = (int) self->GetMaxDuration();
+ short tolua_ret = (short) self->GetMaxDamage();
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'GetMaxDuration'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'GetMaxDamage'.",&tolua_err);
return 0;
#endif
}
@@ -13170,33 +13170,33 @@ static int tolua_AllToLua_cItem_DamageItem00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: HasDuration of class cItem */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_HasDuration00
-static int tolua_AllToLua_cItem_HasDuration00(lua_State* tolua_S)
+/* method: IsDamageable of class cItem */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_IsDamageable00
+static int tolua_AllToLua_cItem_IsDamageable00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
- !tolua_isusertype(tolua_S,1,"cItem",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,1,"const cItem",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,2,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
- cItem* self = (cItem*) tolua_tousertype(tolua_S,1,0);
+ const cItem* self = (const cItem*) tolua_tousertype(tolua_S,1,0);
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'HasDuration'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'IsDamageable'", NULL);
#endif
{
- bool tolua_ret = (bool) self->HasDuration();
+ bool tolua_ret = (bool) self->IsDamageable();
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'HasDuration'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'IsDamageable'.",&tolua_err);
return 0;
#endif
}
@@ -24812,9 +24812,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"IsEqual",tolua_AllToLua_cItem_IsEqual00);
tolua_function(tolua_S,"IsSameType",tolua_AllToLua_cItem_IsSameType00);
tolua_function(tolua_S,"CopyOne",tolua_AllToLua_cItem_CopyOne00);
- tolua_function(tolua_S,"GetMaxDuration",tolua_AllToLua_cItem_GetMaxDuration00);
+ tolua_function(tolua_S,"GetMaxDamage",tolua_AllToLua_cItem_GetMaxDamage00);
tolua_function(tolua_S,"DamageItem",tolua_AllToLua_cItem_DamageItem00);
- tolua_function(tolua_S,"HasDuration",tolua_AllToLua_cItem_HasDuration00);
+ tolua_function(tolua_S,"IsDamageable",tolua_AllToLua_cItem_IsDamageable00);
tolua_function(tolua_S,"IsStackableWith",tolua_AllToLua_cItem_IsStackableWith00);
tolua_function(tolua_S,"IsEnchantable",tolua_AllToLua_cItem_IsEnchantable00);
tolua_variable(tolua_S,"m_ItemType",tolua_get_cItem_m_ItemType,tolua_set_cItem_m_ItemType);
diff --git a/source/Bindings.h b/source/Bindings.h
index a120db988..b12285553 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 04/10/13 23:35:43.
+** Generated automatically by tolua++-1.0.92 on 04/11/13 11:57:59.
*/
/* Exported function */
diff --git a/source/Item.cpp b/source/Item.cpp
index 15f011c13..fde4f7ba9 100644
--- a/source/Item.cpp
+++ b/source/Item.cpp
@@ -19,6 +19,62 @@ cItem cItem::CopyOne(void) const
+short cItem::GetMaxDamage(void) const
+{
+ switch (m_ItemType)
+ {
+ case E_ITEM_DIAMOND_AXE: return 1563;
+ case E_ITEM_DIAMOND_HOE: return 1563;
+ case E_ITEM_DIAMOND_PICKAXE: return 1563;
+ case E_ITEM_DIAMOND_SHOVEL: return 1563;
+ case E_ITEM_DIAMOND_SWORD: return 1563;
+ case E_ITEM_FLINT_AND_STEEL: return 65;
+ case E_ITEM_GOLD_AXE: return 32;
+ case E_ITEM_GOLD_HOE: return 32;
+ case E_ITEM_GOLD_PICKAXE: return 32;
+ case E_ITEM_GOLD_SHOVEL: return 32;
+ case E_ITEM_GOLD_SWORD: return 32;
+ case E_ITEM_IRON_AXE: return 251;
+ case E_ITEM_IRON_HOE: return 251;
+ case E_ITEM_IRON_PICKAXE: return 251;
+ case E_ITEM_IRON_SHOVEL: return 251;
+ case E_ITEM_IRON_SWORD: return 251;
+ case E_ITEM_SHEARS: return 251;
+ case E_ITEM_STONE_AXE: return 132;
+ case E_ITEM_STONE_HOE: return 132;
+ case E_ITEM_STONE_PICKAXE: return 132;
+ case E_ITEM_STONE_SHOVEL: return 132;
+ case E_ITEM_STONE_SWORD: return 132;
+ case E_ITEM_WOODEN_AXE: return 60;
+ case E_ITEM_WOODEN_HOE: return 60;
+ case E_ITEM_WOODEN_PICKAXE: return 60;
+ case E_ITEM_WOODEN_SHOVEL: return 60;
+ case E_ITEM_WOODEN_SWORD: return 60;
+ }
+ return 0;
+}
+
+
+
+
+
+bool cItem::DamageItem(void)
+{
+ short MaxDamage = GetMaxDamage();
+ if (MaxDamage == 0)
+ {
+ // Item doesn't have damage
+ return false;
+ }
+
+ m_ItemDamage++;
+ return (m_ItemDamage >= MaxDamage);
+}
+
+
+
+
+
bool cItem::IsStackableWith(const cItem & a_OtherStack)
{
if (a_OtherStack.m_ItemType != m_ItemType)
diff --git a/source/Item.h b/source/Item.h
index d2cbd6053..fb3999f9e 100644
--- a/source/Item.h
+++ b/source/Item.h
@@ -65,56 +65,13 @@ public:
/// Returns a copy of this item with m_ItemCount set to 1. Useful to preserve enchantments etc. on stacked items
cItem CopyOne(void) const;
- // TODO Sorry for writing the functions in the header. But somehow it doesn´t worked when I put them into the cpp File :s
-
- inline int GetMaxDuration(void) const
- {
- switch (m_ItemType)
- {
- case 256: return 251;
- case 257: return 251;
- case 258: return 251;
- case 259: return 65; //Lighter / Flint and Steel
- case 267: return 251;
- case 268: return 60;
- case 269: return 60;
- case 270: return 60;
- case 271: return 60;
- case 272: return 132;
- case 273: return 132;
- case 274: return 132;
- case 275: return 132;
- case 276: return 1563;
- case 277: return 1563;
- case 278: return 1563;
- case 279: return 1563;
- case 283: return 32;
- case 284: return 32;
- case 285: return 32;
- case 286: return 32;
- case 290: return 60;
- case 291: return 132;
- case 292: return 251;
- case 293: return 1563;
- case 294: return 32;
- case 359: return 251;
- default: return 0;
- }
- }
-
- /// Damages a weapon / tool. Returns true when destroyed
- inline bool DamageItem()
- {
- if (HasDuration())
- {
- m_ItemDamage++;
- if (m_ItemDamage >= GetMaxDuration())
- return true;
- }
- return false;
- }
+ /// Returns the maximum damage value that this item can have; zero if damage is not applied
+ short GetMaxDamage(void) const;
+
+ /// Damages a weapon / tool. Returns true when damage reaches max value and the item should be destroyed
+ bool DamageItem(void);
- inline bool HasDuration() { return GetMaxDuration() > 0; }
+ inline bool IsDamageable(void) const { return (GetMaxDamage() > 0); }
/// Returns true if this itemstack can stack with the specified stack (types match, enchantments etc.) ItemCounts are ignored!
bool IsStackableWith(const cItem & a_OtherStack);