Installing
----------
-In order to use the WorldEdit GUI, you must have one of the following mods installed:
-
-* [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) (RECOMMENDED)
-* [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204)
-
-Installation of Unified Inventory is highly recommended. If neither of these mods are installed, the WorldEdit GUI will not be available, though the rest of WorldEdit will work fine.
If you are using Windows, consider installing this mod using [MODSTER](https://forum.minetest.net/viewtopic.php?id=6497), a super simple mod installer that will take care of everything for you. If you are using MODSTER, skip directly to step 6 in the instructions below.
WorldEdit works quite well with other mods, and does not have any known mod conflicts.
-WorldEdit GUI requires either [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) or [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204) to be installed in order to use it. This is optional but highly recommended.
+WorldEdit GUI works with [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) and [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204), but these are not required to use the mod.
+
+If you use any other inventory manager mods, note that they may conflict with the WorldEdit GUI. If this is the case, it may be necessary to disable them.
WorldEdit API
-------------
* You have WorldEdit installed as a mod.\r
* If using Windows, [MODSTER](https://forum.minetest.net/viewtopic.php?pid=101463) makes installing mods totally painless.\r
* Simply download the file, extract the archive, and move it to the correct mod folder for Minetest.\r
- * If you want to use the WorldEdit GUI, you have installed either [Unified Inventory](https://forum.minetest.net/viewtopic.php?id=3933) (recommended), or [Inventory++](https://forum.minetest.net/viewtopic.php?id=6204).\r
* See the installation instructions in [README](README.md) if you need more details.\r
* You are familiar with the basics of the game.\r
* How to walk, jump, and climb.\r
\r
### WorldEdit GUI\r
\r
-Open the main WorldEdit GUI from your inventory screen.\r
+Open the main WorldEdit GUI from your inventory screen. The icon looks like a globe with a red dot in the center.\r
\r
Press the "Get/Set Positions" button. On the new screen, press the "Set Position 1" button. The inventory screen should close.\r
\r
worldedit = worldedit or {}
---wip: simply add a button to the player inventory if unified_inventory AND inventory++ are both not installed
-
--[[
Example:
return worldedit.pages["worldedit_gui"].get_formspec(name) --default to showing main page if an unknown page is given
end
-if unified_inventory then
+--implement worldedit.show_page(name, page) in different ways depending on the available APIs
+if unified_inventory then --unified inventory installed
local old_func = worldedit.register_gui_function
worldedit.register_gui_function = function(identifier, options)
old_func(identifier, options)
worldedit.show_page = function(name, page)
minetest.get_player_by_name(name):set_inventory_formspec(get_formspec(name, page))
end
-elseif inventory_plus then
+elseif inventory_plus then --inventory++ installed
minetest.register_on_joinplayer(function(player)
inventory_plus.register_button(player, "worldedit_gui", "WorldEdit")
end)
worldedit.show_page = function(name, page)
inventory_plus.set_inventory_formspec(minetest.get_player_by_name(name), get_formspec(name, page))
end
-else
+else --fallback button
+ local player_formspecs = {}
+
+ local update_main_formspec = function(name)
+ local formspec = player_formspecs[name]
+ if not formspec then
+ return
+ end
+ local player = minetest.get_player_by_name(name)
+ if minetest.setting_getbool("creative_mode") and creative_inventory then --creative_inventory is active
+ formspec = formspec .. "image_button[6,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]"
+ else
+ formspec = formspec .. "image_button[0,0;1,1;inventory_plus_worldedit_gui.png;worldedit_gui;]"
+ end
+ player:set_inventory_formspec(formspec)
+ end
+
+ minetest.register_on_joinplayer(function(player)
+ local name = player:get_player_name()
+ minetest.after(1, function()
+ player_formspecs[name] = player:get_inventory_formspec()
+ minetest.after(0.01, function()
+ update_main_formspec(name)
+ end)
+ end)
+ end)
+
+ minetest.register_on_leaveplayer(function(player)
+ player_formspecs[player:get_player_name()] = nil
+ end)
+
+ minetest.register_on_player_receive_fields(function(player, formname, fields)
+ local name = player:get_player_name()
+ if fields.worldedit_gui then --main page
+ worldedit.show_page(name, "worldedit_gui")
+ return true
+ elseif fields.worldedit_gui_exit then --return to original page
+ update_main_formspec(name)
+ return true
+ else --deal with creative_inventory setting the formspec on every single message
+ minetest.after(0.01,function()
+ update_main_formspec(name)
+ end)
+ return false --continue processing in creative inventory
+ end
+ end)
+
worldedit.show_page = function(name, page)
- minetest.log("error", "WorldEdit GUI cannot be shown, requires unified_inventory or inventory_plus")
+ local player = minetest.get_player_by_name(name)
+ player:set_inventory_formspec(get_formspec(name, page))
end
- minetest.log("error", "WorldEdit GUI is unavailable, requires unified_inventory or inventory_plus")
end
worldedit.register_gui_function("worldedit_gui", {