forked from mtcontrib/Minetest-WorldEdit
Rewrite spirals from scratch and fix upside-down pyramids. Use voxelmanip for markers to ensure area is emerged.
This commit is contained in:
parent
3c51ec8c4a
commit
b0bf52e9b6
|
@ -155,9 +155,9 @@ Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height
|
||||||
//pyramid 5 glass
|
//pyramid 5 glass
|
||||||
//pyramid 2 mesecons:wire_00000000_off
|
//pyramid 2 mesecons:wire_00000000_off
|
||||||
|
|
||||||
### //spiral <width> <height> <spacer> <node>
|
### //spiral <length> <height> <spacer> <node>
|
||||||
|
|
||||||
Add spiral centered at WorldEdit position 1 with width <width>, height <height>, space between walls <spacer>, composed of <node>.
|
Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <spacer>, composed of <node>.
|
||||||
|
|
||||||
//spiral 20 5 3 Diamond Block
|
//spiral 20 5 3 Diamond Block
|
||||||
//spiral 5 2 1 glass
|
//spiral 5 2 1 glass
|
||||||
|
|
|
@ -134,9 +134,9 @@ Adds a pyramid centered at `pos` along the `axis` axis ("x" or "y" or "z") with
|
||||||
|
|
||||||
Returns the number of nodes added.
|
Returns the number of nodes added.
|
||||||
|
|
||||||
### count = worldedit.spiral(pos, width, height, spacer, nodename)
|
### count = worldedit.spiral(pos, length, height, spacer, nodename)
|
||||||
|
|
||||||
Adds a spiral centered at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`.
|
Adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `nodename`.
|
||||||
|
|
||||||
Returns the number of nodes added.
|
Returns the number of nodes added.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
worldedit = worldedit or {}
|
worldedit = worldedit or {}
|
||||||
local minetest = minetest --local copy of global
|
local minetest = minetest --local copy of global
|
||||||
|
|
||||||
--wip: remove env parameter where no longer needed in chat commands module
|
|
||||||
--wip: fix the queue
|
--wip: fix the queue
|
||||||
|
|
||||||
--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
|
--modifies positions `pos1` and `pos2` so that each component of `pos1` is less than or equal to its corresponding conent of `pos2`, returning two new positions
|
||||||
|
@ -112,11 +111,68 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
worldedit.copy = function(pos1, pos2, axis, amount)
|
||||||
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
|
if amount == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local other1, other2
|
||||||
|
if axis == "x" then
|
||||||
|
other1, other2 = "y", "z"
|
||||||
|
elseif axis == "y" then
|
||||||
|
other1, other2 = "x", "z"
|
||||||
|
else --axis == "z"
|
||||||
|
other1, other2 = "x", "y"
|
||||||
|
end
|
||||||
|
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
--prepare slice along axis
|
||||||
|
local extent = {
|
||||||
|
[axis] = 1,
|
||||||
|
[other1]=pos2[other1] - pos1[other1] + 1,
|
||||||
|
[other2]=pos2[other2] - pos1[other2] + 1,
|
||||||
|
}
|
||||||
|
local nodes = {}
|
||||||
|
local schematic = {size=extent, data=nodes}
|
||||||
|
|
||||||
|
local currentpos = {x=pos1.x, y=pos1.y, z=pos1.z}
|
||||||
|
local stride = {x=1, y=extent.x, z=extent.x * extent.y}
|
||||||
|
local get_node = minetest.get_node
|
||||||
|
for index1 = 1, extent[axis] do --go through each slice
|
||||||
|
--copy slice into schematic
|
||||||
|
local newindex1 = (index1 + offset[axis]) * stride[axis] + 1 --offset contributed by axis plus 1 to make it 1-indexed
|
||||||
|
for index2 = 1, extent[other1] do
|
||||||
|
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
|
||||||
|
for index3 = 1, extent[other2] do
|
||||||
|
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||||
|
nodes[i] = get_node(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--copy schematic to target
|
||||||
|
currentpos[axis] = currentpos[axis] + amount
|
||||||
|
place_schematic(currentpos, schematic)
|
||||||
|
|
||||||
|
--wip: copy meta
|
||||||
|
|
||||||
|
currentpos[axis] = currentpos[axis] + 1
|
||||||
|
end
|
||||||
|
return worldedit.volume(pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
|
--copies the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") by `amount` nodes, returning the number of nodes copied
|
||||||
worldedit.copy = function(pos1, pos2, axis, amount)
|
worldedit.copy = function(pos1, pos2, axis, amount)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
--wip: copy slice by slice using schematic method in the copy axis and transfer metadata in separate loop (and if the amount is greater than the length in the axis, copy whole thing at a time), use voxelmanip to keep area loaded
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
|
||||||
if amount < 0 then
|
if amount < 0 then
|
||||||
local pos = {x=pos1.x, y=0, z=0}
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
@ -166,7 +222,11 @@ end
|
||||||
worldedit.move = function(pos1, pos2, axis, amount)
|
worldedit.move = function(pos1, pos2, axis, amount)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
--wip: move slice by slice using schematic method in the move axis and transfer metadata in separate loop (and if the amount is greater than the length in the axis, copy whole thing at a time and erase original after, using schematic method), use voxelmanip to keep area loaded
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
|
--wip: move slice by slice using schematic method in the move axis and transfer metadata in separate loop (and if the amount is greater than the length in the axis, copy whole thing at a time and erase original after, using schematic method)
|
||||||
local get_node, get_meta, add_node, remove_node = minetest.get_node, minetest.get_meta, minetest.add_node, minetest.remove_node
|
local get_node, get_meta, add_node, remove_node = minetest.get_node, minetest.get_meta, minetest.add_node, minetest.remove_node
|
||||||
if amount < 0 then
|
if amount < 0 then
|
||||||
local pos = {x=pos1.x, y=0, z=0}
|
local pos = {x=pos1.x, y=0, z=0}
|
||||||
|
@ -215,7 +275,7 @@ worldedit.move = function(pos1, pos2, axis, amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
--duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times, returning the number of nodes stacked
|
--duplicates the region defined by positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z") `count` times, returning the number of nodes stacked
|
||||||
worldedit.stack = function(pos1, pos2, axis, count, env)
|
worldedit.stack = function(pos1, pos2, axis, count)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
local length = pos2[axis] - pos1[axis] + 1
|
local length = pos2[axis] - pos1[axis] + 1
|
||||||
if count < 0 then
|
if count < 0 then
|
||||||
|
@ -226,7 +286,7 @@ worldedit.stack = function(pos1, pos2, axis, count, env)
|
||||||
local copy = worldedit.copy
|
local copy = worldedit.copy
|
||||||
for i = 1, count do
|
for i = 1, count do
|
||||||
amount = amount + length
|
amount = amount + length
|
||||||
copy(pos1, pos2, axis, amount, env)
|
copy(pos1, pos2, axis, amount)
|
||||||
end
|
end
|
||||||
return worldedit.volume(pos1, pos2) * count
|
return worldedit.volume(pos1, pos2) * count
|
||||||
end
|
end
|
||||||
|
@ -291,7 +351,7 @@ worldedit.scale = function(pos1, pos2, factor)
|
||||||
end
|
end
|
||||||
|
|
||||||
--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new transposed position 1, and the new transposed position 2
|
--transposes a region defined by the positions `pos1` and `pos2` between the `axis1` and `axis2` axes, returning the number of nodes transposed, the new transposed position 1, and the new transposed position 2
|
||||||
worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
|
worldedit.transpose = function(pos1, pos2, axis1, axis2)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
local compare
|
local compare
|
||||||
|
@ -350,7 +410,7 @@ worldedit.transpose = function(pos1, pos2, axis1, axis2, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
--flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped
|
--flips a region defined by the positions `pos1` and `pos2` along the `axis` axis ("x" or "y" or "z"), returning the number of nodes flipped
|
||||||
worldedit.flip = function(pos1, pos2, axis, env)
|
worldedit.flip = function(pos1, pos2, axis)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
--make area stay loaded
|
--make area stay loaded
|
||||||
|
@ -388,7 +448,7 @@ worldedit.flip = function(pos1, pos2, axis, env)
|
||||||
end
|
end
|
||||||
|
|
||||||
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around axis `axis` (90 degree increment), returning the number of nodes rotated
|
--rotates a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise around axis `axis` (90 degree increment), returning the number of nodes rotated
|
||||||
worldedit.rotate = function(pos1, pos2, axis, angle, env)
|
worldedit.rotate = function(pos1, pos2, axis, angle)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
local axis1, axis2
|
local axis1, axis2
|
||||||
|
@ -403,20 +463,20 @@ worldedit.rotate = function(pos1, pos2, axis, angle, env)
|
||||||
|
|
||||||
local count
|
local count
|
||||||
if angle == 90 then
|
if angle == 90 then
|
||||||
worldedit.flip(pos1, pos2, axis1, env)
|
worldedit.flip(pos1, pos2, axis1)
|
||||||
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
|
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
|
||||||
elseif angle == 180 then
|
elseif angle == 180 then
|
||||||
worldedit.flip(pos1, pos2, axis1, env)
|
worldedit.flip(pos1, pos2, axis1)
|
||||||
count = worldedit.flip(pos1, pos2, axis2, env)
|
count = worldedit.flip(pos1, pos2, axis2)
|
||||||
elseif angle == 270 then
|
elseif angle == 270 then
|
||||||
worldedit.flip(pos1, pos2, axis2, env)
|
worldedit.flip(pos1, pos2, axis2)
|
||||||
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, env)
|
count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
|
||||||
end
|
end
|
||||||
return count, pos1, pos2
|
return count, pos1, pos2
|
||||||
end
|
end
|
||||||
|
|
||||||
--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented
|
--rotates all oriented nodes in a region defined by the positions `pos1` and `pos2` by `angle` degrees clockwise (90 degree increment) around the Y axis, returning the number of nodes oriented
|
||||||
worldedit.orient = function(pos1, pos2, angle, env) --wip: support 6D facedir rotation along arbitrary axis
|
worldedit.orient = function(pos1, pos2, angle) --wip: support 6D facedir rotation along arbitrary axis
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
local registered_nodes = minetest.registered_nodes
|
local registered_nodes = minetest.registered_nodes
|
||||||
|
|
||||||
|
@ -477,7 +537,7 @@ worldedit.orient = function(pos1, pos2, angle, env) --wip: support 6D facedir ro
|
||||||
end
|
end
|
||||||
|
|
||||||
--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
|
--fixes the lighting in a region defined by positions `pos1` and `pos2`, returning the number of nodes updated
|
||||||
worldedit.fixlight = function(pos1, pos2, env)
|
worldedit.fixlight = function(pos1, pos2)
|
||||||
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
||||||
|
|
||||||
--make area stay loaded
|
--make area stay loaded
|
||||||
|
|
|
@ -326,7 +326,7 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
|
||||||
local newindex3 = newindex2 + (index3 + offset[other2]) * stride[other2]
|
local newindex3 = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||||
if index2 * index2 + index3 * index3 <= max_radius then
|
if index2 * index2 + index3 * index3 <= max_radius then
|
||||||
for index1 = min_slice, max_slice do --add column along axis
|
for index1 = min_slice, max_slice do --add column along axis
|
||||||
local i = newindex3 + index1 * stride[axis] + 1
|
local i = newindex3 + index1 * stride[axis]
|
||||||
nodes[i] = node_id
|
nodes[i] = node_id
|
||||||
end
|
end
|
||||||
count = count + length
|
count = count + length
|
||||||
|
@ -358,18 +358,14 @@ worldedit.pyramid = function(pos, axis, height, nodename)
|
||||||
|
|
||||||
--handle inverted pyramids
|
--handle inverted pyramids
|
||||||
local startaxis, endaxis, step
|
local startaxis, endaxis, step
|
||||||
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
|
|
||||||
if height > 0 then
|
if height > 0 then
|
||||||
height = height - 1
|
height = height - 1
|
||||||
startaxis, endaxis = 0, height
|
|
||||||
step = 1
|
step = 1
|
||||||
pos1[axis] = pos[axis] --upper half of box
|
pos1[axis] = pos[axis] --upper half of box
|
||||||
else
|
else
|
||||||
height = -height - 1
|
height = height + 1
|
||||||
startaxis, endaxis = height, 0
|
|
||||||
step = -1
|
step = -1
|
||||||
pos2[axis] = pos[axis] + 1 --lower half of box
|
pos2[axis] = pos[axis] --lower half of box
|
||||||
currentpos[axis] = pos[axis] - height --bottom of box
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--set up voxel manipulator
|
--set up voxel manipulator
|
||||||
|
@ -387,19 +383,20 @@ worldedit.pyramid = function(pos, axis, height, nodename)
|
||||||
--fill selected area with node
|
--fill selected area with node
|
||||||
local node_id = minetest.get_content_id(nodename)
|
local node_id = minetest.get_content_id(nodename)
|
||||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||||
local offset = {x=currentpos.x - emerged_pos1.x, y=currentpos.y - emerged_pos1.y, z=currentpos.z - emerged_pos1.z}
|
local offset = {x=pos.x - emerged_pos1.x, y=pos.y - emerged_pos1.y, z=pos.z - emerged_pos1.z}
|
||||||
|
local size = height * step
|
||||||
local count = 0
|
local count = 0
|
||||||
for index1 = startaxis, endaxis, step do --go through each level of the pyramid
|
for index1 = 0, height, step do --go through each level of the pyramid
|
||||||
local newindex1 = (index1 + offset[axis]) * stride[axis] + 1 --offset contributed by axis plus 1 to make it 1-indexed
|
local newindex1 = (index1 + offset[axis]) * stride[axis] + 1 --offset contributed by axis plus 1 to make it 1-indexed
|
||||||
for index2 = -height, height do
|
for index2 = -size, size do
|
||||||
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
|
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
|
||||||
for index3 = -height, height do
|
for index3 = -size, size do
|
||||||
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
|
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
|
||||||
nodes[i] = node_id
|
nodes[i] = node_id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
count = count + (height * 2 + 1) ^ 2
|
count = count + (size * 2 + 1) ^ 2
|
||||||
height = height - 1
|
size = size - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--update map nodes
|
--update map nodes
|
||||||
|
@ -410,70 +407,72 @@ worldedit.pyramid = function(pos, axis, height, nodename)
|
||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
--adds a spiral centered at `pos` with width `width`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
|
--adds a spiral centered at `pos` with side length `length`, height `height`, space between walls `spacer`, composed of `nodename`, returning the number of nodes added
|
||||||
worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: rewrite this whole thing, nobody can understand it anyways
|
worldedit.spiral = function(pos, length, height, spacer, nodename)
|
||||||
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
|
local extent = math.ceil(length / 2)
|
||||||
local abs = math.abs
|
local pos1 = {x=pos.x - extent, y=pos.y, z=pos.z - extent}
|
||||||
local sign = function(s) return s ~= 0 and s / av(s) or 0 end
|
local pos2 = {x=pos.x + extent, y=pos.y + height, z=pos.z + extent}
|
||||||
local function sindex(z, x) -- returns the value at (x, z) in a spiral that starts at 1 and goes outwards
|
|
||||||
if z == -x and z >= x then return (2*z+1)^2 end
|
--set up voxel manipulator
|
||||||
local longest = math.max(abs(z), abs(x))
|
local manip = minetest.get_voxel_manip()
|
||||||
return (2*longest-1)^2 + 4*longest + 2*longest*sign(x+z) + sign(z^2-x^2)*(longest-(abs(z)==longest and sign(z)*x or sign(x)*z)) -- OH GOD WHAT
|
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
|
||||||
|
local area = VoxelArea:new({MinEdge=emerged_pos1, MaxEdge=emerged_pos2})
|
||||||
|
|
||||||
|
--fill emerged area with ignore
|
||||||
|
local nodes = {}
|
||||||
|
local ignore = minetest.get_content_id("ignore")
|
||||||
|
for i = 1, worldedit.volume(emerged_pos1, emerged_pos2) do
|
||||||
|
nodes[i] = ignore
|
||||||
end
|
end
|
||||||
local function spiralt(side)
|
|
||||||
local ret, id, start, stop = {}, 0, math.floor((-side+1)/2), math.floor((side-1)/2)
|
--
|
||||||
for i = 1, side do
|
local node_id = minetest.get_content_id(nodename)
|
||||||
for j = 1, side do
|
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||||
local id = side^2 - sindex(stop - i + 1,start + j - 1)
|
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
|
||||||
ret[id] = {x=i,z=j}
|
local i = offsetz * stride.z + offsety * stride.y + offsetx + 1
|
||||||
|
|
||||||
|
--add first column
|
||||||
|
local column = i
|
||||||
|
for y = 1, height do
|
||||||
|
nodes[column] = node_id
|
||||||
|
column = column + stride.y
|
||||||
|
end
|
||||||
|
|
||||||
|
--add spiral segments
|
||||||
|
local axis, other = "x", "z"
|
||||||
|
local sign = 1
|
||||||
|
local count = height
|
||||||
|
for segment = 1, length / spacer - 1 do --go through each segment except the last
|
||||||
|
for index = 1, segment * spacer do --fill segment
|
||||||
|
i = i + stride[axis] * sign
|
||||||
|
local column = i
|
||||||
|
for y = 1, height do --add column
|
||||||
|
nodes[column] = node_id
|
||||||
|
column = column + stride.y
|
||||||
|
end
|
||||||
|
count = count + height
|
||||||
|
end
|
||||||
|
axis, other = other, axis --swap axes
|
||||||
|
if segment % 2 == 1 then --change sign every other turn
|
||||||
|
sign = -sign
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ret
|
|
||||||
end
|
--add shorter final segment
|
||||||
if env == nil then env = minetest.env end
|
for index = 1, (math.floor(length / spacer) - 2) * spacer do
|
||||||
-- connect the joined parts
|
i = i + stride[axis] * sign
|
||||||
local spiral = spiralt(width)
|
local column = i
|
||||||
height = tonumber(height)
|
for y = 1, height do --add column
|
||||||
if height < 1 then height = 1 end
|
nodes[column] = node_id
|
||||||
spacer = tonumber(spacer)-1
|
column = column + stride.y
|
||||||
if spacer < 1 then spacer = 1 end
|
|
||||||
local count = 0
|
|
||||||
local node = {name=nodename}
|
|
||||||
local np,lp
|
|
||||||
for y=0,height do
|
|
||||||
lp = nil
|
|
||||||
for _,v in ipairs(spiral) do
|
|
||||||
np = {x=pos.x+v.x*spacer, y=pos.y+y, z=pos.z+v.z*spacer}
|
|
||||||
if lp~=nil then
|
|
||||||
if lp.x~=np.x then
|
|
||||||
if lp.x<np.x then
|
|
||||||
for i=lp.x+1,np.x do
|
|
||||||
env:add_node({x=i, y=np.y, z=np.z}, node)
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i=np.x,lp.x-1 do
|
|
||||||
env:add_node({x=i, y=np.y, z=np.z}, node)
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if lp.z~=np.z then
|
|
||||||
if lp.z<np.z then
|
|
||||||
for i=lp.z+1,np.z do
|
|
||||||
env:add_node({x=np.x, y=np.y, z=i}, node)
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i=np.z,lp.z-1 do
|
|
||||||
env:add_node({x=np.x, y=np.y, z=i}, node)
|
|
||||||
count = count + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
lp = np
|
|
||||||
end
|
end
|
||||||
|
count = count + height
|
||||||
end
|
end
|
||||||
|
print(minetest.serialize(nodes))
|
||||||
|
--update map nodes
|
||||||
|
manip:set_data(nodes)
|
||||||
|
manip:write_to_map()
|
||||||
|
manip:update_map()
|
||||||
|
|
||||||
return count
|
return count
|
||||||
end
|
end
|
|
@ -183,7 +183,7 @@ end
|
||||||
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
|
--loads the nodes represented by string `value` at position `originpos`, returning the number of nodes deserialized
|
||||||
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
|
--contains code based on [table.save/table.load](http://lua-users.org/wiki/SaveTableToFile) by ChillCode, available under the MIT license (GPL compatible)
|
||||||
worldedit.deserialize = function(originpos, value)
|
worldedit.deserialize = function(originpos, value)
|
||||||
--make sure the area stays loaded --wip: not very performant
|
--make area stay loaded --wip: not very performant
|
||||||
local pos1, pos2 = worldedit.allocate(originpos, value)
|
local pos1, pos2 = worldedit.allocate(originpos, value)
|
||||||
local manip = minetest.get_voxel_manip()
|
local manip = minetest.get_voxel_manip()
|
||||||
manip:read_from_map(pos1, pos2)
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
|
@ -536,8 +536,8 @@ minetest.register_chatcommand("/pyramid", {
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("/spiral", {
|
minetest.register_chatcommand("/spiral", {
|
||||||
params = "<width> <height> <space> <node>",
|
params = "<length> <height> <space> <node>",
|
||||||
description = "Add spiral centered at WorldEdit position 1 with width <width>, height <height>, space between walls <space>, composed of <node>",
|
description = "Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node>",
|
||||||
privs = {worldedit=true},
|
privs = {worldedit=true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
local pos = worldedit.pos1[name]
|
local pos = worldedit.pos1[name]
|
||||||
|
@ -546,7 +546,7 @@ minetest.register_chatcommand("/spiral", {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local found, _, width, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
local found, _, length, height, space, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
||||||
if found == nil then
|
if found == nil then
|
||||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||||
return
|
return
|
||||||
|
@ -557,7 +557,7 @@ minetest.register_chatcommand("/spiral", {
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), node)
|
local count = worldedit.spiral(pos, tonumber(length), tonumber(height), tonumber(space), node)
|
||||||
worldedit.player_notify(name, count .. " nodes added")
|
worldedit.player_notify(name, count .. " nodes added")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
|
@ -21,16 +21,21 @@ minetest.register_entity(":worldedit:region_cube", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
--wip: use voxelmanip to put the entity in the correct spot
|
|
||||||
|
|
||||||
--marks worldedit region position 1
|
--marks worldedit region position 1
|
||||||
worldedit.mark_pos1 = function(name)
|
worldedit.mark_pos1 = function(name)
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
|
|
||||||
|
if pos1 ~= nil then
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos1) --wip: see if this even works
|
||||||
|
end
|
||||||
if worldedit.marker1[name] ~= nil then --marker already exists
|
if worldedit.marker1[name] ~= nil then --marker already exists
|
||||||
worldedit.marker1[name]:remove() --remove marker
|
worldedit.marker1[name]:remove() --remove marker
|
||||||
worldedit.marker1[name] = nil
|
worldedit.marker1[name] = nil
|
||||||
end
|
end
|
||||||
if pos1 ~= nil then --add marker
|
if pos1 ~= nil then
|
||||||
|
--add marker
|
||||||
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
|
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
|
||||||
worldedit.marker1[name]:get_luaentity().active = true
|
worldedit.marker1[name]:get_luaentity().active = true
|
||||||
if pos2 ~= nil then --region defined
|
if pos2 ~= nil then --region defined
|
||||||
|
@ -42,11 +47,18 @@ end
|
||||||
--marks worldedit region position 2
|
--marks worldedit region position 2
|
||||||
worldedit.mark_pos2 = function(name)
|
worldedit.mark_pos2 = function(name)
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
|
|
||||||
|
if pos2 ~= nil then
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos2, pos2) --wip: see if this even works
|
||||||
|
end
|
||||||
if worldedit.marker2[name] ~= nil then --marker already exists
|
if worldedit.marker2[name] ~= nil then --marker already exists
|
||||||
worldedit.marker2[name]:remove() --remove marker
|
worldedit.marker2[name]:remove() --remove marker
|
||||||
worldedit.marker2[name] = nil
|
worldedit.marker2[name] = nil
|
||||||
end
|
end
|
||||||
if pos2 ~= nil then --add marker
|
if pos2 ~= nil then
|
||||||
|
--add marker
|
||||||
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
|
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
|
||||||
worldedit.marker2[name]:get_luaentity().active = true
|
worldedit.marker2[name]:get_luaentity().active = true
|
||||||
if pos1 ~= nil then --region defined
|
if pos1 ~= nil then --region defined
|
||||||
|
@ -56,10 +68,16 @@ worldedit.mark_pos2 = function(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
worldedit.mark_region = function(pos1, pos2)
|
worldedit.mark_region = function(pos1, pos2)
|
||||||
|
--make area stay loaded
|
||||||
|
local manip = minetest.get_voxel_manip()
|
||||||
|
manip:read_from_map(pos1, pos2)
|
||||||
|
|
||||||
if worldedit.marker[name] ~= nil then --marker already exists
|
if worldedit.marker[name] ~= nil then --marker already exists
|
||||||
--wip: remove markers
|
--wip: remove markers
|
||||||
end
|
end
|
||||||
|
if pos1 ~= nil and pos2 ~= nil then
|
||||||
|
--wip: place markers
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_entity(":worldedit:pos1", {
|
minetest.register_entity(":worldedit:pos1", {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user