From feb4d6a4bfeea096d6ea27762e053f3c99de1ca9 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 2 Mar 2021 00:09:46 +0000 Subject: [PATCH] //overlay: Don't place nodes above water Fixes #38 --- CHANGELOG.md | 1 + worldeditadditions/lib/overlay.lua | 14 ++++++++++---- worldeditadditions/utils/node_identification.lua | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b02c9b7..4b450c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) - Add `//srect` (_select rectangle_) - thanks, @VorTechnix! - Add `//spush`, `//spop`, and `//sstack` + - `//overlay`: Don't place nodes above water ## v1.11: The big data update (25th January 2021) diff --git a/worldeditadditions/lib/overlay.lua b/worldeditadditions/lib/overlay.lua index 12a35f5..cc21b8d 100644 --- a/worldeditadditions/lib/overlay.lua +++ b/worldeditadditions/lib/overlay.lua @@ -23,32 +23,38 @@ function worldeditadditions.overlay(pos1, pos2, node_weights) for x = pos2.x, pos1.x, -1 do local found_air = false local placed_node = false - + -- print("\n\n[overlay] ****** column start ******") for y = pos2.y, pos1.y, -1 do 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_liquid = worldeditadditions.is_liquidlike(data[i]) -- wielded_light is now handled by worldeditadditions.is_airlike local is_ignore = data[i] == node_id_ignore 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)] -- We've found an air block previously, so it must be above us -- 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 placed_node = true if not changes.placed[new_id] then changes.placed[new_id] = 0 end changes.placed[new_id] = changes.placed[new_id] + 1 + -- print("[overlay] placed above ", x, y, z) break -- Move on to the next column 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 end + if is_liquid then found_air = false end end if not placed_node then diff --git a/worldeditadditions/utils/node_identification.lua b/worldeditadditions/utils/node_identification.lua index 207cd4b..5375cb6 100644 --- a/worldeditadditions/utils/node_identification.lua +++ b/worldeditadditions/utils/node_identification.lua @@ -44,7 +44,7 @@ function worldeditadditions.is_liquidlike(id) if node_name == nil or not minetest.registered_nodes[node_name] then return false end 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 it's not none, then it has to be a liquid as the only other values are source and flowing