2018-10-14 01:19:32 +02:00
|
|
|
--- Overlap command. Places a specified node on top of each column.
|
2018-05-22 23:20:26 +02:00
|
|
|
-- @module worldeditadditions.overlay
|
|
|
|
|
2020-06-07 21:46:46 +02:00
|
|
|
function worldeditadditions.overlay(pos1, pos2, node_weights)
|
2018-05-22 23:20:26 +02:00
|
|
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
|
|
|
-- pos2 will always have the highest co-ordinates now
|
|
|
|
|
|
|
|
-- Fetch the nodes in the specified area
|
|
|
|
local manip, area = worldedit.manip_helpers.init(pos1, pos2)
|
|
|
|
local data = manip:get_data()
|
|
|
|
|
2020-06-07 21:46:46 +02:00
|
|
|
local node_id_ignore = minetest.get_content_id("ignore")
|
|
|
|
|
|
|
|
local node_ids, node_ids_count = worldeditadditions.make_weighted(node_weights)
|
2018-05-22 23:20:26 +02:00
|
|
|
|
2020-05-11 00:29:49 +02:00
|
|
|
-- minetest.log("action", "pos1: " .. worldeditadditions.vector.tostring(pos1))
|
|
|
|
-- minetest.log("action", "pos2: " .. worldeditadditions.vector.tostring(pos2))
|
2018-05-22 23:20:26 +02:00
|
|
|
|
|
|
|
-- z y x is the preferred loop order, but that isn't really possible here
|
|
|
|
|
|
|
|
local changes = { updated = 0, skipped_columns = 0 }
|
|
|
|
for z = pos2.z, pos1.z, -1 do
|
|
|
|
for x = pos2.x, pos1.x, -1 do
|
|
|
|
local found_air = false
|
|
|
|
local placed_node = false
|
|
|
|
|
|
|
|
for y = pos2.y, pos1.y, -1 do
|
2020-06-07 21:46:46 +02:00
|
|
|
local i = area:index(x, y, z)
|
|
|
|
|
2020-06-11 01:38:16 +02:00
|
|
|
local is_air = worldeditadditions.is_airlike(data[i])
|
2020-06-07 21:46:46 +02:00
|
|
|
if not is_air then -- wielded_light nodes are airlike too
|
|
|
|
local this_node_name = minetest.get_name_from_content_id(data[i])
|
|
|
|
is_air = is_air or worldeditadditions.string_starts(this_node_name, "wielded_light")
|
|
|
|
end
|
|
|
|
local is_ignore = data[i] == node_id_ignore
|
|
|
|
|
|
|
|
if not is_air and not is_ignore then
|
2018-05-22 23:20:26 +02:00
|
|
|
if found_air then
|
2020-06-07 21:46:46 +02:00
|
|
|
local new_id = node_ids[math.random(node_ids_count)]
|
2018-05-22 23:20:26 +02:00
|
|
|
-- We've found an air block previously, so it must be above us
|
|
|
|
-- Replace the node above us with the target block
|
2020-06-07 21:46:46 +02:00
|
|
|
data[area:index(x, y + 1, z)] = new_id
|
2018-05-22 23:20:26 +02:00
|
|
|
changes.updated = changes.updated + 1
|
|
|
|
placed_node = true
|
|
|
|
break -- Move on to the next column
|
|
|
|
end
|
2020-06-07 21:46:46 +02:00
|
|
|
elseif not is_ignore then
|
2018-05-22 23:20:26 +02:00
|
|
|
found_air = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not placed_node then
|
|
|
|
changes.skipped_columns = changes.skipped_columns + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- Save the modified nodes back to disk & return
|
|
|
|
worldedit.manip_helpers.finish(manip, data)
|
|
|
|
|
|
|
|
return changes
|
|
|
|
end
|