Skip to content
Permalink
Browse files

Use sfinv if possible, fixes #124 with recent minetest versions

  • Loading branch information
sfan5 committed Mar 11, 2017
1 parent c0f3bb6 commit 610cd9981dbb2649308172936a1c5f626581a4c5
Showing with 32 additions and 1 deletion.
  1. +2 −1 worldedit_gui/depends.txt
  2. +30 −0 worldedit_gui/init.lua
@@ -2,4 +2,5 @@ worldedit
worldedit_commands
unified_inventory?
inventory_plus?
creative?
sfinv?
creative?
@@ -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)

0 comments on commit 610cd99

Please sign in to comment.
You can’t perform that action at this time.