From 724cd6ccb633fcc55d0210b282cb7bd696329412 Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Thu, 20 Sep 2012 16:25:29 -0400 Subject: [PATCH 1/3] Add cornernote to authors. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d726438..ff79659 100644 --- a/README.md +++ b/README.md @@ -322,7 +322,7 @@ Returns the number of nodes loaded License ------- -Copyright 2012 sfan5 and Anthony Zhang (Temperest) +Copyright 2012 sfan5, Anthony Zhang (Temperest), and Brett O'Donnell (cornernote). This mod is licensed under the [GNU Affero General Public License](http://www.gnu.org/licenses/agpl-3.0.html). From d89fded397184bebe333ceec0f6f48bb7c55378b Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Tue, 25 Sep 2012 17:04:24 -0400 Subject: [PATCH 2/3] Fix negative cylinder lengths (thanks @cornernote). --- functions.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/functions.lua b/functions.lua index 2d16daf..eaac5d6 100644 --- a/functions.lua +++ b/functions.lua @@ -90,6 +90,11 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) local currentpos = {x=pos.x, y=pos.y, z=pos.z} local node = {name=nodename} local count = 0 + local step = 1 + if length < 0 + length = -length + step = -1 + end for i = 1, length do local offset1, offset2 = 0, radius local delta = -radius @@ -126,7 +131,7 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) end offset1 = offset1 + 1 end - currentpos[axis] = currentpos[axis] + 1 + currentpos[axis] = currentpos[axis] + step end return count end @@ -146,6 +151,11 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename) local currentpos = {x=pos.x, y=pos.y, z=pos.z} local node = {name=nodename} local count = 0 + local step = 1 + if length < 0 + length = -length + step = -1 + end for i = 1, length do local offset1, offset2 = 0, radius local delta = -radius @@ -180,7 +190,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename) delta = delta - (offset2 * 2) end end - currentpos[axis] = currentpos[axis] + 1 + currentpos[axis] = currentpos[axis] + step end return count end From def676cd2d12e16a3fc7e2a1995166dd65d5a1a3 Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Tue, 25 Sep 2012 18:42:10 -0400 Subject: [PATCH 3/3] Add worldedit.hollow_sphere, worldedit.sphere, //hollowsphere, and //sphere, improve cylinder docs slightly. --- README.md | 34 ++++++++++++++++++++++++++++++--- functions.lua | 49 +++++++++++++++++++++++++++++++++++++++++++++--- init.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ff79659..e513605 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,22 @@ Replace all instances of with in the current WorldEdi //replace dirt flowers:flower_waterlily //replace flowers:flower_rose flowers:flower_tulip +### //hollowsphere + +Add hollow sphere at WorldEdit position 1 with radius , composed of . + + //hollowsphere 5 dirt + //hollowsphere 12 default:glass + //hollowsphere 17 mesecons:mesecon + +### //sphere + +Add sphere at WorldEdit position 1 with radius , composed of . + + //sphere 5 dirt + //sphere 12 default:glass + //sphere 17 mesecons:mesecon + ### //hollowcylinder x/y/z/? Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of . @@ -228,15 +244,27 @@ Replaces all instances of `searchnode` with `replacenode` in a region defined by Returns the number of nodes replaced. +### worldedit.hollow_sphere = function(pos, radius, nodename) + +Adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`. + +Returns the number of nodes added. + +### worldedit.sphere = function(pos, radius, nodename) + +Adds a sphere at `pos` with radius `radius`, composed of `nodename`. + +Returns the number of nodes added. + ### worldedit.hollow_cylinder(pos, axis, length, radius, nodename) -Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`. +Adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`. 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`. +Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `nodename`. Returns the number of nodes added. @@ -322,7 +350,7 @@ Returns the number of nodes loaded License ------- -Copyright 2012 sfan5, Anthony Zhang (Temperest), and Brett O'Donnell (cornernote). +Copyright 2012 sfan5 and Anthony Zhang (Temperest) This mod is licensed under the [GNU Affero General Public License](http://www.gnu.org/licenses/agpl-3.0.html). diff --git a/functions.lua b/functions.lua index eaac5d6..4b98a84 100644 --- a/functions.lua +++ b/functions.lua @@ -75,7 +75,50 @@ worldedit.replace = function(pos1, pos2, searchnode, replacenode) return count end ---adds a hollow cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, returning the number of nodes added +--adds a hollow sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added +worldedit.hollow_sphere = function(pos, radius, nodename) + local node = {name=nodename} + local pos1 = {x=0, y=0, z=0} + local full_radius = radius * radius + radius + local env = minetest.env + for x = -radius, radius do + pos1.x = pos.x + x + for y = -radius, radius do + pos1.y = pos.y + y + for z = -radius, radius do + if x*x+y*y+z*z >= (radius-1) * (radius-1) + (radius-1) and x*x+y*y+z*z <= full_radius then + pos1.z = pos.z + z + env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}, node) + end + end + end + end +end + +--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added +worldedit.sphere = function(pos, radius, nodename) + local node = {name=nodename} + local pos1 = {x=0, y=0, z=0} + local full_radius = radius * radius + radius + local count = 0 + local env = minetest.env + for x = -radius, radius do + pos1.x = pos.x + x + for y = -radius, radius do + pos1.y = pos.y + y + for z = -radius, radius do + if x*x+y*y+z*z <= full_radius then + pos1.z = pos.z + z + env:add_node(pos1, node) + count = count + 1 + end + end + end + end + return count +end + +--adds a hollow 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.hollow_cylinder = function(pos, axis, length, radius, nodename) local other1, other2 if axis == "x" then @@ -136,7 +179,7 @@ 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`, returning the number of nodes added +--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) local other1, other2 if axis == "x" then @@ -195,7 +238,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename) return count end ---adds a spiral at `pos` with size `size`, returning the number of nodes changed +--adds a spiral at `pos` with size `size`, composed of `nodename`, returning the number of nodes changed worldedit.spiral = function(pos, size, nodename) local shift_x, shift_y sa = spiralt(size) diff --git a/init.lua b/init.lua index 1e9b0ef..a7e1947 100644 --- a/init.lua +++ b/init.lua @@ -189,6 +189,58 @@ minetest.register_chatcommand("/replace", { end, }) +minetest.register_chatcommand("/hollowsphere", { + params = " ", + description = "Add hollow sphere at WorldEdit position 1 with radius , composed of ", + privs = {worldedit=true}, + func = function(name, param) + local pos = worldedit.pos1[name] + if pos == nil then + minetest.chat_send_player(name, "No WorldEdit region selected") + return + end + + local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$") + if found == nil then + minetest.chat_send_player(name, "Invalid usage: " .. param) + return + end + if not worldedit.node_is_valid(pos, nodename) then + minetest.chat_send_player(name, "Invalid node name: " .. param) + return + end + + local count = worldedit.hollow_sphere(pos, tonumber(radius), nodename) + minetest.chat_send_player(name, count .. " nodes added") + end, +}) + +minetest.register_chatcommand("/sphere", { + params = " ", + description = "Add sphere at WorldEdit position 1 with radius , composed of ", + privs = {worldedit=true}, + func = function(name, param) + local pos = worldedit.pos1[name] + if pos == nil then + minetest.chat_send_player(name, "No WorldEdit region selected") + return + end + + local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$") + if found == nil then + minetest.chat_send_player(name, "Invalid usage: " .. param) + return + end + if not worldedit.node_is_valid(pos, nodename) then + minetest.chat_send_player(name, "Invalid node name: " .. param) + return + end + + local count = worldedit.sphere(pos, tonumber(radius), nodename) + minetest.chat_send_player(name, count .. " nodes added") + end, +}) + minetest.register_chatcommand("/hollowcylinder", { params = "x/y/z/? ", description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of ",