From 0a4499267669a9c50b3ba1542155d9f8b2a33fdf Mon Sep 17 00:00:00 2001 From: VorTechnix <45538536+VorTechnix@users.noreply.github.com> Date: Mon, 17 May 2021 17:16:04 -0700 Subject: [PATCH] reference: add hollow example to torus --- worldeditadditions/lib/torus.lua | 2 +- worldeditadditions_commands/commands/torus.lua | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/worldeditadditions/lib/torus.lua b/worldeditadditions/lib/torus.lua index 5c4b3ac..66d5c99 100644 --- a/worldeditadditions/lib/torus.lua +++ b/worldeditadditions/lib/torus.lua @@ -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 diff --git a/worldeditadditions_commands/commands/torus.lua b/worldeditadditions_commands/commands/torus.lua index e9bf88c..cbaf93f 100644 --- a/worldeditadditions_commands/commands/torus.lua +++ b/worldeditadditions_commands/commands/torus.lua @@ -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 = " []", + params = " [] [h[ollow]]", description = "Creates a 3D torus with a major radius of and a minor radius of at pos1, filled with , on 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")