1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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.
This commit is contained in:
raymoo 2017-04-18 16:30:27 -07:00 committed by paramat
parent 610ea6f216
commit a637107a4e
10 changed files with 206 additions and 14 deletions

View file

@ -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}
};

View file

@ -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);