mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 00:53:00 +00:00
//torus update
This commit is contained in:
parent
9bb9aeda5c
commit
5b893901dc
2 changed files with 9 additions and 7 deletions
|
@ -11,7 +11,7 @@
|
||||||
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
|
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
|
||||||
local matrix = {x='yz', y='xz', z='xy'}
|
local matrix = {x='yz', y='xz', z='xy'}
|
||||||
if type(axes) ~= "string" then axes = "xz" end
|
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 }
|
-- position = { x, y, z }
|
||||||
local total_radius = major_radius + minor_radius
|
local total_radius = major_radius + minor_radius
|
||||||
|
|
|
@ -35,21 +35,23 @@ local function parse_params_torus(params_text)
|
||||||
if axes:find("[^xyz]") then
|
if axes:find("[^xyz]") then
|
||||||
return false, "Error: The axes may only contain the letters x, y, and z."
|
return false, "Error: The axes may only contain the letters x, y, and z."
|
||||||
end
|
end
|
||||||
if #axes ~= 2 then
|
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)."
|
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
|
||||||
end
|
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)
|
-- Sort the axis names (this is important to ensure we can identify the direction properly)
|
||||||
if axes == "yx" then axes = "xy" end
|
if axes == "yx" then axes = "xy" end
|
||||||
if axes == "zx" then axes = "xz" end
|
if axes == "zx" then axes = "xz" end
|
||||||
if axes == "zy" then axes = "yz" 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
|
end
|
||||||
|
|
||||||
worldedit.register_command("torus", {
|
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).",
|
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 },
|
privs = { worldedit = true },
|
||||||
require_pos = 1,
|
require_pos = 1,
|
||||||
|
@ -60,9 +62,9 @@ worldedit.register_command("torus", {
|
||||||
nodes_needed = function(name, target_node, major_radius, minor_radius)
|
nodes_needed = function(name, target_node, major_radius, minor_radius)
|
||||||
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
||||||
end,
|
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 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
|
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")
|
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
|
|
Loading…
Reference in a new issue