diff --git a/mods/CORE/Item/src/Item/Callbacks.lua b/mods/CORE/Item/src/Item/Callbacks.lua new file mode 100644 index 0000000..8f137ce --- /dev/null +++ b/mods/CORE/Item/src/Item/Callbacks.lua @@ -0,0 +1,90 @@ +---@class Item.Callbacks +local Callbacks = {} + +-- TODO: Вписать вместо `table` более определенные классы: ItemStack, ObjectRef и т.п. + +---Called when the 'place' key was pressed with the item in hand +---and pointing at a node. +---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) + return core.item_place(itemstack, placer, pointed_thing) +end + +---Same as on_place but called when not pointing at a node. +---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) + 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) + 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, ...) + return core.item_pickup(itemstack, picker, pointed_thing, time_from_last_punch, ...) +end + +---Called when user presses the 'punch/dig' key with the item in hand. +---Function must return either nil if inventory shall not be modified, +---or an itemstack to replace the original itemstack. +---e.g. itemstack:take_item(); return itemstack +---The user may be any ObjectRef or nil. +---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) + +end + +---Called after a tool is used to dig a node and will replace the default +---tool wear-out handling. +---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) + +end + +return Callbacks \ No newline at end of file diff --git a/mods/CORE/Item/src/ItemDefinition.lua b/mods/CORE/Item/src/Item/ItemDefinition.lua similarity index 50% rename from mods/CORE/Item/src/ItemDefinition.lua rename to mods/CORE/Item/src/Item/ItemDefinition.lua index 2b23f35..e7834b9 100644 --- a/mods/CORE/Item/src/ItemDefinition.lua +++ b/mods/CORE/Item/src/Item/ItemDefinition.lua @@ -1,6 +1,6 @@ ---@class Item.ItemDefinition ----@field settings Item.ItemDefinition.Settings ----@field callbacks table +---@field settings Item.Settings +---@field callbacks Item.Callbacks local ItemDefinition = {} return ItemDefinition diff --git a/mods/CORE/Item/src/Item/Settings.lua b/mods/CORE/Item/src/Item/Settings.lua new file mode 100644 index 0000000..d99be02 --- /dev/null +++ b/mods/CORE/Item/src/Item/Settings.lua @@ -0,0 +1,35 @@ +---@class Item.Settings +---@field name string +---@field title string 1st line of item description +---@field description string the rest of item description +---@field visual Enum.EnumKey from ENUM `Item.VisualEnum` +--- +---@field groups table? +--- +---@field inventory_image string? +---@field inventory_overlay string? +--- +---@field wield_image string? +---@field wield_overlay string? +---@field wield_scale table? +--- +---@field palette string? +---@field color string? +--- +---@field stack_max number? +---@field range number? +---@field liquids_pointable boolean? +---@field pointabilities table? +---@field light_source number? +--- +---@field tool_capabilities table? +---@field wear_color table? +--- +---@field node_placement_prediction string? +---@field node_dig_prediction string? +---@field touch_interaction table? +--- +---@field sound table? +local Settings = {} + +return Settings \ No newline at end of file diff --git a/mods/CORE/Item/src/VisualEnum.lua b/mods/CORE/Item/src/Item/VisualEnum.lua similarity index 100% rename from mods/CORE/Item/src/VisualEnum.lua rename to mods/CORE/Item/src/Item/VisualEnum.lua diff --git a/mods/CORE/Item/src/ItemDefinition/Callbacks.lua b/mods/CORE/Item/src/ItemDefinition/Callbacks.lua deleted file mode 100644 index 0f93559..0000000 --- a/mods/CORE/Item/src/ItemDefinition/Callbacks.lua +++ /dev/null @@ -1,4 +0,0 @@ ----@class Item.ItemDefinition.Callbacks -local Callbacks = {} - -return Callbacks \ No newline at end of file diff --git a/mods/CORE/Item/src/ItemDefinition/Settings.lua b/mods/CORE/Item/src/ItemDefinition/Settings.lua deleted file mode 100644 index 9a6094f..0000000 --- a/mods/CORE/Item/src/ItemDefinition/Settings.lua +++ /dev/null @@ -1,8 +0,0 @@ ----@class Item.ItemDefinition.Settings ----@field name string ----@field title string 1st line of item description ----@field description string the rest of item description ----@field visual Enum.EnumKey from ENUM `Item.ItemDefinition.Settings.VisualEnum` -local Settings = {} - -return Settings \ No newline at end of file