From 5011e1220909155693de7bf5daeb871059fcd36d Mon Sep 17 00:00:00 2001 From: AFCMS Date: Sat, 10 Sep 2022 23:33:16 +0200 Subject: [PATCH] mcl_inventory API documentation + fix --- mods/HUD/mcl_inventory/API.md | 35 +++++++++++++++++++++++++++++ mods/HUD/mcl_inventory/survival.lua | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/mods/HUD/mcl_inventory/API.md b/mods/HUD/mcl_inventory/API.md index e69de29bb..5fc5a8d6e 100644 --- a/mods/HUD/mcl_inventory/API.md +++ b/mods/HUD/mcl_inventory/API.md @@ -0,0 +1,35 @@ +# `mcl_inventory` + +## `mcl_inventory.register_survival_inventory_tab(def)` + +```lua +mcl_inventory.register_survival_inventory_tab({ + -- Page identifier + -- Used to uniquely identify the tab + id = "test", + + -- The tab description, can be translated + description = "Test", + + -- The name of the item that will be used as icon + item_icon = "mcl_core:stone", + + -- If true, the main inventory will be shown at the bottom of the tab + -- Listrings need to be added by hand + show_inventory = true, + + -- This function must return the tab's formspec for the player + build = function(player) + return "label[1,1;Hello hello]button[2,2;2,2;Hello;hey]" + end, + + -- This function will be called in the on_player_receive_fields callback if the tab is currently open + handle = function(player, fields) + print(dump(fields)) + end, + + -- This function will be called to know if a player can see the tab + -- Returns true by default + access = function(player) + end, +``` diff --git a/mods/HUD/mcl_inventory/survival.lua b/mods/HUD/mcl_inventory/survival.lua index 0ca22d119..5b5c6032c 100644 --- a/mods/HUD/mcl_inventory/survival.lua +++ b/mods/HUD/mcl_inventory/survival.lua @@ -21,6 +21,10 @@ function mcl_inventory.register_survival_inventory_tab(def) assert(def.build) assert(def.handle) + for _, d in ipairs(mcl_inventory.registered_survival_inventory_tabs) do + assert(d.id ~= def.id, "Another tab exists with the same name!") + end + if not def.access then function def.access(player) return true @@ -62,6 +66,7 @@ local function build_page(player, content, inventory, tabname) ",-1.34;1.5,1.44;" .. (tabname == d.id and "crafting_creative_active.png" or "crafting_creative_inactive.png") .. "]", "item_image_button[" .. (0.44 + (i - 1) * 1.6) .. ",-1.1;1,1;" .. d.item_icon .. ";" .. btn_name .. ";]", + "tooltip[" .. btn_name .. ";" .. F(d.description) .. "]" }) end end