diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-07 03:19:05 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-06-07 03:19:05 +0200 |
commit | b11c0a6721cd884d78b38b63797dfdb933004e03 (patch) | |
tree | 629c49cda2995fafef2bf345abf31b39bd21ff69 /src/script/lua_api/l_item.cpp | |
parent | 827b9f8d7054158b058679999d77c1345162a293 (diff) | |
parent | edc7df54801ab3bf30f96ac5aad6ce11a102f6b9 (diff) | |
download | dragonfireclient-b11c0a6721cd884d78b38b63797dfdb933004e03.tar.xz |
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/script/lua_api/l_item.cpp')
-rw-r--r-- | src/script/lua_api/l_item.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp index bae6701a0..160bb4e83 100644 --- a/src/script/lua_api/l_item.cpp +++ b/src/script/lua_api/l_item.cpp @@ -348,7 +348,7 @@ int LuaItemStack::l_get_tool_capabilities(lua_State *L) } // add_wear(self, amount) -> true/false -// The range for "amount" is [0,65535]. Wear is only added if the item +// The range for "amount" is [0,65536]. Wear is only added if the item // is a tool. Adding wear might destroy the item. // Returns true if the item is (or was) a tool. int LuaItemStack::l_add_wear(lua_State *L) @@ -362,6 +362,25 @@ int LuaItemStack::l_add_wear(lua_State *L) return 1; } +// add_wear_by_uses(self, max_uses) -> true/false +// The range for "max_uses" is [0,65536]. +// Adds wear to the item in such a way that, if +// only this function is called to add wear, the item +// will be destroyed exactly after `max_uses` times of calling it. +// No-op if `max_uses` is 0 or item is not a tool. +// Returns true if the item is (or was) a tool. +int LuaItemStack::l_add_wear_by_uses(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + LuaItemStack *o = checkobject(L, 1); + ItemStack &item = o->m_stack; + u32 max_uses = readParam<int>(L, 2); + u32 add_wear = calculateResultWear(max_uses, item.wear); + bool result = item.addWear(add_wear, getGameDef(L)->idef()); + lua_pushboolean(L, result); + return 1; +} + // add_item(self, itemstack or itemstring or table or nil) -> itemstack // Returns leftover item stack int LuaItemStack::l_add_item(lua_State *L) @@ -537,6 +556,7 @@ const luaL_Reg LuaItemStack::methods[] = { luamethod(LuaItemStack, get_definition), luamethod(LuaItemStack, get_tool_capabilities), luamethod(LuaItemStack, add_wear), + luamethod(LuaItemStack, add_wear_by_uses), luamethod(LuaItemStack, add_item), luamethod(LuaItemStack, item_fits), luamethod(LuaItemStack, take_item), |