Skip to content

Commit

Permalink
New commands //hollowdome and //dome, as well as new API functions wo…
Browse files Browse the repository at this point in the history
…rldedit.dome and worldedit.hollow_dome. Oh, and spheres generate faster too.
  • Loading branch information
Uberi committed Apr 27, 2013
1 parent 2072238 commit 71b6004
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 7 deletions.
16 changes: 16 additions & 0 deletions Chat Commands.md
Expand Up @@ -83,6 +83,22 @@ Add sphere at WorldEdit position 1 with radius <radius>, composed of <node>.
//sphere 12 default:glass
//sphere 17 mesecons:mesecon

### //hollowdome <radius> <node>

Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>.

//hollowdome 5 dirt
//hollowdome 12 default:glass
//hollowdome 17 mesecons:mesecon

### //dome <radius> <node>

Add dome at WorldEdit position 1 with radius <radius>, composed of <node>.

//dome 5 dirt
//dome 12 default:glass
//dome 17 mesecons:mesecon

### //hollowcylinder x/y/z/? <length> <radius> <node>

Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>.
Expand Down
12 changes: 12 additions & 0 deletions WorldEdit API.md
Expand Up @@ -92,6 +92,18 @@ Adds a sphere at `pos` with radius `radius`, composed of `nodename`.

Returns the number of nodes added.

### count = worldedit.hollow_dome(pos, radius, nodename)

Adds a hollow dome at `pos` with radius `radius`, composed of `nodename`.

Returns the number of nodes added.

### count = worldedit.dome(pos, radius, nodename)

Adds a dome at `pos` with radius `radius`, composed of `nodename`.

Returns the number of nodes added.

### count = 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`, composed of `nodename`.
Expand Down
62 changes: 55 additions & 7 deletions worldedit/primitives.lua
@@ -1,20 +1,21 @@
worldedit = worldedit or {}

--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) --wip: use bresenham sphere for maximum speed
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 min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1)
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 >= (radius-1) * (radius-1) + (radius-1) and x*x+y*y+z*z <= full_radius then
if x*x+y*y+z*z >= min_radius and x*x+y*y+z*z <= max_radius then
pos1.z = pos.z + z
env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z}, node)
env:add_node(pos1, node)
count = count + 1
end
end
Expand All @@ -24,18 +25,65 @@ worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham s
end

--adds a sphere at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
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 max_radius = radius * (radius + 1)
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
if x*x+y*y+z*z <= max_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 dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.hollow_dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
local min_radius = radius * (radius - 1)
local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
for x = -radius, radius do
pos1.x = pos.x + x
for y = 0, radius do
pos1.y = pos.y + y
for z = -radius, radius do
if x*x+y*y+z*z >= min_radius and x*x+y*y+z*z <= max_radius then
pos1.z = pos.z + z
env:add_node(pos1, node)
count = count + 1
end
end
end
end
return count
end

--adds a dome at `pos` with radius `radius`, composed of `nodename`, returning the number of nodes added
worldedit.dome = function(pos, radius, nodename) --wip: use bresenham sphere for maximum speed
local node = {name=nodename}
local pos1 = {x=0, y=0, z=0}
local max_radius = radius * (radius + 1)
local count = 0
local env = minetest.env
for x = -radius, radius do
pos1.x = pos.x + x
for y = 0, radius do
pos1.y = pos.y + y
for z = -radius, radius do
if x*x+y*y+z*z <= max_radius then
pos1.z = pos.z + z
env:add_node(pos1, node)
count = count + 1
Expand Down
52 changes: 52 additions & 0 deletions worldedit_commands/init.lua
Expand Up @@ -279,6 +279,58 @@ minetest.register_chatcommand("/sphere", {
end,
})

minetest.register_chatcommand("/hollowdome", {
params = "<radius> <node>",
description = "Add hollow dome at WorldEdit position 1 with radius <radius>, composed of <node>",
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", false)
return
end

local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param, false)
return
end
if not worldedit.node_is_valid(nodename) then
minetest.chat_send_player(name, "Invalid node name: " .. param, false)
return
end

local count = worldedit.hollow_dome(pos, tonumber(radius), nodename)
minetest.chat_send_player(name, count .. " nodes added", false)
end,
})

minetest.register_chatcommand("/dome", {
params = "<radius> <node>",
description = "Add dome at WorldEdit position 1 with radius <radius>, composed of <node>",
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", false)
return
end

local found, _, radius, nodename = param:find("^(%d+)%s+([^%s]+)$")
if found == nil then
minetest.chat_send_player(name, "Invalid usage: " .. param, false)
return
end
if not worldedit.node_is_valid(nodename) then
minetest.chat_send_player(name, "Invalid node name: " .. param, false)
return
end

local count = worldedit.dome(pos, tonumber(radius), nodename)
minetest.chat_send_player(name, count .. " nodes added", false)
end,
})

minetest.register_chatcommand("/hollowcylinder", {
params = "x/y/z/? <length> <radius> <node>",
description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
Expand Down

0 comments on commit 71b6004

Please sign in to comment.