mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-30 19:13:53 +01:00
Ellipsoid parsing overhaul with hollow option addition
This commit is contained in:
parent
6e04b11e18
commit
956fc5370a
@ -3,35 +3,39 @@
|
|||||||
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
|
-- █████ ██ ██ ██ ██████ ███████ ██ ██ ██ ██ ██
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
|
-- ███████ ███████ ███████ ██ ██ ███████ ██████ ██ ██████
|
||||||
|
local wea = worldeditadditions
|
||||||
local function parse_params_ellipsoid(params_text)
|
local function parse_params_ellipsoid(params_text)
|
||||||
local found, _, radius_x, radius_y, radius_z, replace_node = params_text:find("([0-9]+)%s+([0-9]+)%s+([0-9]+)%s+([a-z:_\\-]+)")
|
local parts = worldeditadditions.split(params_text, "%s+", false)
|
||||||
|
-- Test: ('1 2 3 stone h')
|
||||||
|
-- Test: ('1 gill 3 stone h')
|
||||||
|
-- /lua a = worldeditadditions.split(" ", "%s+", false)
|
||||||
|
-- /lua worldeditadditions.split(" ", "%s+", false)
|
||||||
|
|
||||||
if found == nil then
|
if #parts < 4 then
|
||||||
return false, "Invalid syntax"
|
return false, "Error: Not enough arguments. Expected \"<rx> <ry> <rz> <replace_node> [h[ollow]]\"."
|
||||||
end
|
end
|
||||||
|
|
||||||
local radius = {
|
local radius = minetest.string_to_pos(parts[1].." "..parts[2].." "..parts[3])
|
||||||
x = tonumber(radius_x),
|
if not radius then
|
||||||
y = tonumber(radius_y),
|
return false, "Error: 3 radii must be specified."
|
||||||
z = tonumber(radius_z)
|
end
|
||||||
}
|
wea.vector.abs(radius)
|
||||||
|
|
||||||
replace_node = worldedit.normalize_nodename(replace_node)
|
local replace_node = worldedit.normalize_nodename(parts[4])
|
||||||
if not replace_node then
|
if not replace_node then
|
||||||
worldedit.player_notify(name, "Error: Invalid node name.")
|
return false, "Error: Invalid replace_node specified."
|
||||||
return false
|
|
||||||
end
|
|
||||||
if not radius.x or not radius.y or not radius.z then
|
|
||||||
worldedit.player_notify(name, "Error: Invalid radius(es).")
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, replace_node, radius
|
local hollow = false
|
||||||
|
if parts[5] == "hollow" or parts[5] == "h" then
|
||||||
|
hollow = true
|
||||||
|
end
|
||||||
|
|
||||||
|
return true, replace_node, radius, hollow
|
||||||
end
|
end
|
||||||
|
|
||||||
worldedit.register_command("ellipsoid", {
|
worldedit.register_command("ellipsoid", {
|
||||||
params = "<rx> <ry> <rz> <replace_node>",
|
params = "<rx> <ry> <rz> <replace_node> [h[ollow]]",
|
||||||
description = "Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with <replace_node>.",
|
description = "Creates a 3D ellipsoid with a radius of (rx, ry, rz) at pos1, filled with <replace_node>.",
|
||||||
privs = { worldedit = true },
|
privs = { worldedit = true },
|
||||||
require_pos = 1,
|
require_pos = 1,
|
||||||
@ -42,9 +46,9 @@ worldedit.register_command("ellipsoid", {
|
|||||||
nodes_needed = function(name, target_node, radius)
|
nodes_needed = function(name, target_node, radius)
|
||||||
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
return math.ceil(4/3 * math.pi * radius.x * radius.y * radius.z)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, radius)
|
func = function(name, target_node, radius, hollow)
|
||||||
local start_time = worldeditadditions.get_ms_time()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, false)
|
local replaced = worldeditadditions.ellipsoid(worldedit.pos1[name], radius, target_node, hollow)
|
||||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //ellipsoid at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
|
Loading…
Reference in New Issue
Block a user