Item: rewrite callbacks annotations (again, xd)

This commit is contained in:
Van
2025-09-15 17:46:16 +00:00
parent a9e3089c1b
commit 5b0e3f7b20

View File

@@ -8,12 +8,10 @@ local Callbacks = {}
---Shall place item and return the leftover itemstack
---or nil to not modify the inventory.
---The placer may be any ObjectRef or nil.
---
---default: core.item_place
---@param itemstack table
---@param placer table
---@param pointed_thing table
---@return table?
function Callbacks.on_place(itemstack, placer, pointed_thing)
---@type nil | fun(itemstack : table, placer : table, pointed_thing : table):table?
Callbacks.on_place = function(itemstack, placer, pointed_thing)
return core.item_place(itemstack, placer, pointed_thing)
end
@@ -21,37 +19,34 @@ end
---Function must return either nil if inventory shall not be modified,
---or an itemstack to replace the original itemstack.
---The user may be any ObjectRef or nil.
---
---default: core.item_secondary_use
---@param itemstack table
---@param user table
---@param pointed_thing table
---@return table?
function Callbacks.on_secondary_use(itemstack, user, pointed_thing)
---@type nil | fun(itemstack : table, user : table, pointed_thing : table):table?
Callbacks.on_secondary_use = function(itemstack, user, pointed_thing)
return core.item_secondary_use(itemstack, user, pointed_thing)
end
---Shall drop item and return the leftover itemstack.
---The dropper may be any ObjectRef or nil.
---
---default: core.item_drop
---@param itemstack table
---@param dropper table
---@param pos table
---@return table
function Callbacks.on_drop(itemstack, dropper, pos)
---@type nil | fun(itemstack : table, dropper : table, pos : table):table
Callbacks.on_drop = function(itemstack, dropper, pos)
return core.item_drop(itemstack, dropper, pos)
end
---Called when a dropped item is punched by a player.
---Shall pick-up the item and return the leftover itemstack or nil to not
---modify the dropped item.
---
---default: core.item_pickup
---@param itemstack table The `ItemStack` to be picked up.
---@param picker table Any `ObjectRef` or `nil`.
---@param pointed_thing table? The dropped item (a `"__builtin:item"` luaentity) as `type="object"` `pointed_thing`.
---@param time_from_last_punch number? Other parameters from `luaentity:on_punch`.
---@param ... any? Other parameters from `luaentity:on_punch`.
---@return table
function Callbacks.on_pickup(itemstack, picker, pointed_thing, time_from_last_punch, ...)
---* `itemstack`: the `ItemStack` to be picked up
---* `picker`: any `ObjectRef` or `nil`
---* `pointed_thing`: the dropped item (a `"__builtin:item"` luaentity) as `type="object"` `pointed_thing`
---* `time_from_last_punch`: other parameters from `luaentity:on_punch`
---* `...`: other parameters from `luaentity:on_punch`
---@type nil | fun(itemstack : table, picker : table, pointed_thing : table?, time_from_last_punch : number?, ... : any?):table?
Callbacks.on_pickup = function(itemstack, picker, pointed_thing, time_from_last_punch, ...)
return core.item_pickup(itemstack, picker, pointed_thing, time_from_last_punch, ...)
end
@@ -63,12 +58,10 @@ end
---Note that defining this callback will prevent normal punching/digging
---behavior on the client, as the interaction is instead "forwarded" to the
---server.
---
---default: nil
---@param itemstack table
---@param user table
---@param pointed_thing table
---@return table?
function Callbacks.on_use(itemstack, user, pointed_thing)
---@type nil | fun(itemstack : table, user : table, pointed_thing : table):table?
Callbacks.on_use = function(itemstack, user, pointed_thing)
end
@@ -77,13 +70,12 @@ end
---Shall return the leftover itemstack or nil to not
---modify the dropped item.
---The user may be any ObjectRef or nil.
---
---default: nil
---@param itemstack table
---@param user table?
---@param node any? TODO: какой тут тип???
---@param digparams any? TODO: какой тут тип???
---@return table?
function Callbacks.after_use(itemstack, user, node, digparams)
---
---TODO: разобраться какие типы должны быть у node и diagrams
---@type nil | fun(itemstack : table, user : table?, node : any?, diagrams : any?):table?
Callbacks.after_use = function(itemstack, user, node, digparams)
end