aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorraymoo <uguu@installgentoo.com>2017-04-18 16:30:27 -0700
committerparamat <mat.gregory@virginmedia.com>2017-10-29 11:57:38 +0000
commita637107a4e81be88938d68df4deae50e68cf2cd8 (patch)
tree2d35b9bf380af88bb7618a6b4efbca6f55c338d3 /src/script
parent610ea6f21629933be3b38c2b5fce53a35c5aac3a (diff)
downloadminetest-a637107a4e81be88938d68df4deae50e68cf2cd8.tar.gz
minetest-a637107a4e81be88938d68df4deae50e68cf2cd8.tar.bz2
minetest-a637107a4e81be88938d68df4deae50e68cf2cd8.zip
Allow overriding tool capabilities through itemstack metadata
This makes it possible to modify the tool capabilities of individual itemstacks by calling a method on itemstack metadata references.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_itemstackmeta.cpp15
-rw-r--r--src/script/lua_api/l_itemstackmeta.h11
2 files changed, 26 insertions, 0 deletions
diff --git a/src/script/lua_api/l_itemstackmeta.cpp b/src/script/lua_api/l_itemstackmeta.cpp
index c37a82116..3cbc3d0f7 100644
--- a/src/script/lua_api/l_itemstackmeta.cpp
+++ b/src/script/lua_api/l_itemstackmeta.cpp
@@ -50,6 +50,20 @@ void ItemStackMetaRef::reportMetadataChange()
}
// Exported functions
+int ItemStackMetaRef::l_set_tool_capabilities(lua_State *L)
+{
+ ItemStackMetaRef *metaref = checkobject(L, 1);
+ if (lua_isnoneornil(L, 2)) {
+ metaref->clearToolCapabilities();
+ } else if (lua_istable(L, 2)) {
+ ToolCapabilities caps = read_tool_capabilities(L, 2);
+ metaref->setToolCapabilities(caps);
+ } else {
+ luaL_typerror(L, 2, "table or nil");
+ }
+
+ return 0;
+}
// garbage collector
int ItemStackMetaRef::gc_object(lua_State *L) {
@@ -116,5 +130,6 @@ const luaL_Reg ItemStackMetaRef::methods[] = {
luamethod(MetaDataRef, to_table),
luamethod(MetaDataRef, from_table),
luamethod(MetaDataRef, equals),
+ luamethod(ItemStackMetaRef, set_tool_capabilities),
{0,0}
};
diff --git a/src/script/lua_api/l_itemstackmeta.h b/src/script/lua_api/l_itemstackmeta.h
index 241f04c4c..46c40ab30 100644
--- a/src/script/lua_api/l_itemstackmeta.h
+++ b/src/script/lua_api/l_itemstackmeta.h
@@ -40,7 +40,18 @@ private:
virtual void reportMetadataChange();
+ void setToolCapabilities(const ToolCapabilities &caps)
+ {
+ istack->metadata.setToolCapabilities(caps);
+ }
+
+ void clearToolCapabilities()
+ {
+ istack->metadata.clearToolCapabilities();
+ }
+
// Exported functions
+ static int l_set_tool_capabilities(lua_State *L);
// garbage collector
static int gc_object(lua_State *L);