//overlay: Don't place nodes above water

Fixes #38
This commit is contained in:
Starbeamrainbowlabs 2021-03-02 00:09:46 +00:00
parent 093a4823bb
commit feb4d6a4bf
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
3 changed files with 12 additions and 5 deletions

@ -5,6 +5,7 @@ It's about time I started a changelog! This will serve from now on as the main c
## v1.12 (unreleased) ## v1.12 (unreleased)
- Add `//srect` (_select rectangle_) - thanks, @VorTechnix! - Add `//srect` (_select rectangle_) - thanks, @VorTechnix!
- Add `//spush`, `//spop`, and `//sstack` - Add `//spush`, `//spop`, and `//sstack`
- `//overlay`: Don't place nodes above water
## v1.11: The big data update (25th January 2021) ## v1.11: The big data update (25th January 2021)

@ -23,32 +23,38 @@ function worldeditadditions.overlay(pos1, pos2, node_weights)
for x = pos2.x, pos1.x, -1 do for x = pos2.x, pos1.x, -1 do
local found_air = false local found_air = false
local placed_node = false local placed_node = false
-- print("\n\n[overlay] ****** column start ******")
for y = pos2.y, pos1.y, -1 do for y = pos2.y, pos1.y, -1 do
local i = area:index(x, y, z) local i = area:index(x, y, z)
-- print("[overlay] pos", x, y, z, "id", data[i], "name", minetest.get_name_from_content_id(data[i]), "is_liquid", worldeditadditions.is_liquidlike(data[i]))
local is_air = worldeditadditions.is_airlike(data[i]) local is_air = worldeditadditions.is_airlike(data[i])
local is_liquid = worldeditadditions.is_liquidlike(data[i])
-- wielded_light is now handled by worldeditadditions.is_airlike -- wielded_light is now handled by worldeditadditions.is_airlike
local is_ignore = data[i] == node_id_ignore local is_ignore = data[i] == node_id_ignore
if not is_air and not is_ignore then if not is_air and not is_ignore then
if found_air then local i_above = area:index(x, y + 1, z)
if found_air and not is_liquid then
local new_id = node_ids[math.random(node_ids_count)] local new_id = node_ids[math.random(node_ids_count)]
-- We've found an air block previously, so it must be above us -- We've found an air block previously, so it must be above us
-- Replace the node above us with the target block -- Replace the node above us with the target block
data[area:index(x, y + 1, z)] = new_id data[i_above] = new_id
changes.updated = changes.updated + 1 changes.updated = changes.updated + 1
placed_node = true placed_node = true
if not changes.placed[new_id] then if not changes.placed[new_id] then
changes.placed[new_id] = 0 changes.placed[new_id] = 0
end end
changes.placed[new_id] = changes.placed[new_id] + 1 changes.placed[new_id] = changes.placed[new_id] + 1
-- print("[overlay] placed above ", x, y, z)
break -- Move on to the next column break -- Move on to the next column
end end
elseif not is_ignore then elseif not is_ignore and not is_liquid then
-- print("[overlay] found air at", x, y, z)
found_air = true found_air = true
end end
if is_liquid then found_air = false end
end end
if not placed_node then if not placed_node then

@ -44,7 +44,7 @@ function worldeditadditions.is_liquidlike(id)
if node_name == nil or not minetest.registered_nodes[node_name] then return false end if node_name == nil or not minetest.registered_nodes[node_name] then return false end
local liquidtype = minetest.registered_nodes[node_name].liquidtype local liquidtype = minetest.registered_nodes[node_name].liquidtype
-- print("[is_liquidlike]", "id", id, "liquidtype", liquidtype) -- print("[is_liquidlike]", "id", id, "name", node_name, "liquidtype", liquidtype)
if liquidtype == nil or liquidtype == "none" then return false end if liquidtype == nil or liquidtype == "none" then return false end
-- If it's not none, then it has to be a liquid as the only other values are source and flowing -- If it's not none, then it has to be a liquid as the only other values are source and flowing