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