Add //walls command - fixes #12

This commit is contained in:
Starbeamrainbowlabs 2020-05-11 21:44:18 +01:00
parent 32eb0ffc79
commit 952d7a96f8
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
5 changed files with 85 additions and 0 deletions

@ -17,6 +17,7 @@ If you can dream of it, it probably belongs here!
- [`//maze <replace_node> [<path_length> [<path_width> [<seed>]]]`](#maze-replace_node-seed)
- [`//maze3d <replace_node> [<path_length> [<path_width> [<path_depth> [<seed>]]]]`](#maze3d-replace_node-seed)
- [`//bonemeal [<strength> [<chance>]]`](#bonemeal-strength-chance)
- [`//walls <replace_node>`](#walls-replace_node)
- [`//multi <command_a> <command_b> .....`](#multi-command_a-command_b-command_c-)
- [`//y`](#y)
- [`//n`](#n)
@ -130,6 +131,15 @@ For example, a chance number of 2 would mean a 50% chance that any given eligibl
//bonemeal 2 15
```
### `//walls <replace_node>`
Creates vertical walls of `<replace_node>` around the inside edges of the defined region.
```
//walls dirt
//walls stone
//walls goldblock
```
### `//multi <command_a> <command_b> <command_c> .....`
Executes multi chat commands in sequence. Intended for _WorldEdit_ commands, but does work with others too. Don't forget a space between commands!

@ -15,4 +15,6 @@ dofile(minetest.get_modpath("worldeditadditions") .. "/torus.lua")
dofile(minetest.get_modpath("worldeditadditions") .. "/maze2d.lua")
dofile(minetest.get_modpath("worldeditadditions") .. "/maze3d.lua")
dofile(minetest.get_modpath("worldeditadditions") .. "/walls.lua")
dofile(minetest.get_modpath("worldeditadditions") .. "/bonemeal.lua")

@ -0,0 +1,37 @@
--- Creates vertical walls on the inside of the defined region.
-- @module worldeditadditions.walls
-- ██ ██ █████ ██ ██ ███████
-- ██ ██ ██ ██ ██ ██ ██
-- ██ █ ██ ███████ ██ ██ ███████
-- ██ ███ ██ ██ ██ ██ ██ ██
-- ███ ███ ██ ██ ███████ ███████ ███████
function worldeditadditions.walls(pos1, pos2, node_name)
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 = minetest.get_content_id(node_name)
-- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array)
local count_replaced = 0
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
data[area:index(x, y, z)] = node_id
count_replaced = count_replaced + 1
end
end
end
end
-- Save the modified nodes back to disk & return
worldedit.manip_helpers.finish(manip, data)
return true, count_replaced
end

@ -0,0 +1,34 @@
-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██
worldedit.register_command("walls", {
params = "<replace_node>",
description = "Creates vertical walls of <replace_node> around the inside edges of the defined region.",
privs = { worldedit = true },
require_pos = 2,
parse = function(params_text)
local target_node = worldedit.normalize_nodename(params_text)
if not target_node then
return false, "Error: Invalid node name"
end
return true, target_node
end,
nodes_needed = function(name)
-- //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])
local pos3 = { x = pos2.x - 2, z = pos2.z - 2, y = pos2.y }
return worldedit.volume(pos1, pos2) - worldedit.volume(pos1, pos3)
end,
func = function(name, target_node)
local start_time = os.clock()
local success, replaced = worldeditadditions.walls(worldedit.pos1[name], worldedit.pos2[name], target_node)
local time_taken = os.clock() - 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")
return true, replaced .. " nodes replaced in " .. time_taken .. "s"
end
})

@ -26,6 +26,8 @@ dofile(we_c.modpath.."/commands/ellipsoid.lua")
dofile(we_c.modpath.."/commands/torus.lua")
dofile(we_c.modpath.."/commands/maze.lua")
dofile(we_c.modpath.."/commands/walls.lua")
-- Don't registry the //bonemeal command if the bonemeal mod isn't present
if minetest.get_modpath("bonemeal") then
dofile(we_c.modpath.."/commands/bonemeal.lua")