mod_api.txt 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. unified_inventory API
  2. =====================
  3. This file provides information about the API of unified_inventory.
  4. API revisions within unified_inventory can be checked using:
  5. (unified_inventory.version or 1)
  6. **Revision history**
  7. * Version `1`: Classic formspec layout (no real_coordinates)
  8. * Version `2`: Force formspec version 4 (includes real_coordinates)
  9. Misc functions
  10. --------------
  11. Grouped by use-case, afterwards sorted alphabetically.
  12. * `unified_inventory.is_creative(name)`
  13. * Checks whether creative is enabled or the player has `creative`
  14. Pages
  15. -----
  16. Register a new page: The callback inside this function is called on user input.
  17. unified_inventory.register_page("pagename", {
  18. get_formspec = function(player)
  19. -- ^ `player` is an `ObjectRef`
  20. -- Compute the formspec string here
  21. return {
  22. formspec = "button[2,2;2,1;mybutton;Press me]",
  23. -- ^ Final form of the formspec to display
  24. draw_inventory = false, -- default `true`
  25. -- ^ Optional. Hides the player's `main` inventory list
  26. draw_item_list = false, -- default `true`
  27. -- ^ Optional. Hides the item list on the right side
  28. formspec_prepend = false, -- default `false`
  29. -- ^ Optional. When `false`: Disables the formspec prepend
  30. }
  31. end,
  32. })
  33. Buttons
  34. -------
  35. Register a new button for the bottom row:
  36. unified_inventory.register_button("skins", {
  37. type = "image",
  38. image = "skins_skin_button.png",
  39. tooltip = "Skins",
  40. hide_lite = true
  41. -- ^ Button is hidden when following two conditions are met:
  42. -- Configuration line `unified_inventory_lite = true`
  43. -- Player does not have the privilege `ui_full`
  44. })
  45. Crafting
  46. --------
  47. The code blocks below document each possible parameter using exemplary values.
  48. Provide information to display custom craft types:
  49. unified_inventory.register_craft_type("mytype", {
  50. -- ^ Unique identifier for `register_craft`
  51. description = "Sample Craft",
  52. -- ^ Text shown below the crafting arrow
  53. icon = "dummy.png",
  54. -- ^ Image shown above the crafting arrow
  55. width = 3,
  56. height = 3,
  57. -- ^ Maximal input dimensions of the recipes
  58. dynamic_display_size = function(craft)
  59. -- ^ `craft` is the definition from `register_craft`
  60. return {
  61. width = 2,
  62. height = 3
  63. }
  64. end,
  65. -- ^ Optional callback to change the displayed recipe size
  66. uses_crafting_grid = true,
  67. })
  68. Register a non-standard craft recipe:
  69. unified_inventory.register_craft({
  70. output = "default:foobar",
  71. type = "mytype",
  72. -- ^ Standard craft type or custom (see `register_craft_type`)
  73. items = {
  74. { "default:foo" },
  75. { "default:bar" }
  76. },
  77. width = 3,
  78. -- ^ Same as `minetest.register_recipe`
  79. })
  80. Categories
  81. ----------
  82. Register a new category:
  83. The config table (second argument) is optional, and all its members are optional
  84. See the unified_inventory.set_category_* functions for more details on the members of the config table
  85. unified_inventory.register_category("category_name", {
  86. symbol = "mod_name:item_name" or "texture.png",
  87. label = "Human Readable Label",
  88. index = 5,
  89. items = {
  90. "mod_name:item_name",
  91. "another_mod:different_item"
  92. }
  93. })
  94. Add / override the symbol for a category:
  95. The category does not need to exist first
  96. The symbol can be an item name or a texture image
  97. If unset this will default to "default:stick"
  98. unified_inventory.set_category_symbol("category_name", "mod_name:item_name" or "texture.png")
  99. Add / override the human readable label for a category:
  100. If unset this will default to the category name
  101. unified_inventory.set_category_label("category_name", "Human Readable Label")
  102. Add / override the sorting index of the category:
  103. Must be a number, can also be negative (-5) or fractional (2.345)
  104. This determines the position the category appears in the list of categories
  105. The "all" meta-category has index -2, the "misc"/"uncategorized" meta-category has index -1, use a negative number smaller than these to make a category appear before these in the list
  106. By default categories are sorted alphabetically with an index between 0.0101(AA) and 0.2626(ZZ)
  107. unified_inventory.set_category_index("category_name", 5)
  108. Add a single item to a category:
  109. unified_inventory.add_category_item("category_name", "mod_name:item_name")
  110. Add multiple items to a category:
  111. unified_inventory.add_category_items("category_name", {
  112. "mod_name:item_name",
  113. "another_mod:different_item"
  114. })
  115. Remove an item from a category:
  116. unified_inventory.remove_category_item("category_name", "mod_name:item_name")
  117. Remove a category entirely:
  118. unified_inventory.remove_category("category_name")
  119. Finding existing items in categories:
  120. This will find the first category an item exists in
  121. It should be used for checking if an item is catgorised
  122. Returns "category_name" or nil
  123. unified_inventory.find_category("mod_name:item_name")
  124. This will find all the categories an item exists in
  125. Returns a number indexed table (list) of category names
  126. unified_inventory.find_categories("mod_name:item_name")