mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 05:43:43 +01:00
mcl_inventory API documentation + fix
This commit is contained in:
parent
f6804600ba
commit
5011e12209
@ -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,
|
||||
```
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user