From f30ddbae3bd2f9932235fa6d339b623126278625 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 5 Aug 2021 02:00:38 +0100 Subject: [PATCH] //walls: add optional thickness argument --- CHANGELOG.md | 3 +- Chat-Command-Reference.md | 6 ++-- worldeditadditions/lib/walls.lua | 16 +++++++--- .../commands/walls.lua | 31 ++++++++++++++----- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5307ca..1bd2957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ Note to self: See the bottom of this file for the release template text. - Use [luacheck](https://github.com/mpeterv/luacheck) to find and fix a large number of bugs and other issues - Multiple commands: Allow using quotes (`"thing"`, `'thing'`) to quote values when splitting - `//layers`: Add optional slope constraint (inspired by [WorldPainter](https://worldpainter.net/)) - - `//bonemeal`: Add optional node list contraint + - `//bonemeal`: Add optional node list constraint + - `//walls`: Add optional thickness argument ## v1.12: The selection tools update (26th June 2021) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 4a57f26..7cebe35 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -254,13 +254,15 @@ Since WorldEditAdditions v1.13, a list of node names is also optionally supporte //bonemeal 4 50 ethereal:grove_dirt ``` -## `//walls ` -Creates vertical walls of `` around the inside edges of the defined region. +## `//walls []` +Creates vertical walls of `` around the inside edges of the defined region, optionally specifying the thickness thereof. ```weacmd //walls dirt //walls stone //walls goldblock +//walls sandstone 2 +//walls glass 4 ``` ## `//scale | [ [ ` diff --git a/worldeditadditions/lib/walls.lua b/worldeditadditions/lib/walls.lua index 79c2a52..4de8f34 100644 --- a/worldeditadditions/lib/walls.lua +++ b/worldeditadditions/lib/walls.lua @@ -1,5 +1,3 @@ ---- Creates vertical walls on the inside of the defined region. --- @module worldeditadditions.walls -- ██ ██ █████ ██ ██ ███████ -- ██ ██ ██ ██ ██ ██ ██ @@ -7,8 +5,15 @@ -- ██ ███ ██ ██ ██ ██ ██ ██ -- ███ ███ ██ ██ ███████ ███████ ███████ -function worldeditadditions.walls(pos1, pos2, node_name) +--- Creates vertical walls on the inside of the defined region. +-- @apipath worldeditadditions.walls +-- @param pos1 Vector Position 1 of the defined region, +-- @param pos2 Vector Position 2 of the defined region. +-- @param node_name string The name of the node to use to create the walls with. +-- @param thickness number? The thickness of the walls to create. Default: 1 +function worldeditadditions.walls(pos1, pos2, node_name, thickness) pos1, pos2 = worldedit.sort_pos(pos1, pos2) + if not thickness then thickness = 1 end -- pos2 will always have the highest co-ordinates now -- Fetch the nodes in the specified area @@ -22,7 +27,10 @@ function worldeditadditions.walls(pos1, pos2, node_name) for z = pos2.z, pos1.z, -1 do for y = pos2.y, pos1.y, -1 do for x = pos2.x, pos1.x, -1 do - if x == pos1.x or x == pos2.x or z == pos1.z or z == pos2.z then + if math.abs(x - pos1.x) < thickness + or math.abs(x - pos2.x) < thickness + or math.abs(z - pos1.z) < thickness + or math.abs(z - pos2.z) < thickness then data[area:index(x, y, z)] = node_id count_replaced = count_replaced + 1 end diff --git a/worldeditadditions_commands/commands/walls.lua b/worldeditadditions_commands/commands/walls.lua index 1ca777e..c506f32 100644 --- a/worldeditadditions_commands/commands/walls.lua +++ b/worldeditadditions_commands/commands/walls.lua @@ -4,16 +4,30 @@ -- ██ ███ ██ ██ ██ ██ ██ ██ -- ███ ███ ██ ██ ███████ ███████ ███████ worldedit.register_command("walls", { - params = "", - description = "Creates vertical walls of around the inside edges of the defined region.", + params = " []", + description = "Creates vertical walls of around the inside edges of the defined region. Optionally specifies a thickness for the walls to be created (defaults to 1)", privs = { worldedit = true }, require_pos = 2, parse = function(params_text) - local target_node = worldedit.normalize_nodename(params_text) + local parts = worldeditadditions.split_shell(params_text) + + local target_node + local thickness = 1 + + local target_node_raw = table.remove(parts, 1) + target_node = worldedit.normalize_nodename(target_node_raw) if not target_node then - return false, "Error: Invalid node name" + return false, "Error: Invalid node name '"..target_node_raw.."'." end - return true, target_node + + if #parts > 0 then + local thickness_raw = table.remove(parts, 1) + thickness = tonumber(thickness_raw) + if not thickness then return false, "Error: Invalid thickness value '"..thickness_raw.."'. The thickness value must be a positive integer greater than or equal to 0." end + if thickness < 1 then return false, "Error: That thickness value '"..thickness_raw.."' is out of range. The thickness value must be a positive integer greater than or equal to 0." end + end + + return true, target_node, math.floor(thickness) end, nodes_needed = function(name) -- //overlay only modifies up to 1 node per column in the selected region @@ -23,9 +37,12 @@ worldedit.register_command("walls", { return worldedit.volume(pos1, pos2) - worldedit.volume(pos1, pos3) end, - func = function(name, target_node) + func = function(name, target_node, thickness) local start_time = worldeditadditions.get_ms_time() - local success, replaced = worldeditadditions.walls(worldedit.pos1[name], worldedit.pos2[name], target_node) + local success, replaced = worldeditadditions.walls( + worldedit.pos1[name], worldedit.pos2[name], + target_node, thickness + ) local time_taken = worldeditadditions.get_ms_time() - start_time minetest.log("action", name .. " used //walls from "..worldeditadditions.vector.tostring(worldedit.pos1[name]).." to "..worldeditadditions.vector.tostring(worldedit.pos1[name])..", replacing " .. replaced .. " nodes in " .. time_taken .. "s")