//pyramid works along any axis and backwards. Working //clearobjects and //cylinder command, begin implementing super marker. Remove EnvRef usages and the block queue (the block queue does not work with VoxelManips). More block emergers.

This commit is contained in:
Anthony Zhang 2013-07-31 00:02:37 -04:00
parent 49b683f27f
commit 3c51ec8c4a
8 changed files with 172 additions and 304 deletions

View File

@ -301,7 +301,7 @@ Executes <code> as a Lua chunk in the global namespace.
Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region.
//luatransform minetest.add_node(pos, {name="default:stone"})
//luatransform if minetest.get_node(pos).name == "air" then minetest.env:add_node(pos, {name="default:water_source"})
//luatransform if minetest.get_node(pos).name == "air" then minetest.add_node(pos, {name="default:water_source"})
### //mtschemcreate <file>

View File

@ -18,4 +18,3 @@ loadmodule(path .. "/visualization.lua")
loadmodule(path .. "/serialization.lua")
loadmodule(path .. "/code.lua")
loadmodule(path .. "/compatibility.lua")
loadmodule(path .. "/queue.lua")

View File

@ -113,11 +113,11 @@ worldedit.replaceinverse = function(pos1, pos2, searchnode, replacenode)
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
worldedit.copy = function(pos1, pos2, axis, amount, env)
worldedit.copy = function(pos1, pos2, axis, amount)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
if env == nil then env = minetest.env end
--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
local get_node, get_meta, add_node = minetest.get_node, minetest.get_meta, minetest.add_node
if amount < 0 then
local pos = {x=pos1.x, y=0, z=0}
while pos.x <= pos2.x do
@ -125,12 +125,12 @@ worldedit.copy = function(pos1, pos2, axis, amount, env)
while pos.y <= pos2.y do
pos.z = pos1.z
while pos.z <= pos2.z do
local node = env:get_node(pos) --obtain current node
local meta = env:get_meta(pos):to_table() --get meta of current node
local node = get_node(pos) --obtain current node
local meta = get_meta(pos):to_table() --get meta of current node
local value = pos[axis] --store current position
pos[axis] = value + amount --move along axis
env:add_node(pos, node) --copy node to new position
env:get_meta(pos):from_table(meta) --set metadata of new node
add_node(pos, node) --copy node to new position
get_meta(pos):from_table(meta) --set metadata of new node
pos[axis] = value --restore old position
pos.z = pos.z + 1
end
@ -145,12 +145,12 @@ worldedit.copy = function(pos1, pos2, axis, amount, env)
while pos.y >= pos1.y do
pos.z = pos2.z
while pos.z >= pos1.z do
local node = minetest.env:get_node(pos) --obtain current node
local meta = env:get_meta(pos):to_table() --get meta of current node
local node = get_node(pos) --obtain current node
local meta = get_meta(pos):to_table() --get meta of current node
local value = pos[axis] --store current position
pos[axis] = value + amount --move along axis
minetest.env:add_node(pos, node) --copy node to new position
env:get_meta(pos):from_table(meta) --set metadata of new node
add_node(pos, node) --copy node to new position
get_meta(pos):from_table(meta) --set metadata of new node
pos[axis] = value --restore old position
pos.z = pos.z - 1
end
@ -163,11 +163,11 @@ worldedit.copy = function(pos1, pos2, axis, amount, env)
end
--moves 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 moved
worldedit.move = function(pos1, pos2, axis, amount, env)
worldedit.move = function(pos1, pos2, axis, amount)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
if env == nil then env = minetest.env end
--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
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
local pos = {x=pos1.x, y=0, z=0}
while pos.x <= pos2.x do
@ -175,13 +175,13 @@ worldedit.move = function(pos1, pos2, axis, amount, env)
while pos.y <= pos2.y do
pos.z = pos1.z
while pos.z <= pos2.z do
local node = env:get_node(pos) --obtain current node
local meta = env:get_meta(pos):to_table() --get metadata of current node
env:remove_node(pos)
local node = get_node(pos) --obtain current node
local meta = get_meta(pos):to_table() --get metadata of current node
remove_node(pos)
local value = pos[axis] --store current position
pos[axis] = value + amount --move along axis
env:add_node(pos, node) --move node to new position
env:get_meta(pos):from_table(meta) --set metadata of new node
add_node(pos, node) --move node to new position
get_meta(pos):from_table(meta) --set metadata of new node
pos[axis] = value --restore old position
pos.z = pos.z + 1
end
@ -196,13 +196,13 @@ worldedit.move = function(pos1, pos2, axis, amount, env)
while pos.y >= pos1.y do
pos.z = pos2.z
while pos.z >= pos1.z do
local node = env:get_node(pos) --obtain current node
local meta = env:get_meta(pos):to_table() --get metadata of current node
env:remove_node(pos)
local node = get_node(pos) --obtain current node
local meta = get_meta(pos):to_table() --get metadata of current node
remove_node(pos)
local value = pos[axis] --store current position
pos[axis] = value + amount --move along axis
env:add_node(pos, node) --move node to new position
env:get_meta(pos):from_table(meta) --set metadata of new node
add_node(pos, node) --move node to new position
get_meta(pos):from_table(meta) --set metadata of new node
pos[axis] = value --restore old position
pos.z = pos.z - 1
end
@ -249,7 +249,7 @@ worldedit.scale = function(pos1, pos2, factor)
--make area stay loaded
local manip = minetest.get_voxel_manip()
local new_pos2 = {x=pos1.x + (pos2.x - pos1.x) * factor + size, y=pos1.y + (pos2.y - pos1.y) * factor + size, z=pos1.z + (pos2.z - pos1.z) * factor + size}
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, new_pos2)
manip:read_from_map(pos1, new_pos2)
local pos = {x=pos2.x, y=0, z=0}
local bigpos = {x=0, y=0, z=0}
@ -496,22 +496,25 @@ end
worldedit.clearobjects = function(pos1, pos2)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
--set up voxel manipulator
--make area stay loaded
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)
local pos1x, pos1y, pos1z = pos1.x, pos1.y, pos1.z
local pos2x, pos2y, pos2z = pos2.x, pos2.y, pos2.z
local center = {x=(pos1x + pos2x + 1) / 2, y=(pos1y + pos2y + 1) / 2, z=(pos1z + pos2z + 1) / 2}
local radius = ((center.x - pos1x + 0.5) + (center.y - pos1y + 0.5) + (center.z - pos1z + 0.5)) ^ 0.5
local pos2x, pos2y, pos2z = pos2.x + 1, pos2.y + 1, pos2.z + 1
local center = {x=(pos1x + pos2x) / 2, y=(pos1y + pos2y) / 2, z=(pos1z + pos2z) / 2} --center of region
local radius = ((center.x - pos1x + 0.5) + (center.y - pos1y + 0.5) + (center.z - pos1z + 0.5)) ^ 0.5 --bounding sphere radius
local count = 0
for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do
local pos = obj:getpos()
if pos.x >= pos1x and pos.x <= pos2x
and pos.y >= pos1y and pos.y <= pos2y
and pos.z >= pos1z and pos.z <= pos2z then
obj:remove()
count = count + 1
for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do --all objects in bounding sphere
local entity = obj:get_luaentity()
if not (entity and entity.name:find("^worldedit:")) then --avoid WorldEdit entities
local pos = obj:getpos()
if pos.x >= pos1x and pos.x <= pos2x
and pos.y >= pos1y and pos.y <= pos2y
and pos.z >= pos1z and pos.z <= pos2z then --inside region
obj:remove()
count = count + 1
end
end
end
return count

View File

@ -209,6 +209,20 @@ worldedit.hollow_cylinder = function(pos, axis, length, radius, nodename) --wip:
currentpos[axis] = currentpos[axis] - length
end
--make area stay loaded
local manip = minetest.get_voxel_manip()
local pos1 = {
[axis]=currentpos[axis],
[other1]=currentpos[other1] - radius,
[other2]=currentpos[other2] - radius
}
local pos2 = {
[axis]=currentpos[axis] + length - 1,
[other1]=currentpos[other1] + radius,
[other2]=currentpos[other2] + radius
}
manip:read_from_map(pos1, pos2)
--create schematic for single node column along the axis
local node = {name=nodename, param1=0, param2=0}
local nodes = {}
@ -306,13 +320,13 @@ worldedit.cylinder = function(pos, axis, length, radius, nodename)
local offset = {x=currentpos.x - emerged_pos1.x, y=currentpos.y - emerged_pos1.y, z=currentpos.z - emerged_pos1.z}
local min_slice, max_slice = offset[axis], offset[axis] + length - 1
local count = 0
for axis1 = -radius, radius do
local newaxis1 = (axis1 + offset[other1]) * stride[other1] + 1 --offset contributed by other axis 1 plus 1 to make it 1-indexed
for axis2 = -radius, radius do
local newaxis2 = newaxis1 + (axis2 + offset[other2]) * stride[other2]
if axis1 * axis1 + axis2 * axis2 <= max_radius then
for slice = min_slice, max_slice do
local i = newaxis2 + slice * stride[axis] + 1
for index2 = -radius, radius do
local newindex2 = (index2 + offset[other1]) * stride[other1] + 1 --offset contributed by other axis 1 plus 1 to make it 1-indexed
for index3 = -radius, radius do
local newindex3 = newindex2 + (index3 + offset[other2]) * stride[other2]
if index2 * index2 + index3 * index3 <= max_radius then
for index1 = min_slice, max_slice do --add column along axis
local i = newindex3 + index1 * stride[axis] + 1
nodes[i] = node_id
end
count = count + length
@ -330,9 +344,34 @@ end
--adds a pyramid centered at `pos` with height `height`, composed of `nodename`, returning the number of nodes added
worldedit.pyramid = function(pos, axis, height, nodename)
local pos1 = {x=pos.x - height, y=pos.y, z=pos.z - height}
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
local pos1 = {x=pos.x - height, y=pos.y - height, z=pos.z - height}
local pos2 = {x=pos.x + height, y=pos.y + height, z=pos.z + height}
--handle inverted pyramids
local startaxis, endaxis, step
local currentpos = {x=pos.x, y=pos.y, z=pos.z}
if height > 0 then
height = height - 1
startaxis, endaxis = 0, height
step = 1
pos1[axis] = pos[axis] --upper half of box
else
height = -height - 1
startaxis, endaxis = height, 0
step = -1
pos2[axis] = pos[axis] + 1 --lower half of box
currentpos[axis] = pos[axis] - height --bottom of box
end
--set up voxel manipulator
local manip = minetest.get_voxel_manip()
local emerged_pos1, emerged_pos2 = manip:read_from_map(pos1, pos2)
@ -345,31 +384,22 @@ worldedit.pyramid = function(pos, axis, height, nodename)
nodes[i] = ignore
end
--handle inverted pyramids
height = height - 1
local size = height
local step = -1
if height < 0 then
size = 0
step = 1
end
--wip: support arbitrary axes
--fill selected area with node
local node_id = minetest.get_content_id(nodename)
local offsetx, offsety, offsetz = pos.x - emerged_pos1.x, pos.y - emerged_pos1.y, pos.z - emerged_pos1.z
local zstride, ystride = area.zstride, area.ystride
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 count = 0
for y = 0, height do --go through each level of the pyramid
local newy = (y + offsety) * ystride + 1 --offset contributed by y plus 1 to make it 1-indexed
for z = -size, size do
local newz = newy + (z + offsetz) * zstride
for x = -size, size do
local i = newz + (x + offsetx)
for index1 = startaxis, endaxis, 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
for index2 = -height, height do
local newindex2 = newindex1 + (index2 + offset[other1]) * stride[other1]
for index3 = -height, height do
local i = newindex2 + (index3 + offset[other2]) * stride[other2]
nodes[i] = node_id
end
end
size = size + step
count = count + ((height - y) * 2 + 1) ^ 2
count = count + (height * 2 + 1) ^ 2
height = height - 1
end
--update map nodes
@ -383,11 +413,12 @@ 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
worldedit.spiral = function(pos, width, height, spacer, nodename, env) --wip: rewrite this whole thing, nobody can understand it anyways
-- spiral matrix - http://rosettacode.org/wiki/Spiral_matrix#Lua
av, sn = math.abs, function(s) return s~=0 and s/av(s) or 0 end
local abs = math.abs
local sign = function(s) return s ~= 0 and s / av(s) or 0 end
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
local l = math.max(av(z), av(x))
return (2*l-1)^2+4*l+2*l*sn(x+z)+sn(z^2-x^2)*(l-(av(z)==l and sn(z)*x or sn(x)*z)) -- OH GOD WHAT
local longest = math.max(abs(z), abs(x))
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
end
local function spiralt(side)
local ret, id, start, stop = {}, 0, math.floor((-side+1)/2), math.floor((side-1)/2)

View File

@ -1,123 +0,0 @@
worldedit = worldedit or {}
local minetest = minetest --local copy of global
worldedit.queue = {}
worldedit.lower = 1
worldedit.higher = 0
worldedit.ENABLE_QUEUE = true --enable the WorldEdit block queue
worldedit.MAXIMUM_TIME = 0.08 --maximum time each step alloted for WorldEdit operations
minetest.register_globalstep(function(dtime)
local elapsed = 0
local env = minetest.env
while worldedit.lower <= worldedit.higher and elapsed <= worldedit.MAXIMUM_TIME do
local entry = worldedit.queue[worldedit.lower]
if entry.t == "set_node" then
env:set_node(entry.pos, entry.node)
elapsed = elapsed + 0.0002
elseif entry.t == "remove_node" then
env:remove_node(entry.pos)
elapsed = elapsed + 0.0002
elseif entry.t == "place_node" then
env:place_node(entry.pos, entry.node)
elapsed = elapsed + 0.001
elseif entry.t == "dig_node" then
env:dig_node(entry.pos)
elapsed = elapsed + 0.001
elseif entry.t == "add_entity" then
env:add_entity(entry.pos, entry.name)
elapsed = elapsed + 0.005
elseif entry.t == "add_item" then
env:add_item(entry.pos, entry.item)
elapsed = elapsed + 0.005
elseif entry.t == "meta_from_table" then
env:get_meta(entry.pos):from_table(entry.table)
elapsed = elapsed + 0.0002
else
print("Unknown queue event type: " .. entry.t)
end
worldedit.queue[worldedit.lower] = nil
worldedit.lower = worldedit.lower + 1
end
end)
worldedit.enqueue = function(value)
worldedit.higher = worldedit.higher + 1
worldedit.queue[worldedit.higher] = value
end
function table.copy(t, seen)
seen = seen or {}
if t == nil then return nil end
if seen[t] then return seen[t] end
local nt = {}
for k, v in pairs(t) do
if type(v) == 'table' then
nt[k] = table.copy(v, seen)
else
nt[k] = v
end
end
seen[t] = nt
return nt
end
local queue_setnode = function(self, pos_, node_)
worldedit.enqueue({pos=table.copy(pos_), node=table.copy(node_), t="set_node"})
end
local queue_removenode = function(self, pos_)
worldedit.enqueue({pos=table.copy(pos_), t="remove_node"})
end
local queue_placenode = function(self, pos_, node_)
worldedit.enqueue({pos=table.copy(pos_), node=table.copy(node_), t="place_node"})
end
local queue_dignode = function(self, pos_)
worldedit.enqueue({pos=table.copy(pos_), t="dig_node"})
end
local queue_addentity = function(self, pos_, name_)
worldedit.enqueue({pos=table.copy(pos_), name=name_.."", t="add_entity"})
end
local queue_additem = function(self, pos_, item_)
worldedit.enqueue({pos=table.copy(pos_), item=item_.."", t="add_item"})
end
local queue_setmeta = function(self, pos_, table_)
worldedit.enqueue({pos=table.copy(pos_), table=table.copy(table_), t="meta_from_table"})
end
local aliasmeta = {
-- the other functions are left out because they are not used in worldedit
to_table = function(self) return minetest.env:get_meta(self._pos):to_table() end,
set_string = function(self, name_, value_) minetest.env:get_meta(self._pos):set_string(name_, value_) end,
from_table = function(self, tbl) queue_setmeta(nil, self._pos, tbl) end,
}
local get_meta_alias = function(self, pos)
local am = table.copy(aliasmeta)
am._pos = pos
return am
end
worldedit.queue_aliasenv = {
-- ALL functions that are not just piped to the real minetest.env function must copy the arguments, not just reference them
set_node = queue_setnode,
add_node = queue_setnode,
remove_node = queue_removenode,
get_node = function(self, pos) return minetest.env:get_node(pos) end,
get_node_or_nil = function(self, pos) return minetest.env:get_node_or_nil(pos) end,
get_node_light = function(self, pos, timeofday) return minetest.env:get_node_light(pos, timeofday) end,
place_node = queue_placenode,
dig_node = queue_dignode,
punch_node = function(self, pos) return minetest.env:punch_node(pos) end,
get_meta = get_meta_alias,
get_node_timer = function(self, pos) return minetest.env:get_node_timer(pos) end,
add_entity = queue_addentity,
add_item = queue_additem,
}

View File

@ -182,7 +182,12 @@ end
--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)
worldedit.deserialize = function(originpos, value) --wip: use voxelmanip to make sure the blocks are loaded
worldedit.deserialize = function(originpos, value)
--make sure the area stays loaded --wip: not very performant
local pos1, pos2 = worldedit.allocate(originpos, value)
local manip = minetest.get_voxel_manip()
manip:read_from_map(pos1, pos2)
local originx, originy, originz = originpos.x, originpos.y, originpos.z
local count = 0
local add_node, get_meta = minetest.add_node, minetest.get_meta

View File

@ -38,7 +38,7 @@ end
--determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
worldedit.player_axis = function(name)
local dir = minetest.env:get_player_by_name(name):get_look_dir()
local dir = minetest.get_player_by_name(name):get_look_dir()
local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z)
if x > y then
if x > z then
@ -125,7 +125,7 @@ minetest.register_chatcommand("/pos1", {
description = "Set WorldEdit region position 1 to the player's location",
privs = {worldedit=true},
func = function(name, param)
local pos = minetest.env:get_player_by_name(name):getpos()
local pos = minetest.get_player_by_name(name):getpos()
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
worldedit.pos1[name] = pos
worldedit.mark_pos1(name)
@ -138,7 +138,7 @@ minetest.register_chatcommand("/pos2", {
description = "Set WorldEdit region position 2 to the player's location",
privs = {worldedit=true},
func = function(name, param)
local pos = minetest.env:get_player_by_name(name):getpos()
local pos = minetest.get_player_by_name(name):getpos()
pos.x, pos.y, pos.z = math.floor(pos.x + 0.5), math.floor(pos.y + 0.5), math.floor(pos.z + 0.5)
worldedit.pos2[name] = pos
worldedit.mark_pos2(name)
@ -294,11 +294,7 @@ minetest.register_chatcommand("/replace", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode, tenv)
local count = worldedit.replace(pos1, pos2, newsearchnode, newreplacenode)
worldedit.player_notify(name, count .. " nodes replaced")
end,
})
@ -330,11 +326,7 @@ minetest.register_chatcommand("/replaceinverse", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode, tenv)
local count = worldedit.replaceinverse(pos1, pos2, searchnode, replacenode)
worldedit.player_notify(name, count .. " nodes replaced")
end,
})
@ -361,11 +353,7 @@ minetest.register_chatcommand("/hollowsphere", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hollow_sphere(pos, tonumber(radius), node, tenv)
local count = worldedit.hollow_sphere(pos, tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -392,11 +380,7 @@ minetest.register_chatcommand("/sphere", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.sphere(pos, tonumber(radius), node, tenv)
local count = worldedit.sphere(pos, tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -423,11 +407,7 @@ minetest.register_chatcommand("/hollowdome", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hollow_dome(pos, tonumber(radius), node, tenv)
local count = worldedit.hollow_dome(pos, tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -454,11 +434,7 @@ minetest.register_chatcommand("/dome", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.dome(pos, tonumber(radius), node, tenv)
local count = worldedit.dome(pos, tonumber(radius), node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -490,11 +466,7 @@ minetest.register_chatcommand("/hollowcylinder", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.hollow_cylinder(pos, axis, length, radius, node, tenv)
local count = worldedit.hollow_cylinder(pos, axis, length, radius, node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -526,11 +498,7 @@ minetest.register_chatcommand("/cylinder", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.cylinder(pos, axis, length, radius, node, tenv)
local count = worldedit.cylinder(pos, axis, length, radius, node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -589,11 +557,7 @@ minetest.register_chatcommand("/spiral", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), node, tenv)
local count = worldedit.spiral(pos, tonumber(width), tonumber(height), tonumber(space), node)
worldedit.player_notify(name, count .. " nodes added")
end,
})
@ -620,11 +584,7 @@ minetest.register_chatcommand("/copy", {
amount = amount * sign
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.copy(pos1, pos2, axis, amount, tenv)
local count = worldedit.copy(pos1, pos2, axis, amount)
worldedit.player_notify(name, count .. " nodes copied")
end,
})
@ -651,11 +611,7 @@ minetest.register_chatcommand("/move", {
amount = amount * sign
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.move(pos1, pos2, axis, amount, tenv)
local count = worldedit.move(pos1, pos2, axis, amount)
pos1[axis] = pos1[axis] + amount
pos2[axis] = pos2[axis] + amount
@ -687,11 +643,7 @@ minetest.register_chatcommand("/stack", {
count = count * sign
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.stack(pos1, pos2, axis, count, tenv)
local count = worldedit.stack(pos1, pos2, axis, count)
worldedit.player_notify(name, count .. " nodes stacked")
end,
})
@ -712,11 +664,7 @@ minetest.register_chatcommand("/scale", {
worldedit.player_notify(name, "invalid scaling factor: " .. param)
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor, tenv)
local count, pos1, pos2 = worldedit.scale(pos1, pos2, factor)
--reset markers to scaled positions
worldedit.pos1[name] = pos1
@ -755,11 +703,7 @@ minetest.register_chatcommand("/transpose", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2, tenv)
local count, pos1, pos2 = worldedit.transpose(pos1, pos2, axis1, axis2)
--reset markers to transposed positions
worldedit.pos1[name] = pos1
@ -790,11 +734,7 @@ minetest.register_chatcommand("/flip", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.flip(pos1, pos2, param, tenv)
local count = worldedit.flip(pos1, pos2, param)
worldedit.player_notify(name, count .. " nodes flipped")
end,
})
@ -856,11 +796,7 @@ minetest.register_chatcommand("/orient", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.orient(pos1, pos2, angle, tenv)
local count = worldedit.orient(pos1, pos2, angle)
worldedit.player_notify(name, count .. " nodes oriented")
end,
@ -877,11 +813,7 @@ minetest.register_chatcommand("/fixlight", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.fixlight(pos1, pos2, tenv)
local count = worldedit.fixlight(pos1, pos2)
worldedit.player_notify(name, count .. " nodes updated")
end,
})
@ -919,11 +851,7 @@ minetest.register_chatcommand("/suppress", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.suppress(pos1, pos2, node, tenv)
local count = worldedit.suppress(pos1, pos2, node)
worldedit.player_notify(name, count .. " nodes suppressed")
end,
})
@ -945,11 +873,7 @@ minetest.register_chatcommand("/highlight", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.highlight(pos1, pos2, node, tenv)
local count = worldedit.highlight(pos1, pos2, node)
worldedit.player_notify(name, count .. " nodes highlighted")
end,
})
@ -965,11 +889,7 @@ minetest.register_chatcommand("/restore", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.restore(pos1, pos2, tenv)
local count = worldedit.restore(pos1, pos2)
worldedit.player_notify(name, count .. " nodes restored")
end,
})
@ -1089,11 +1009,7 @@ minetest.register_chatcommand("/load", {
return
end
local tenv = minetest.env
if worldedit.ENABLE_QUEUE then
tenv = worldedit.queue_aliasenv
end
local count = worldedit.deserialize(pos1, value, tenv)
local count = worldedit.deserialize(pos1, value)
worldedit.player_notify(name, count .. " nodes loaded")
end,

View File

@ -1,32 +1,67 @@
worldedit.marker1 = {}
worldedit.marker2 = {}
worldedit.marker = {}
--wip: use this as a huge entity to make a full worldedit region box
minetest.register_entity(":worldedit:region_cube", {
initial_properties = {
visual = "upright_sprite",
visual_size = {x=1.1, y=1.1},
textures = {"worldedit_pos1.png"},
visual_size = {x=10, y=10},
physical = false,
},
on_step = function(self, dtime)
if self.active == nil then
self.object:remove()
end
end,
on_punch = function(self, hitter)
--wip: remove the entire region marker
end,
})
--wip: use voxelmanip to put the entity in the correct spot
--marks worldedit region position 1
worldedit.mark_pos1 = function(name)
local pos = worldedit.pos1[name]
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if worldedit.marker1[name] ~= nil then --marker already exists
worldedit.marker1[name]:remove() --remove marker
worldedit.marker1[name] = nil
end
if pos ~= nil then --add marker
worldedit.marker1[name] = minetest.env:add_entity(pos, "worldedit:pos1")
if pos1 ~= nil then --add marker
worldedit.marker1[name] = minetest.add_entity(pos1, "worldedit:pos1")
worldedit.marker1[name]:get_luaentity().active = true
if pos2 ~= nil then --region defined
worldedit.mark_region(pos1, pos2)
end
end
end
--marks worldedit region position 2
worldedit.mark_pos2 = function(name)
local pos = worldedit.pos2[name]
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
if worldedit.marker2[name] ~= nil then --marker already exists
worldedit.marker2[name]:remove() --remove marker
worldedit.marker2[name] = nil
end
if pos ~= nil then --add marker
worldedit.marker2[name] = minetest.env:add_entity(pos, "worldedit:pos2")
if pos2 ~= nil then --add marker
worldedit.marker2[name] = minetest.add_entity(pos2, "worldedit:pos2")
worldedit.marker2[name]:get_luaentity().active = true
if pos1 ~= nil then --region defined
worldedit.mark_region(pos1, pos2)
end
end
end
worldedit.mark_region = function(pos1, pos2)
if worldedit.marker[name] ~= nil then --marker already exists
--wip: remove markers
end
end
minetest.register_entity(":worldedit:pos1", {
initial_properties = {
visual = "cube",
@ -35,6 +70,7 @@ minetest.register_entity(":worldedit:pos1", {
"worldedit_pos1.png", "worldedit_pos1.png",
"worldedit_pos1.png", "worldedit_pos1.png"},
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
physical = false,
},
on_step = function(self, dtime)
if self.active == nil then
@ -56,6 +92,7 @@ minetest.register_entity(":worldedit:pos2", {
"worldedit_pos2.png", "worldedit_pos2.png",
"worldedit_pos2.png", "worldedit_pos2.png"},
collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
physical = false,
},
on_step = function(self, dtime)
if self.active == nil then