diff --git a/definitions/DetachedInventoryCallbacksDef.lua b/definitions/DetachedInventoryCallbacksDef.lua new file mode 100644 index 0000000..311d447 --- /dev/null +++ b/definitions/DetachedInventoryCallbacksDef.lua @@ -0,0 +1,32 @@ +--- @class DetachedInventoryCallbacksDef +local DetachedInventoryCallbacksDef = { + --- Called when a player wants to move items inside the inventory. + --- Return value: number of items allowed to move. + --- @type fun(inv:InvRef, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player):number + allow_move = nil, + + --- Called when a player wants to put something into the inventory. + --- Return value: number of items allowed to put. + --- Return value -1: Allow and don't modify item count in inventory. + --- @type fun(inv:InvRef, list_name:string, index:number, stack:ItemStack, player:Player):number + allow_put = nil, + + --- Called when a player wants to take something out of the inventory. + --- Return value: number of items allowed to take. + --- Return value -1: Allow and don't modify item count in inventory. + --- @type fun(inv:InvRef, list_name:string, index:number, stack:ItemStack, player:Player):number + allow_take = nil, + + --- Called after the actual action has happened, according to what was allowed (see `allow_move()`). + --- No return value. + --- @type fun(inv:InvRef, from_list:string, from_index:number, to_list:string, to_index:number, count:number, player:Player):void + on_move = nil, + --- Called after the actual action has happened, according to what was allowed (see `allow_put()`). + --- No return value. + --- @type fun(inv:InvRef, list_name:string, index:number, stack:ItemStack, player:Player) + on_put = nil, + --- Called after the actual action has happened, according to what was allowed (see `allow_take()`). + --- No return value. + --- @type fun(inv:InvRef, list_name:string, index:number, stack:ItemStack, player:Player) + on_take = nil, +} diff --git a/minetest_types.lua b/minetest_types.lua index c8f7d7e..c8b8edf 100644 --- a/minetest_types.lua +++ b/minetest_types.lua @@ -1387,6 +1387,10 @@ function minetest.get_inventory(location) end --- * Creates a detached inventory. If it already exists, it is cleared. --- --- [View in lua_api.txt](https://github.com/minetest/minetest/blob/5.4.1/doc/lua_api.txt#L5190-L5198) +--- @param name string +--- @param callbacks DetachedInventoryCallbacksDef +--- @param player_name string +--- @return InvRef function minetest.create_detached_inventory(name, callbacks, player_name) end --- * Returns a `boolean` indicating whether the removal succeeded. ---