mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-25 18:20:38 +01:00
New commands //hollowdome and //dome, as well as new API functions worldedit.dome and worldedit.hollow_dome. Oh, and spheres generate faster too.
This commit is contained in:
parent
20722389bd
commit
71b6004b92
@ -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>.
|
||||
|
@ -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`.
|
||||
|
@ -1,10 +1,11 @@
|
||||
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
|
||||
@ -12,9 +13,9 @@ worldedit.hollow_sphere = function(pos, radius, nodename) --wip: use bresenham s
|
||||
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
|
||||
@ -24,10 +25,10 @@ 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
|
||||
@ -35,7 +36,54 @@ worldedit.sphere = function(pos, radius, nodename) --wip: use bresenham sphere f
|
||||
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
|
||||
|
@ -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>",
|
||||
|
Loading…
Reference in New Issue
Block a user