item.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. ---@meta
  2. ---Items
  3. --------
  4. -- Items are things that can be held by players, dropped in the map and
  5. -- stored in inventories.
  6. -- Items come in the form of item stacks, which are collections of equal
  7. -- items that occupy a single inventory slot.
  8. --
  9. -- Items and item stacks can exist in three formats: `ItemString`, `ItemTable`
  10. -- and `ItemStack`.
  11. --
  12. -- When an item must be passed to a function, it can usually be in any of
  13. -- these formats.
  14. ---@alias mt.Item mt.ItemStack|mt.ItemString|mt.ItemTable|nil
  15. -- It is a simple string with 1-4 components:
  16. --
  17. -- 1. Full item identifier ("item name")
  18. -- 2. Optional amount
  19. -- 3. Optional wear value
  20. -- 4. Optional item metadata
  21. --
  22. -- Syntax:
  23. --
  24. -- <identifier> [<amount>[ <wear>[ <metadata>]]]
  25. --
  26. -- Examples:
  27. --
  28. -- * `"default:apple"`: 1 apple
  29. -- * `"default:dirt 5"`: 5 dirt
  30. -- * `"default:pick_stone"`: a new stone pickaxe
  31. -- * `"default:pick_wood 1 21323"`: a wooden pickaxe, ca. 1/3 worn out
  32. -- * `[[default:pick_wood 1 21323 "\u0001description\u0002My worn out pick\u0003"]]`:
  33. -- * a wooden pickaxe from the `default` mod,
  34. -- * amount must be 1 (pickaxe is a tool), ca. 1/3 worn out (it's a tool),
  35. -- * with the `description` field set to `"My worn out pick"` in its metadata
  36. -- * `[[default:dirt 5 0 "\u0001description\u0002Special dirt\u0003"]]`:
  37. -- * analogous to the above example
  38. -- * note how the wear is set to `0` as dirt is not a tool
  39. --
  40. -- You should ideally use the `ItemStack` format to build complex item strings
  41. -- (especially if they use item metadata)
  42. -- without relying on the serialization format. Example:
  43. --
  44. -- local stack = ItemStack("default:pick_wood")
  45. -- stack:set_wear(21323)
  46. -- stack:get_meta():set_string("description", "My worn out pick")
  47. -- local itemstring = stack:to_string()
  48. --
  49. -- Additionally the methods `minetest.itemstring_with_palette(item, palette_index)`
  50. -- and `minetest.itemstring_with_color(item, colorstring)` may be used to create
  51. -- item strings encoding color information in their metadata.
  52. ---@alias mt.ItemString string
  53. -- 5 dirt nodes:
  54. --
  55. -- {name="default:dirt", count=5, wear=0, metadata=""}
  56. --
  57. -- A wooden pick about 1/3 worn out:
  58. --
  59. -- {name="default:pick_wood", count=1, wear=21323, metadata=""}
  60. --
  61. -- An apple:
  62. --
  63. -- {name="default:apple", count=1, wear=0, metadata=""}
  64. ---@class mt.ItemTable
  65. ---@field name string
  66. ---@field count number
  67. ---@field wear number
  68. ---@field metadata string