mod_api.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. unified_inventory API
  2. =====================
  3. This file provides information about the API of unified_inventory.
  4. Misc functions
  5. --------------
  6. Grouped by use-case, afterwards sorted alphabetically.
  7. * `unified_inventory.is_creative(name)`
  8. * Checks whether creative is enabled or the player has `creative`
  9. Pages
  10. -----
  11. Register a new page: The callback inside this function is called on user input.
  12. unified_inventory.register_page("pagename", {
  13. get_formspec = function(player)
  14. -- ^ `player` is an `ObjectRef`
  15. -- Compute the formspec string here
  16. return {
  17. formspec = "button[2,2;2,1;mybutton;Press me]",
  18. -- ^ Final form of the formspec to display
  19. draw_inventory = false, -- default `true`
  20. -- ^ Optional. Hides the player's `main` inventory list
  21. draw_item_list = false, -- default `true`
  22. -- ^ Optional. Hides the item list on the right side
  23. formspec_prepend = false, -- default `false`
  24. -- ^ Optional. When `false`: Disables the formspec prepend
  25. }
  26. end,
  27. })
  28. Buttons
  29. -------
  30. Register a new button for the bottom row:
  31. unified_inventory.register_button("skins", {
  32. type = "image",
  33. image = "skins_skin_button.png",
  34. tooltip = "Skins",
  35. hide_lite = true
  36. -- ^ Button is hidden when following two conditions are met:
  37. -- Configuration line `unified_inventory_lite = true`
  38. -- Player does not have the privilege `ui_full`
  39. })
  40. Crafting
  41. --------
  42. The code blocks below document each possible parameter using exemplary values.
  43. Provide information to display custom craft types:
  44. unified_inventory.register_craft_type("mytype", {
  45. -- ^ Unique identifier for `register_craft`
  46. description = "Sample Craft",
  47. -- ^ Text shown below the crafting arrow
  48. icon = "dummy.png",
  49. -- ^ Image shown above the crafting arrow
  50. width = 3,
  51. height = 3,
  52. -- ^ Maximal input dimensions of the recipes
  53. dynamic_display_size = function(craft)
  54. -- ^ `craft` is the definition from `register_craft`
  55. return {
  56. width = 2,
  57. height = 3
  58. }
  59. end,
  60. -- ^ Optional callback to change the displayed recipe size
  61. uses_crafting_grid = true,
  62. })
  63. Register a non-standard craft recipe:
  64. unified_inventory.register_craft({
  65. output = "default:foobar",
  66. type = "mytype",
  67. -- ^ Standard craft type or custom (see `register_craft_type`)
  68. items = {
  69. { "default:foo" },
  70. { "default:bar" }
  71. },
  72. width = 3,
  73. -- ^ Same as `minetest.register_recipe`
  74. })