//torus update

This commit is contained in:
VorTechnix 2021-05-17 17:16:04 -07:00
parent 9bb9aeda5c
commit 5b893901dc
2 changed files with 9 additions and 7 deletions

View File

@ -11,7 +11,7 @@
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
local matrix = {x='yz', y='xz', z='xy'}
if type(axes) ~= "string" then axes = "xz" end
if #axes == 1 and axes.match('[xyz]') then axes = matrix[axes] end
if #axes == 1 and axes:match('[xyz]') then axes = matrix[axes] end
-- position = { x, y, z }
local total_radius = major_radius + minor_radius

View File

@ -35,21 +35,23 @@ local function parse_params_torus(params_text)
if axes:find("[^xyz]") then
return false, "Error: The axes may only contain the letters x, y, and z."
end
if #axes ~= 2 then
return false, "Error: Exactly 2 axes must be specified. For example, 'xy' is valid, but 'xyy' is not (both of course without quotes)."
if #axes > 2 then
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
end
local hollow = parts[5]
if hollow == "false" then hollow = false end
-- Sort the axis names (this is important to ensure we can identify the direction properly)
if axes == "yx" then axes = "xy" end
if axes == "zx" then axes = "xz" end
if axes == "zy" then axes = "yz" end
return true, replace_node, major_radius, minor_radius, axes
return true, replace_node, major_radius, minor_radius, axes, hollow
end
worldedit.register_command("torus", {
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>]",
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>] [h[ollow]]",
description = "Creates a 3D torus with a major radius of <major_radius> and a minor radius of <minor_radius> at pos1, filled with <replace_node>, on axes <axes> (i.e. 2 axis names: xz, zy, etc).",
privs = { worldedit = true },
require_pos = 1,
@ -60,9 +62,9 @@ worldedit.register_command("torus", {
nodes_needed = function(name, target_node, major_radius, minor_radius)
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
end,
func = function(name, target_node, major_radius, minor_radius, axes)
func = function(name, target_node, major_radius, minor_radius, axes, hollow)
local start_time = worldeditadditions.get_ms_time()
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, false)
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, hollow)
local time_taken = worldeditadditions.get_ms_time() - start_time
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")