diff --git a/mods/rp_crafting/api.lua b/mods/rp_crafting/api.lua index 2d0dfe5..3d641c0 100644 --- a/mods/rp_crafting/api.lua +++ b/mods/rp_crafting/api.lua @@ -4,6 +4,8 @@ local S = minetest.get_translator("rp_crafting") local MODE_CRAFTABLE = 1 -- crafting guide mode, show all recipes (default) local MODE_GUIDE = 2 -- craftable mode, only show recipes craftable from input slots +local mod_creative = minetest.get_modpath("rp_creative") ~= nil + -- -- API -- @@ -424,13 +426,16 @@ function crafting.get_formspec(name, select_craft_id) return form end - rp_formspec.register_page("rp_crafting:crafting", form) rp_formspec.register_invpage("rp_crafting:crafting", { - is_startpage = function(pname) - return true - end, get_formspec = crafting.get_formspec, + _is_startpage = function(pname) + if mod_creative and minetest.is_creative_enabled(pname) then + return false + else + return true + end + end, }) rp_formspec.register_invtab("rp_crafting:crafting", { diff --git a/mods/rp_creative/init.lua b/mods/rp_creative/init.lua index 8b6d6eb..93c89e2 100644 --- a/mods/rp_creative/init.lua +++ b/mods/rp_creative/init.lua @@ -260,6 +260,13 @@ end rp_formspec.register_page("rp_creative:creative", form) rp_formspec.register_invpage("rp_creative:creative", { get_formspec = creative.get_formspec, + _is_startpage = function(pname) + if minetest.is_creative_enabled(pname) then + return true + else + return false + end + end, }) if minetest.is_creative_enabled("") then rp_formspec.register_invtab("rp_creative:creative", { diff --git a/mods/rp_formspec/init.lua b/mods/rp_formspec/init.lua index 37dd0d1..29ba259 100644 --- a/mods/rp_formspec/init.lua +++ b/mods/rp_formspec/init.lua @@ -403,14 +403,29 @@ minetest.register_on_joinplayer( -- Initialize player formspec and set initial invpage player:set_formspec_prepend(formspec_prepend) local pname = player:get_player_name() + local first_page for invpagename,def in pairs(rp_formspec.registered_invpages) do - if def.is_startpage and def.is_startpage(pname) then + if not first_page then + first_page = invpagename + end + -- _is_startpage returns true if this page + -- is a startpage, false otherwise. + -- As this function only makes sense within the context of a game, + -- it is undocumented in API.md. + if def._is_startpage and def._is_startpage(pname) then rp_formspec.set_current_invpage(player, invpagename) + break end end -- Fallback invpage if not rp_formspec.get_current_invpage(player) then - rp_formspec.set_current_invpage(player, "rp_formspec:inventory") + if first_page then + -- First invpage of the pairs() above (kinda unpredicable tho) + rp_formspec.set_current_invpage(player, first_page) + else + -- Empty inventory fallback page if no invpages registered + rp_formspec.set_current_invpage(player, "rp_formspec:inventory") + end end end)