Mobs: Traders: Refactoring: use local var, simlify add_goods. Relates to lord-server/lord#1153

This commit is contained in:
alek13
2023-09-17 00:31:22 +03:00
parent 0fad786123
commit 15e3ae23dc
2 changed files with 36 additions and 0 deletions

View File

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

View File

@@ -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.
---