Start implementing //hollow, but it isn't finished yet

This commit is contained in:
Starbeamrainbowlabs 2021-01-31 18:03:07 +00:00
parent f19a897a9e
commit 0be205dae7
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
4 changed files with 94 additions and 0 deletions

@ -29,6 +29,7 @@ dofile(worldeditadditions.modpath.."/lib/walls.lua")
dofile(worldeditadditions.modpath.."/lib/replacemix.lua")
dofile(worldeditadditions.modpath.."/lib/maze2d.lua")
dofile(worldeditadditions.modpath.."/lib/maze3d.lua")
dofile(worldeditadditions.modpath.."/lib/hollow.lua")
dofile(worldeditadditions.modpath.."/lib/conv/conv.lua")
dofile(worldeditadditions.modpath.."/lib/erode/erode.lua")

@ -0,0 +1,44 @@
-- ██ ██ ██████ ██ ██ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██ ██ ██ ██ █ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
-- ██ ██ ██████ ███████ ███████ ██████ ███ ███
--- Hollows out the defined region, leaving a given number of nodes on the
-- outside.
-- (think of the bits of the outermost parts of the defined region as the
-- 'walls' to a box)
function worldeditadditions.hollow(pos1, pos2, wall_thickness)
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()
local node_id_ignore = minetest.get_content_id("air")
-- minetest.log("action", "pos1: " .. worldeditadditions.vector.tostring(pos1))
-- minetest.log("action", "pos2: " .. worldeditadditions.vector.tostring(pos2))
local changes = { replaced = 0 }
for z = pos2.z - wall_thickness, pos1.z + wall_thickness, -1 do
for y = pos2.y - wall_thickness, pos1.y + wall_thickness, -1 do
for x = pos2.x - wall_thickness, pos1.x + wall_thickness, -1 do
local i = area:index(x, y, z)
local is_air = worldeditadditions.is_airlike(data[i])
local is_ignore = data[i] == node_id_ignore
if not is_ignore and not is_air then
data[i] = node_id_air
changes.replaced = changes.replaced + 1
end
end
end
end
-- Save the modified nodes back to disk & return
worldedit.manip_helpers.finish(manip, data)
return true, changes
end

@ -0,0 +1,48 @@
-- ██ ██ ██████ ██ ██ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ███████ ██ ██ ██ ██ ██ ██ ██ █ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██
-- ██ ██ ██████ ███████ ███████ ██████ ███ ███
worldedit.register_command("hollow", {
params = "[<wall_thickness>]",
description = "Replaces nodes inside the defined region with air, but leaving a given number of nodes near the outermost edges alone. In other words, it makes the defined region hollow leaving walls of a given thickness (default: 1)",
privs = { worldedit = true },
require_pos = 2,
parse = function(params_text)
if not params_text or #params_text == 0 then params_text = "1" end
local wall_thickness = tonumber(params_text)
if not wall_thickness then
return false, "Error: Unrecognised number '"..params_text.."'."
end
return success, wall_thickness
end,
nodes_needed = function(name, wall_thickness)
-- //overlay only modifies up to 1 node per column in the selected region
local pos1, pos2 = worldedit.sort_pos(worldedit.pos1[name], worldedit.pos2[name])
return worldedit.volume(
{
x = pos2.x - wall_thickness,
y = pos2.y - wall_thickness,
z = pos2.z - wall_thickness
},
{
x = pos2.x + wall_thickness,
y = pos2.y + wall_thickness,
z = pos2.z + wall_thickness
}
)
end,
func = function(name, wall_thickness)
local start_time = worldeditadditions.get_ms_time()
local success, changes = worldeditadditions.hollow(worldedit.pos1[name], worldedit.pos2[name], wall_thickness)
local time_taken = worldeditadditions.get_ms_time() - start_time
if not success then return success, changes end
minetest.log("action", name .. " used //hollow at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. changes.replaced .. " nodes in " .. time_taken .. "s")
return true, changes.replaced .. " nodes replaced in " .. worldeditadditions.human_time(time_taken)
end
})

@ -31,6 +31,7 @@ dofile(we_c.modpath.."/commands/maze.lua")
dofile(we_c.modpath.."/commands/replacemix.lua")
dofile(we_c.modpath.."/commands/convolve.lua")
dofile(we_c.modpath.."/commands/erode.lua")
dofile(we_c.modpath.."/commands/hollow.lua")
dofile(we_c.modpath.."/commands/count.lua")
dofile(we_c.modpath.."/commands/saplingaliases.lua")