From ae068989e20b12e57ec08ef73b34528b333645a5 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 10 May 2020 21:32:01 +0100 Subject: [PATCH] migrate //overlaya to worldedit.register_command --- README.md | 1 + worldeditadditions/overlay.lua | 2 +- .../commands/overlay.lua | 40 +++++++------------ 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index ad35d5d..dca6da2 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ WorldEditAdditions requires that the `worldedit` mod is installed as a dependenc ### I get an error saying that `worldedit.register_command()` is not a function This is probably because your version of `worldedit` is too old. Try updating it. Specifically the `worldedit.register_command()` function was only added to `worldedit` in December 2019. + ## Contributing Contributions are welcome! Please state in your pull request(s) that you release your contribution under the _Mozilla Public License 2.0_. diff --git a/worldeditadditions/overlay.lua b/worldeditadditions/overlay.lua index 8916f45..6cfb7ba 100644 --- a/worldeditadditions/overlay.lua +++ b/worldeditadditions/overlay.lua @@ -1,7 +1,7 @@ --- Overlap command. Places a specified node on top of each column. -- @module worldeditadditions.overlay -function worldedit.overlay(pos1, pos2, target_node) +function worldeditadditions.overlay(pos1, pos2, target_node) pos1, pos2 = worldedit.sort_pos(pos1, pos2) -- pos2 will always have the highest co-ordinates now diff --git a/worldeditadditions_commands/commands/overlay.lua b/worldeditadditions_commands/commands/overlay.lua index 3d9e2d1..c04afc7 100644 --- a/worldeditadditions_commands/commands/overlay.lua +++ b/worldeditadditions_commands/commands/overlay.lua @@ -1,41 +1,31 @@ -local we_c = worldeditadditions_commands - -- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ █████ ██████ ██ ███████ ████ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██ - -minetest.register_chatcommand("/overlay", { +worldedit.register_command("overlay", { params = "", description = "Places in the last contiguous air space encountered above the first non-air node. In other words, overlays all top-most nodes in the specified area with .", privs = { worldedit = true }, - func = we_c.safe_region(function(name, params_text) + require_pos = 2, + parse = function(params_text) local target_node = worldedit.normalize_nodename(params_text) - if not target_node then - worldedit.player_notify(name, "Error: Invalid node name.") - return false + return false, "Error: Invalid node name" end - + return true, target_node + end, + nodes_needed = function(name) + -- //overlay only modifies up to 1 node per column in the selected region + local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name]) + return (pos2.x - pos1.x) * (pos2.y - pos1.y) + end, + func = function(name, target_node) local start_time = os.clock() - local changes = worldedit.overlay(worldedit.pos1[name], worldedit.pos2[name], target_node) + local changes = worldeditadditions.overlay(worldedit.pos1[name], worldedit.pos2[name], target_node) local time_taken = os.clock() - start_time - worldedit.player_notify(name, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s") minetest.log("action", name .. " used //overlay at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.updated .. " nodes and skipping " .. changes.skipped_columns .. " columns in " .. time_taken .. "s") - end, function(name, params_text) - if not worldedit.normalize_nodename(params_text) then - worldedit.player_notify(name, "Error: Invalid node name '" .. params_text .. "'.") - return 0 - end - - local pos1 = worldedit.pos1[name] - local pos2 = worldedit.pos2[name] - pos1, pos2 = worldedit.sort_pos(pos1, pos2) - - local vol = vector.subtract(pos2, pos1) - - return vol.x*vol.z - end) + return true, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s" + end })