diff options
author | Vanessa Ezekowitz <vanessaezekowitz@gmail.com> | 2016-04-01 21:00:20 -0400 |
---|---|---|
committer | Vanessa Ezekowitz <vanessaezekowitz@gmail.com> | 2016-04-01 21:10:04 -0400 |
commit | 888b0ebfec8c2eff9015163549a7e47443cb8665 (patch) | |
tree | 915080159bfaa6ba6e226087c7ce0e8d5464b518 /worldedit_commands/safe.lua | |
parent | da66780a569712c23ae4f2996cfb4608a9f9d69d (diff) | |
download | dreambuilder_modpack-888b0ebfec8c2eff9015163549a7e47443cb8665.tar dreambuilder_modpack-888b0ebfec8c2eff9015163549a7e47443cb8665.tar.gz dreambuilder_modpack-888b0ebfec8c2eff9015163549a7e47443cb8665.tar.bz2 dreambuilder_modpack-888b0ebfec8c2eff9015163549a7e47443cb8665.tar.xz dreambuilder_modpack-888b0ebfec8c2eff9015163549a7e47443cb8665.zip |
"explode" all modpacks into their individual components
(you can't have a modpack buried inside a modpack)
Diffstat (limited to 'worldedit_commands/safe.lua')
-rw-r--r-- | worldedit_commands/safe.lua | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/worldedit_commands/safe.lua b/worldedit_commands/safe.lua new file mode 100644 index 0000000..e640853 --- /dev/null +++ b/worldedit_commands/safe.lua @@ -0,0 +1,68 @@ +local safe_region_callback = {}
+local safe_region_param = {}
+
+local function check_region(name, param)
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name] --obtain positions
+ if pos1 == nil or pos2 == nil then
+ worldedit.player_notify(name, "no region selected")
+ return nil
+ end
+ return worldedit.volume(pos1, pos2)
+end
+
+--`callback` is a callback to run when the user confirms
+--`nodes_needed` is a function accepting `param`, `pos1`, and `pos2` to calculate the number of nodes needed
+local function safe_region(callback, nodes_needed)
+ --default node volume calculation
+ nodes_needed = nodes_needed or check_region
+
+ return function(name, param)
+ --check if the operation applies to a safe number of nodes
+ local count = nodes_needed(name, param)
+ if count == nil then return end --invalid command
+ if count < 10000 then
+ return callback(name, param)
+ end
+
+ --save callback to call later
+ safe_region_callback[name], safe_region_param[name] = callback, param
+ worldedit.player_notify(name, "WARNING: this operation could affect up to " .. count .. " nodes; type //y to continue or //n to cancel")
+ end
+end
+
+minetest.register_chatcommand("/y", {
+ params = "",
+ description = "Confirm a pending operation",
+ func = function(name)
+ local callback, param = safe_region_callback[name], safe_region_param[name]
+ if not callback then
+ worldedit.player_notify(name, "no operation pending")
+ return
+ end
+
+ --obtain positions
+ local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
+ if pos1 == nil or pos2 == nil then
+ worldedit.player_notify(name, "no region selected")
+ return
+ end
+
+ safe_region_callback[name], safe_region_param[name] = nil, nil --reset pending operation
+ callback(name, param, pos1, pos2)
+ end,
+})
+
+minetest.register_chatcommand("/n", {
+ params = "",
+ description = "Confirm a pending operation",
+ func = function(name)
+ if not safe_region_callback[name] then
+ worldedit.player_notify(name, "no operation pending")
+ return
+ end
+ safe_region_callback[name], safe_region_param[name] = nil, nil
+ end,
+})
+
+return safe_region, check_region
+
|