2014-10-30 03:47:08 +01:00
|
|
|
--- Functions for visibly hiding nodes
|
|
|
|
-- @module worldedit.visualization
|
2012-10-14 03:45:50 +02:00
|
|
|
|
|
|
|
minetest.register_node("worldedit:placeholder", {
|
|
|
|
drawtype = "airlike",
|
|
|
|
paramtype = "light",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
diggable = false,
|
2019-07-17 01:22:12 +02:00
|
|
|
pointable = false,
|
2014-10-30 03:47:08 +01:00
|
|
|
walkable = false,
|
2012-10-14 03:45:50 +02:00
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
})
|
|
|
|
|
2014-10-30 03:47:08 +01:00
|
|
|
--- Hides all nodes in a region defined by positions `pos1` and `pos2` by
|
|
|
|
-- non-destructively replacing them with invisible nodes.
|
|
|
|
-- @return The number of nodes hidden.
|
|
|
|
function worldedit.hide(pos1, pos2)
|
|
|
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
|
|
|
|
|
|
|
worldedit.keep_loaded(pos1, pos2)
|
2013-07-21 22:54:25 +02:00
|
|
|
|
2023-06-09 14:28:29 +02:00
|
|
|
local pos = vector.new(pos1.x, 0, 0)
|
2014-10-30 03:47:08 +01:00
|
|
|
local get_node, get_meta, swap_node = minetest.get_node,
|
|
|
|
minetest.get_meta, minetest.swap_node
|
2012-10-14 03:45:50 +02:00
|
|
|
while pos.x <= pos2.x do
|
|
|
|
pos.y = pos1.y
|
|
|
|
while pos.y <= pos2.y do
|
|
|
|
pos.z = pos1.z
|
|
|
|
while pos.z <= pos2.z do
|
2013-06-23 18:46:59 +02:00
|
|
|
local node = get_node(pos)
|
2014-10-30 03:47:08 +01:00
|
|
|
if node.name ~= "air" and node.name ~= "worldedit:placeholder" then
|
|
|
|
-- Save the node's original name
|
|
|
|
get_meta(pos):set_string("worldedit_placeholder", node.name)
|
|
|
|
-- Swap in placeholder node
|
|
|
|
node.name = "worldedit:placeholder"
|
|
|
|
swap_node(pos, node)
|
2013-07-29 00:15:46 +02:00
|
|
|
end
|
2012-10-14 03:45:50 +02:00
|
|
|
pos.z = pos.z + 1
|
|
|
|
end
|
|
|
|
pos.y = pos.y + 1
|
|
|
|
end
|
|
|
|
pos.x = pos.x + 1
|
|
|
|
end
|
|
|
|
return worldedit.volume(pos1, pos2)
|
|
|
|
end
|
|
|
|
|
2014-10-30 03:47:08 +01:00
|
|
|
--- Suppresses all instances of `node_name` in a region defined by positions
|
|
|
|
-- `pos1` and `pos2` by non-destructively replacing them with invisible nodes.
|
|
|
|
-- @return The number of nodes suppressed.
|
|
|
|
function worldedit.suppress(pos1, pos2, node_name)
|
|
|
|
-- Ignore placeholder supression
|
|
|
|
if node_name == "worldedit:placeholder" then
|
2013-07-29 00:15:46 +02:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2014-10-30 03:47:08 +01:00
|
|
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
2013-07-21 22:54:25 +02:00
|
|
|
|
2014-10-30 03:47:08 +01:00
|
|
|
worldedit.keep_loaded(pos1, pos2)
|
|
|
|
|
|
|
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, node_name)
|
|
|
|
local get_node, get_meta, swap_node = minetest.get_node,
|
|
|
|
minetest.get_meta, minetest.swap_node
|
2013-06-23 05:08:51 +02:00
|
|
|
for _, pos in ipairs(nodes) do
|
2013-06-23 18:46:59 +02:00
|
|
|
local node = get_node(pos)
|
2014-10-30 03:47:08 +01:00
|
|
|
-- Save the node's original name
|
|
|
|
get_meta(pos):set_string("worldedit_placeholder", node.name)
|
|
|
|
-- Swap in placeholder node
|
|
|
|
node.name = "worldedit:placeholder"
|
|
|
|
swap_node(pos, node)
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
2013-06-23 05:08:51 +02:00
|
|
|
return #nodes
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
|
2014-10-30 03:47:08 +01:00
|
|
|
--- Highlights all instances of `node_name` in a region defined by positions
|
|
|
|
-- `pos1` and `pos2` by non-destructively hiding all other nodes.
|
|
|
|
-- @return The number of nodes found.
|
|
|
|
function worldedit.highlight(pos1, pos2, node_name)
|
|
|
|
pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
|
|
|
|
|
|
|
worldedit.keep_loaded(pos1, pos2)
|
2013-07-21 22:54:25 +02:00
|
|
|
|
2023-06-09 14:28:29 +02:00
|
|
|
local pos = vector.new(pos1.x, 0, 0)
|
2014-10-30 03:47:08 +01:00
|
|
|
local get_node, get_meta, swap_node = minetest.get_node,
|
|
|
|
minetest.get_meta, minetest.swap_node
|
2012-10-14 03:45:50 +02:00
|
|
|
local count = 0
|
2013-06-23 18:46:59 +02:00
|
|
|
while pos.x <= pos2.x do
|
2012-10-14 03:45:50 +02:00
|
|
|
pos.y = pos1.y
|
|
|
|
while pos.y <= pos2.y do
|
|
|
|
pos.z = pos1.z
|
|
|
|
while pos.z <= pos2.z do
|
2013-06-23 18:46:59 +02:00
|
|
|
local node = get_node(pos)
|
2014-10-30 03:47:08 +01:00
|
|
|
if node.name == node_name then -- Node found
|
2012-10-14 03:45:50 +02:00
|
|
|
count = count + 1
|
2014-10-30 03:47:08 +01:00
|
|
|
elseif node.name ~= "worldedit:placeholder" then -- Hide other nodes
|
|
|
|
-- Save the node's original name
|
|
|
|
get_meta(pos):set_string("worldedit_placeholder", node.name)
|
|
|
|
-- Swap in placeholder node
|
|
|
|
node.name = "worldedit:placeholder"
|
|
|
|
swap_node(pos, node)
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
|
|
|
pos.z = pos.z + 1
|
|
|
|
end
|
|
|
|
pos.y = pos.y + 1
|
|
|
|
end
|
|
|
|
pos.x = pos.x + 1
|
|
|
|
end
|
|
|
|
return count
|
|
|
|
end
|
|
|
|
|
2014-10-30 03:47:08 +01:00
|
|
|
-- Restores all nodes hidden with WorldEdit functions in a region defined
|
|
|
|
-- by positions `pos1` and `pos2`.
|
|
|
|
-- @return The number of nodes restored.
|
|
|
|
function worldedit.restore(pos1, pos2)
|
2012-10-14 03:45:50 +02:00
|
|
|
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
|
2014-10-30 03:47:08 +01:00
|
|
|
|
|
|
|
worldedit.keep_loaded(pos1, pos2)
|
|
|
|
|
2013-06-23 18:46:59 +02:00
|
|
|
local nodes = minetest.find_nodes_in_area(pos1, pos2, "worldedit:placeholder")
|
2014-10-30 03:47:08 +01:00
|
|
|
local get_node, get_meta, swap_node = minetest.get_node,
|
|
|
|
minetest.get_meta, minetest.swap_node
|
2013-06-23 05:08:51 +02:00
|
|
|
for _, pos in ipairs(nodes) do
|
2013-07-29 00:15:46 +02:00
|
|
|
local node = get_node(pos)
|
2014-10-30 03:47:08 +01:00
|
|
|
local meta = get_meta(pos)
|
|
|
|
local data = meta:to_table()
|
|
|
|
node.name = data.fields.worldedit_placeholder
|
|
|
|
data.fields.worldedit_placeholder = nil
|
|
|
|
meta:from_table(data)
|
|
|
|
swap_node(pos, node)
|
2012-10-14 03:45:50 +02:00
|
|
|
end
|
2013-06-23 05:08:51 +02:00
|
|
|
return #nodes
|
2013-04-28 19:08:09 +02:00
|
|
|
end
|
2014-10-30 03:47:08 +01:00
|
|
|
|