From dbbf91dd6e7673b72009f6999064bff253979c25 Mon Sep 17 00:00:00 2001 From: Kyle Date: Thu, 18 Oct 2012 18:10:30 -0700 Subject: [PATCH] dual-based cylinder --- Chat Commands.md | 10 +++++++--- WorldEdit API.md | 4 ++-- worldedit/primitives.lua | 9 ++++++--- worldedit_commands/init.lua | 19 +++++++++++++------ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Chat Commands.md b/Chat Commands.md index f140880..61423ad 100644 --- a/Chat Commands.md +++ b/Chat Commands.md @@ -81,14 +81,18 @@ Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length < //hollowcylinder z -12 3 mesecons:mesecon //hollowcylinder ? 2 4 stone -### //cylinder x/y/z/? +### //cylinder x/y/z/? [] -Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of . +Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length , base radius [and top radius ], composed of . //cylinder x +5 8 dirt //cylinder y 28 10 default:glass //cylinder z -12 3 mesecons:mesecon //cylinder ? 2 4 stone + + //cylinder y 10 10 0 water_flowing + //cylinder x 6 5 0 dirt + //cylinder z 20 10 20 desert_stone ### //pyramid @@ -220,4 +224,4 @@ Save the current WorldEdit region including metadata to "(world folder)/schems/< Load nodes and metadata from "(world folder)/schems/.wem" with position 1 of the current WorldEdit region as the origin. //metaload some random filename - //metaload huge_base \ No newline at end of file + //metaload huge_base diff --git a/WorldEdit API.md b/WorldEdit API.md index 30e4437..dced1d8 100644 --- a/WorldEdit API.md +++ b/WorldEdit API.md @@ -94,7 +94,7 @@ Returns the number of nodes added. ### worldedit.cylinder(pos, axis, length, radius, nodename) -Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`. +Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length`, base radius `radius` (and top radius `radius`), composed of `nodename`. Returns the number of nodes added. @@ -170,4 +170,4 @@ Returns the number of nodes saved. Loads the nodes and meta from `file` to position `pos1`. -Returns the number of nodes loaded. \ No newline at end of file +Returns the number of nodes loaded. diff --git a/worldedit/primitives.lua b/worldedit/primitives.lua index 2685d2b..01afd02 100644 --- a/worldedit/primitives.lua +++ b/worldedit/primitives.lua @@ -104,8 +104,8 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) return count end ---adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`, returning the number of nodes added -worldedit.cylinder = function(pos, axis, length, radius, nodename) +--adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length`, base radius `radius` (and top radius `radius`), composed of `nodename`, returning the number of nodes added +worldedit.cylinder = function(pos, axis, length, radius1, radius2, nodename) local other1, other2 if axis == "x" then other1, other2 = "y", "z" @@ -125,6 +125,9 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename) step = -1 end for i = 1, length do + local radius = radius1 + (radius2 - radius1) * (i - 1) / (length - 1) + --radius shouldn't need rounding + radius = math.floor(radius+0.5) local offset1, offset2 = 0, radius local delta = -radius while offset1 <= offset2 do @@ -256,4 +259,4 @@ worldedit.spiral = function(pos, width, height, spacer, nodename) --wip: clean t end end return count -end \ No newline at end of file +end diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index a1ba9ae..db64cee 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -269,8 +269,8 @@ minetest.register_chatcommand("/hollowcylinder", { }) minetest.register_chatcommand("/cylinder", { - params = "x/y/z/? ", - description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of ", + params = "x/y/z/? [] ", + description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length , base radius [and top radius ], composed of ", privs = {worldedit=true}, func = function(name, param) local pos = worldedit.pos1[name] @@ -279,10 +279,17 @@ minetest.register_chatcommand("/cylinder", { return end - local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$") + --double radius + local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+([^%s]+)$") if found == nil then - minetest.chat_send_player(name, "Invalid usage: " .. param) - return + --single radius + found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+([^%s]+)$") + if found == nil then + --no radius + minetest.chat_send_player(name, "Invalid usage: " .. param) + return + end + radius2 = radius1 end if axis == "?" then axis, sign = worldedit.player_axis(name) @@ -293,7 +300,7 @@ minetest.register_chatcommand("/cylinder", { return end - local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius), nodename) + local count = worldedit.cylinder(pos, axis, tonumber(length), tonumber(radius1), tonumber(radius2), nodename) minetest.chat_send_player(name, count .. " nodes added") end, })