1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-25 02:00:39 +01:00

Switch bare vectors to vector.new()

This commit is contained in:
sfan5 2023-06-09 14:28:29 +02:00
parent 1a9f66f091
commit 7f7e928dd9
9 changed files with 63 additions and 60 deletions

View File

@ -31,7 +31,7 @@ function worldedit.luatransform(pos1, pos2, code)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y
while pos.y <= pos2.y do while pos.y <= pos2.y do

View File

@ -5,8 +5,8 @@
-- `pos1` is less than or equal to the corresponding component of `pos2`. -- `pos1` is less than or equal to the corresponding component of `pos2`.
-- Returns the new positions. -- Returns the new positions.
function worldedit.sort_pos(pos1, pos2) function worldedit.sort_pos(pos1, pos2)
pos1 = {x=pos1.x, y=pos1.y, z=pos1.z} pos1 = vector.new(pos1.x, pos1.y, pos1.z)
pos2 = {x=pos2.x, y=pos2.y, z=pos2.z} pos2 = vector.new(pos2.x, pos2.y, pos2.z)
if pos1.x > pos2.x then if pos1.x > pos2.x then
pos2.x, pos1.x = pos1.x, pos2.x pos2.x, pos1.x = pos1.x, pos2.x
end end

View File

@ -128,7 +128,7 @@ function worldedit.stack2(pos1, pos2, direction, amount, finished)
direction = table.copy(direction) direction = table.copy(direction)
local i = 0 local i = 0
local translated = {x=0, y=0, z=0} local translated = vector.new()
local function step() local function step()
translated.x = translated.x + direction.x translated.x = translated.x + direction.x
translated.y = translated.y + direction.y translated.y = translated.y + direction.y
@ -155,7 +155,7 @@ function worldedit.copy(pos1, pos2, axis, amount)
-- Decide if we need to copy stuff backwards (only applies to metadata) -- Decide if we need to copy stuff backwards (only applies to metadata)
local backwards = amount > 0 and amount < (pos2[axis] - pos1[axis] + 1) local backwards = amount > 0 and amount < (pos2[axis] - pos1[axis] + 1)
local off = {x=0, y=0, z=0} local off = vector.new()
off[axis] = amount off[axis] = amount
return worldedit.copy2(pos1, pos2, off, backwards) return worldedit.copy2(pos1, pos2, off, backwards)
end end
@ -170,7 +170,7 @@ function worldedit.copy2(pos1, pos2, off, meta_backwards)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2) local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
local src_manip, src_area = mh.init(pos1, pos2) local src_manip, src_area = mh.init(pos1, pos2)
local src_stride = {x=1, y=src_area.ystride, z=src_area.zstride} local src_stride = vector.new(1, src_area.ystride, src_area.zstride)
local src_offset = vector.subtract(pos1, src_area.MinEdge) local src_offset = vector.subtract(pos1, src_area.MinEdge)
local dpos1 = vector.add(pos1, off) local dpos1 = vector.add(pos1, off)
@ -178,7 +178,7 @@ function worldedit.copy2(pos1, pos2, off, meta_backwards)
local dim = vector.add(vector.subtract(pos2, pos1), 1) local dim = vector.add(vector.subtract(pos2, pos1), 1)
local dst_manip, dst_area = mh.init(dpos1, dpos2) local dst_manip, dst_area = mh.init(dpos1, dpos2)
local dst_stride = {x=1, y=dst_area.ystride, z=dst_area.zstride} local dst_stride = vector.new(1, dst_area.ystride, dst_area.zstride)
local dst_offset = vector.subtract(dpos1, dst_area.MinEdge) local dst_offset = vector.subtract(dpos1, dst_area.MinEdge)
local function do_copy(src_data, dst_data) local function do_copy(src_data, dst_data)
@ -226,7 +226,7 @@ function worldedit.copy2(pos1, pos2, off, meta_backwards)
for z = dim.z-1, 0, -1 do for z = dim.z-1, 0, -1 do
for y = dim.y-1, 0, -1 do for y = dim.y-1, 0, -1 do
for x = dim.x-1, 0, -1 do for x = dim.x-1, 0, -1 do
local pos = {x=pos1.x+x, y=pos1.y+y, z=pos1.z+z} local pos = vector.new(pos1.x+x, pos1.y+y, pos1.z+z)
local meta = get_meta(pos):to_table() local meta = get_meta(pos):to_table()
pos = vector.add(pos, off) pos = vector.add(pos, off)
get_meta(pos):from_table(meta) get_meta(pos):from_table(meta)
@ -237,7 +237,7 @@ function worldedit.copy2(pos1, pos2, off, meta_backwards)
for z = 0, dim.z-1 do for z = 0, dim.z-1 do
for y = 0, dim.y-1 do for y = 0, dim.y-1 do
for x = 0, dim.x-1 do for x = 0, dim.x-1 do
local pos = {x=pos1.x+x, y=pos1.y+y, z=pos1.z+z} local pos = vector.new(pos1.x+x, pos1.y+y, pos1.z+z)
local meta = get_meta(pos):to_table() local meta = get_meta(pos):to_table()
pos = vector.add(pos, off) pos = vector.add(pos, off)
get_meta(pos):from_table(meta) get_meta(pos):from_table(meta)
@ -286,21 +286,21 @@ function worldedit.move(pos1, pos2, axis, amount)
end end
-- Copy stuff to new location -- Copy stuff to new location
local off = {x=0, y=0, z=0} local off = vector.new()
off[axis] = amount off[axis] = amount
worldedit.copy2(pos1, pos2, off, backwards) worldedit.copy2(pos1, pos2, off, backwards)
-- Nuke old area -- Nuke old area
if not overlap then if not overlap then
nuke_area({x=0, y=0, z=0}, dim) nuke_area(vector.new(), dim)
else else
-- Source and destination region are overlapping, which means we can't -- Source and destination region are overlapping, which means we can't
-- blindly delete the [pos1, pos2] area -- blindly delete the [pos1, pos2] area
local leftover = vector.new(dim) -- size of the leftover slice local leftover = vector.new(dim) -- size of the leftover slice
leftover[axis] = math.abs(amount) leftover[axis] = math.abs(amount)
if amount > 0 then if amount > 0 then
nuke_area({x=0, y=0, z=0}, leftover) nuke_area(vector.new(), leftover)
else else
local top = {x=0, y=0, z=0} -- offset of the leftover slice from pos1 local top = vector.new() -- offset of the leftover slice from pos1
top[axis] = dim[axis] - math.abs(amount) top[axis] = dim[axis] - math.abs(amount)
nuke_area(top, leftover) nuke_area(top, leftover)
end end
@ -358,7 +358,7 @@ function worldedit.stretch(pos1, pos2, stretch_x, stretch_y, stretch_z)
for i = 1, stretch_x * stretch_y * stretch_z do for i = 1, stretch_x * stretch_y * stretch_z do
nodes[i] = placeholder_node nodes[i] = placeholder_node
end end
local schematic = {size={x=stretch_x, y=stretch_y, z=stretch_z}, data=nodes} local schematic = {size=vector.new(stretch_x, stretch_y, stretch_z), data=nodes}
local size_x, size_y, size_z = stretch_x - 1, stretch_y - 1, stretch_z - 1 local size_x, size_y, size_z = stretch_x - 1, stretch_y - 1, stretch_z - 1
@ -369,8 +369,8 @@ function worldedit.stretch(pos1, pos2, stretch_x, stretch_y, stretch_z)
} }
worldedit.keep_loaded(pos1, new_pos2) worldedit.keep_loaded(pos1, new_pos2)
local pos = {x=pos2.x, y=0, z=0} local pos = vector.new(pos2.x, 0, 0)
local big_pos = {x=0, y=0, z=0} local big_pos = vector.new()
while pos.x >= pos1.x do while pos.x >= pos1.x do
pos.y = pos2.y pos.y = pos2.y
while pos.y >= pos1.y do while pos.y >= pos1.y do
@ -436,16 +436,16 @@ function worldedit.transpose(pos1, pos2, axis1, axis2)
end end
-- Calculate the new position 2 after transposition -- Calculate the new position 2 after transposition
local new_pos2 = {x=pos2.x, y=pos2.y, z=pos2.z} local new_pos2 = vector.new(pos2)
new_pos2[axis1] = pos1[axis1] + extent2 new_pos2[axis1] = pos1[axis1] + extent2
new_pos2[axis2] = pos1[axis2] + extent1 new_pos2[axis2] = pos1[axis2] + extent1
local upper_bound = {x=pos2.x, y=pos2.y, z=pos2.z} local upper_bound = vector.new(pos2)
if upper_bound[axis1] < new_pos2[axis1] then upper_bound[axis1] = new_pos2[axis1] end if upper_bound[axis1] < new_pos2[axis1] then upper_bound[axis1] = new_pos2[axis1] end
if upper_bound[axis2] < new_pos2[axis2] then upper_bound[axis2] = new_pos2[axis2] end if upper_bound[axis2] < new_pos2[axis2] then upper_bound[axis2] = new_pos2[axis2] end
worldedit.keep_loaded(pos1, upper_bound) worldedit.keep_loaded(pos1, upper_bound)
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
local get_node, get_meta, set_node = minetest.get_node, local get_node, get_meta, set_node = minetest.get_node,
minetest.get_meta, minetest.set_node minetest.get_meta, minetest.set_node
while pos.x <= pos2.x do while pos.x <= pos2.x do
@ -485,7 +485,7 @@ function worldedit.flip(pos1, pos2, axis)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
--- TODO: Flip the region slice by slice along the flip axis using schematic method. --- TODO: Flip the region slice by slice along the flip axis using schematic method.
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
local start = pos1[axis] + pos2[axis] local start = pos1[axis] + pos2[axis]
pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2) pos2[axis] = pos1[axis] + math.floor((pos2[axis] - pos1[axis]) / 2)
local get_node, get_meta, set_node = minetest.get_node, local get_node, get_meta, set_node = minetest.get_node,
@ -584,7 +584,7 @@ function worldedit.orient(pos1, pos2, angle)
local count = 0 local count = 0
local get_node, swap_node = minetest.get_node, minetest.swap_node local get_node, swap_node = minetest.get_node, minetest.swap_node
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
while pos.x <= pos2.x do while pos.x <= pos2.x do
pos.y = pos1.y pos.y = pos1.y
while pos.y <= pos2.y do while pos.y <= pos2.y do
@ -650,13 +650,12 @@ function worldedit.clear_objects(pos1, pos2)
end end
-- Offset positions to include full nodes (positions are in the center of nodes) -- Offset positions to include full nodes (positions are in the center of nodes)
local pos1x, pos1y, pos1z = pos1.x - 0.5, pos1.y - 0.5, pos1.z - 0.5 pos1 = vector.add(pos1, -0.5)
local pos2x, pos2y, pos2z = pos2.x + 0.5, pos2.y + 0.5, pos2.z + 0.5 pos2 = vector.add(pos1, 0.5)
local count = 0 local count = 0
if minetest.get_objects_in_area then if minetest.get_objects_in_area then
local objects = minetest.get_objects_in_area({x=pos1x, y=pos1y, z=pos1z}, local objects = minetest.get_objects_in_area(pos1, pos2)
{x=pos2x, y=pos2y, z=pos2z})
for _, obj in pairs(objects) do for _, obj in pairs(objects) do
if should_delete(obj) then if should_delete(obj) then
@ -670,21 +669,21 @@ function worldedit.clear_objects(pos1, pos2)
-- Fallback implementation via get_objects_inside_radius -- Fallback implementation via get_objects_inside_radius
-- Center of region -- Center of region
local center = { local center = {
x = pos1x + ((pos2x - pos1x) / 2), x = pos1.x + ((pos2.x - pos1.x) / 2),
y = pos1y + ((pos2y - pos1y) / 2), y = pos1.y + ((pos2.y - pos1.y) / 2),
z = pos1z + ((pos2z - pos1z) / 2) z = pos1.z + ((pos2.z - pos1.z) / 2)
} }
-- Bounding sphere radius -- Bounding sphere radius
local radius = math.sqrt( local radius = math.sqrt(
(center.x - pos1x) ^ 2 + (center.x - pos1.x) ^ 2 +
(center.y - pos1y) ^ 2 + (center.y - pos1.y) ^ 2 +
(center.z - pos1z) ^ 2) (center.z - pos1.z) ^ 2)
for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do for _, obj in pairs(minetest.get_objects_inside_radius(center, radius)) do
if should_delete(obj) then if should_delete(obj) then
local pos = obj:get_pos() local pos = obj:get_pos()
if pos.x >= pos1x and pos.x <= pos2x and if pos.x >= pos1.x and pos.x <= pos2.x and
pos.y >= pos1y and pos.y <= pos2y and pos.y >= pos1.y and pos.y <= pos2.y and
pos.z >= pos1z and pos.z <= pos2z then pos.z >= pos1.z and pos.z <= pos2.z then
-- Inside region -- Inside region
obj:remove() obj:remove()
count = count + 1 count = count + 1

View File

@ -20,7 +20,7 @@ function worldedit.cube(pos, width, height, length, node_name, hollow)
-- Add cube -- Add cube
local node_id = minetest.get_content_id(node_name) local node_id = minetest.get_content_id(node_name)
local stride = {x=1, y=area.ystride, z=area.zstride} local stride = vector.new(1, area.ystride, area.zstride)
local offset = vector.subtract(basepos, area.MinEdge) local offset = vector.subtract(basepos, area.MinEdge)
local count = 0 local count = 0
@ -149,7 +149,7 @@ function worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, holl
end end
-- Handle negative lengths -- Handle negative lengths
local current_pos = {x=pos.x, y=pos.y, z=pos.z} local current_pos = vector.new(pos)
if length < 0 then if length < 0 then
length = -length length = -length
current_pos[axis] = current_pos[axis] - length current_pos[axis] = current_pos[axis] - length
@ -162,7 +162,7 @@ function worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, holl
-- Add desired shape (anything inbetween cylinder & cone) -- Add desired shape (anything inbetween cylinder & cone)
local node_id = minetest.get_content_id(node_name) local node_id = minetest.get_content_id(node_name)
local stride = {x=1, y=area.ystride, z=area.zstride} local stride = vector.new(1, area.ystride, area.zstride)
local offset = { local offset = {
x = current_pos.x - area.MinEdge.x, x = current_pos.x - area.MinEdge.x,
y = current_pos.y - area.MinEdge.y, y = current_pos.y - area.MinEdge.y,
@ -225,7 +225,7 @@ function worldedit.pyramid(pos, axis, height, node_name, hollow)
-- Add pyramid -- Add pyramid
local node_id = minetest.get_content_id(node_name) local node_id = minetest.get_content_id(node_name)
local stride = {x=1, y=area.ystride, z=area.zstride} local stride = vector.new(1, area.ystride, area.zstride)
local offset = { local offset = {
x = pos.x - area.MinEdge.x, x = pos.x - area.MinEdge.x,
y = pos.y - area.MinEdge.y, y = pos.y - area.MinEdge.y,
@ -271,7 +271,7 @@ function worldedit.spiral(pos, length, height, spacer, node_name)
-- Set up variables -- Set up variables
local node_id = minetest.get_content_id(node_name) local node_id = minetest.get_content_id(node_name)
local stride = {x=1, y=area.ystride, z=area.zstride} local stride = vector.new(1, area.ystride, area.zstride)
local offset_x, offset_y, offset_z = pos.x - area.MinEdge.x, pos.y - area.MinEdge.y, pos.z - area.MinEdge.z local offset_x, offset_y, offset_z = pos.x - area.MinEdge.x, pos.y - area.MinEdge.y, pos.z - area.MinEdge.z
local i = offset_z * stride.z + offset_y * stride.y + offset_x + 1 local i = offset_z * stride.z + offset_y * stride.y + offset_x + 1

View File

@ -66,7 +66,7 @@ function worldedit.serialize(pos1, pos2)
has_meta[hash_node_position(meta_positions[i])] = true has_meta[hash_node_position(meta_positions[i])] = true
end end
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
local count = 0 local count = 0
local result = {} local result = {}
while pos.x <= pos2.x do while pos.x <= pos2.x do
@ -235,9 +235,7 @@ function worldedit.allocate_with_nodes(origin_pos, nodes)
if y > pos2y then pos2y = y end if y > pos2y then pos2y = y end
if z > pos2z then pos2z = z end if z > pos2z then pos2z = z end
end end
local pos1 = {x=pos1x, y=pos1y, z=pos1z} return vector.new(pos1x, pos1y, pos1z), vector.new(pos2x, pos2y, pos2z), #nodes
local pos2 = {x=pos2x, y=pos2y, z=pos2z}
return pos1, pos2, #nodes
end end

View File

@ -87,10 +87,10 @@ do
-- Returns an usable area [pos1, pos2] that does not overlap previous ones -- Returns an usable area [pos1, pos2] that does not overlap previous ones
area.get = function(sizex, sizey, sizez) area.get = function(sizex, sizey, sizez)
local size local size
if sizey == nil or sizez == nil then if sizey == nil and sizez == nil then
size = {x=sizex, y=sizex, z=sizex} size = vector.new(sizex, sizex, sizex)
else else
size = {x=sizex, y=sizey, z=sizez} size = vector.new(sizex, sizey, sizez)
end end
local pos1 = vector.add(areamin, off) local pos1 = vector.add(areamin, off)
local pos2 = vector.subtract(vector.add(pos1, size), 1) local pos2 = vector.subtract(vector.add(pos1, size), 1)
@ -425,7 +425,7 @@ do
local fmt51 = '{[r2]=0,x=%d,y=%d,z=%d,name=r%d}' local fmt51 = '{[r2]=0,x=%d,y=%d,z=%d,name=r%d}'
local fmt52 = '{x=%d,y=%d,z=%d,name=_[%d]}' local fmt52 = '{x=%d,y=%d,z=%d,name=_[%d]}'
local test_data = { local test_data = {
-- used by WorldEdit 0.4.2.1 (first public release) -- used by WorldEdit 0.2 (first public release)
{ {
name = "v1", ver = 1, name = "v1", ver = 1,
gen = function(pat) gen = function(pat)
@ -560,7 +560,7 @@ worldedit.run_tests = function()
for x = 0, math.floor(wanted.x/16) do for x = 0, math.floor(wanted.x/16) do
for y = 0, math.floor(wanted.y/16) do for y = 0, math.floor(wanted.y/16) do
for z = 0, math.floor(wanted.z/16) do for z = 0, math.floor(wanted.z/16) do
assert(minetest.forceload_block({x=x*16, y=y*16, z=z*16}, true)) assert(minetest.forceload_block(vector.new(x*16, y*16, z*16), true))
end end
end end
end end

View File

@ -19,7 +19,7 @@ function worldedit.hide(pos1, pos2)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
local get_node, get_meta, swap_node = minetest.get_node, local get_node, get_meta, swap_node = minetest.get_node,
minetest.get_meta, minetest.swap_node minetest.get_meta, minetest.swap_node
while pos.x <= pos2.x do while pos.x <= pos2.x do
@ -79,7 +79,7 @@ function worldedit.highlight(pos1, pos2, node_name)
worldedit.keep_loaded(pos1, pos2) worldedit.keep_loaded(pos1, pos2)
local pos = {x=pos1.x, y=0, z=0} local pos = vector.new(pos1.x, 0, 0)
local get_node, get_meta, swap_node = minetest.get_node, local get_node, get_meta, swap_node = minetest.get_node,
minetest.get_meta, minetest.swap_node minetest.get_meta, minetest.swap_node
local count = 0 local count = 0

View File

@ -27,7 +27,7 @@ local brush_on_use = function(itemstack, placer)
end end
local raybegin = vector.add(placer:get_pos(), local raybegin = vector.add(placer:get_pos(),
{x=0, y=placer:get_properties().eye_height, z=0}) vector.new(0, placer:get_properties().eye_height, 0))
local rayend = vector.add(raybegin, vector.multiply(placer:get_look_dir(), BRUSH_MAX_DIST)) local rayend = vector.add(raybegin, vector.multiply(placer:get_look_dir(), BRUSH_MAX_DIST))
local ray = minetest.raycast(raybegin, rayend, false, true) local ray = minetest.raycast(raybegin, rayend, false, true)
local pointed_thing = ray:next() local pointed_thing = ray:next()

View File

@ -488,7 +488,7 @@ worldedit.register_command("fixedpos", {
if found == nil then if found == nil then
return false return false
end end
return true, flag, {x=tonumber(x), y=tonumber(y), z=tonumber(z)} return true, flag, vector.new(tonumber(x), tonumber(y), tonumber(z))
end, end,
func = function(name, flag, pos) func = function(name, flag, pos)
if flag == "set1" then if flag == "set1" then
@ -1047,7 +1047,7 @@ worldedit.register_command("stack2", {
return false, "invalid increments: " .. param return false, "invalid increments: " .. param
end end
return true, tonumber(repetitions), {x=tonumber(x), y=tonumber(y), z=tonumber(z)} return true, tonumber(repetitions), vector.new(tonumber(x), tonumber(y), tonumber(z))
end, end,
nodes_needed = function(name, repetitions, offset) nodes_needed = function(name, repetitions, offset)
return check_region(name) * repetitions return check_region(name) * repetitions
@ -1219,13 +1219,16 @@ worldedit.register_command("drain", {
-- TODO: make an API function for this -- TODO: make an API function for this
local count = 0 local count = 0
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name]) local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])
local get_node, remove_node = minetest.get_node, minetest.remove_node
for x = pos1.x, pos2.x do for x = pos1.x, pos2.x do
for y = pos1.y, pos2.y do for y = pos1.y, pos2.y do
for z = pos1.z, pos2.z do for z = pos1.z, pos2.z do
local n = minetest.get_node({x=x, y=y, z=z}).name local p = vector.new(x, y, z)
local n = get_node(p).name
local d = minetest.registered_nodes[n] local d = minetest.registered_nodes[n]
if d ~= nil and (d["drawtype"] == "liquid" or d["drawtype"] == "flowingliquid") then if d ~= nil and (d.drawtype == "liquid" or d.drawtype == "flowingliquid") then
minetest.remove_node({x=x, y=y, z=z}) remove_node(p)
count = count + 1 count = count + 1
end end
end end
@ -1263,13 +1266,15 @@ local function clearcut(pos1, pos2)
local count = 0 local count = 0
local prev, any local prev, any
local get_node, remove_node = minetest.get_node, minetest.remove_node
for x = pos1.x, pos2.x do for x = pos1.x, pos2.x do
for z = pos1.z, pos2.z do for z = pos1.z, pos2.z do
prev = false prev = false
any = false any = false
-- first pass: remove floating nodes that would be left over -- first pass: remove floating nodes that would be left over
for y = pos1.y, pos2.y do for y = pos1.y, pos2.y do
local n = minetest.get_node({x=x, y=y, z=z}).name local pos = vector.new(x, y, z)
local n = get_node(pos).name
if plants[n] then if plants[n] then
prev = true prev = true
any = true any = true
@ -1277,7 +1282,7 @@ local function clearcut(pos1, pos2)
local def = minetest.registered_nodes[n] or {} local def = minetest.registered_nodes[n] or {}
local groups = def.groups or {} local groups = def.groups or {}
if groups.attached_node or (def.buildable_to and groups.falling_node) then if groups.attached_node or (def.buildable_to and groups.falling_node) then
minetest.remove_node({x=x, y=y, z=z}) remove_node(pos)
count = count + 1 count = count + 1
else else
prev = false prev = false
@ -1288,9 +1293,10 @@ local function clearcut(pos1, pos2)
-- second pass: remove plants, top-to-bottom to avoid item drops -- second pass: remove plants, top-to-bottom to avoid item drops
if any then if any then
for y = pos2.y, pos1.y, -1 do for y = pos2.y, pos1.y, -1 do
local n = minetest.get_node({x=x, y=y, z=z}).name local pos = vector.new(x, y, z)
local n = get_node(pos).name
if plants[n] then if plants[n] then
minetest.remove_node({x=x, y=y, z=z}) remove_node(pos)
count = count + 1 count = count + 1
end end
end end