From def676cd2d12e16a3fc7e2a1995166dd65d5a1a3 Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Tue, 25 Sep 2012 18:42:10 -0400 Subject: Add worldedit.hollow_sphere, worldedit.sphere, //hollowsphere, and //sphere, improve cylinder docs slightly. --- functions.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'functions.lua') 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) -- cgit v1.2.3