Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use sfinv if possible, fixes #124 with recent minetest versions
  • Loading branch information
sfan5 committed Mar 11, 2017
1 parent c0f3bb6 commit 610cd99
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion worldedit_gui/depends.txt
Expand Up @@ -2,4 +2,5 @@ worldedit
worldedit_commands
unified_inventory?
inventory_plus?
creative?
sfinv?
creative?
30 changes: 30 additions & 0 deletions worldedit_gui/init.lua
Expand Up @@ -131,7 +131,37 @@ elseif rawget(_G, "inventory_plus") then --inventory++ installed
inventory_plus.set_inventory_formspec(player, get_formspec(name, page))
end
end
elseif rawget(_G, "sfinv") then --sfinv installed (part of minetest_game since 0.4.15)
assert(sfinv.enabled)
local orig_get = sfinv.pages["sfinv:crafting"].get
sfinv.override_page("sfinv:crafting", {
get = function(self, player, context)
local can_worldedit = minetest.check_player_privs(player, {worldedit=true})
local fs = orig_get(self, player, context)
return fs .. (can_worldedit and "image_button[0,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]" or "")
end
})

--show the form when the button is pressed and hide it when done
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.worldedit_gui then --main page
worldedit.show_page(player:get_player_name(), "worldedit_gui")
return true
elseif fields.worldedit_gui_exit then --return to original page
sfinv.set_page(player, "sfinv:crafting")
return true
end
return false
end)

worldedit.show_page = function(name, page)
local player = minetest.get_player_by_name(name)
if player then
player:set_inventory_formspec(get_formspec(name, page))
end
end
else --fallback button
-- FIXME: this is a huge clusterfuck and the back button is broken
local player_formspecs = {}

local update_main_formspec = function(name)
Expand Down

0 comments on commit 610cd99

Please sign in to comment.