mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-22 15:33:00 +00:00
migrate //overlaya to worldedit.register_command
This commit is contained in:
parent
afce170d4c
commit
ae068989e2
3 changed files with 17 additions and 26 deletions
|
@ -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
|
### 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.
|
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
|
## Contributing
|
||||||
Contributions are welcome! Please state in your pull request(s) that you release your contribution under the _Mozilla Public License 2.0_.
|
Contributions are welcome! Please state in your pull request(s) that you release your contribution under the _Mozilla Public License 2.0_.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
--- Overlap command. Places a specified node on top of each column.
|
--- Overlap command. Places a specified node on top of each column.
|
||||||
-- @module worldeditadditions.overlay
|
-- @module worldeditadditions.overlay
|
||||||
|
|
||||||
function worldedit.overlay(pos1, pos2, target_node)
|
function worldeditadditions.overlay(pos1, pos2, target_node)
|
||||||
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
-- pos2 will always have the highest co-ordinates now
|
-- pos2 will always have the highest co-ordinates now
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,31 @@
|
||||||
local we_c = worldeditadditions_commands
|
|
||||||
|
|
||||||
-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██
|
-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████
|
-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██
|
-- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██
|
||||||
|
worldedit.register_command("overlay", {
|
||||||
minetest.register_chatcommand("/overlay", {
|
|
||||||
params = "<replace_node>",
|
params = "<replace_node>",
|
||||||
description = "Places <replace_node> 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 <replace_node>.",
|
description = "Places <replace_node> 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 <replace_node>.",
|
||||||
privs = { worldedit = true },
|
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)
|
local target_node = worldedit.normalize_nodename(params_text)
|
||||||
|
|
||||||
if not target_node then
|
if not target_node then
|
||||||
worldedit.player_notify(name, "Error: Invalid node name.")
|
return false, "Error: Invalid node name"
|
||||||
return false
|
|
||||||
end
|
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 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
|
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")
|
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)
|
return true, changes.updated .. " nodes replaced and " .. changes.skipped_columns .. " columns skipped in " .. time_taken .. "s"
|
||||||
if not worldedit.normalize_nodename(params_text) then
|
end
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue