//walls: add optional thickness argument

This commit is contained in:
Starbeamrainbowlabs 2021-08-05 02:00:38 +01:00
parent c2702a8fde
commit f30ddbae3b
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 42 additions and 14 deletions

View file

@ -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)

View file

@ -254,13 +254,15 @@ Since WorldEditAdditions v1.13, a list of node names is also optionally supporte
//bonemeal 4 50 ethereal:grove_dirt
```
## `//walls <replace_node>`
Creates vertical walls of `<replace_node>` around the inside edges of the defined region.
## `//walls <replace_node> [<thickness=1>]`
Creates vertical walls of `<replace_node>` 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 <axis> <scale_factor> | <factor_x> [<factor_y> <factor_z> [<anchor_x> <anchor_y> <anchor_z>`

View file

@ -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

View file

@ -4,16 +4,30 @@
-- ██ ███ ██ ██ ██ ██ ██ ██
-- ███ ███ ██ ██ ███████ ███████ ███████
worldedit.register_command("walls", {
params = "<replace_node>",
description = "Creates vertical walls of <replace_node> around the inside edges of the defined region.",
params = "<replace_node> [<thickness=1>]",
description = "Creates vertical walls of <replace_node> 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")