From 952d7a96f8e8435942a59b112ae7d812749350f5 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 11 May 2020 21:44:18 +0100 Subject: [PATCH] Add //walls command - fixes #12 --- README.md | 10 +++++ worldeditadditions/init.lua | 2 + worldeditadditions/walls.lua | 37 +++++++++++++++++++ .../commands/walls.lua | 34 +++++++++++++++++ worldeditadditions_commands/init.lua | 2 + 5 files changed, 85 insertions(+) create mode 100644 worldeditadditions/walls.lua create mode 100644 worldeditadditions_commands/commands/walls.lua diff --git a/README.md b/README.md index 85d83bc..2bd0d42 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ If you can dream of it, it probably belongs here! - [`//maze [ [ []]]`](#maze-replace_node-seed) - [`//maze3d [ [ [ []]]]`](#maze3d-replace_node-seed) - [`//bonemeal [ []]`](#bonemeal-strength-chance) + - [`//walls `](#walls-replace_node) - [`//multi .....`](#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 ` +Creates vertical walls of `` around the inside edges of the defined region. + +``` +//walls dirt +//walls stone +//walls goldblock +``` + ### `//multi .....` Executes multi chat commands in sequence. Intended for _WorldEdit_ commands, but does work with others too. Don't forget a space between commands! diff --git a/worldeditadditions/init.lua b/worldeditadditions/init.lua index 15eadfe..7623890 100644 --- a/worldeditadditions/init.lua +++ b/worldeditadditions/init.lua @@ -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") diff --git a/worldeditadditions/walls.lua b/worldeditadditions/walls.lua new file mode 100644 index 0000000..79c2a52 --- /dev/null +++ b/worldeditadditions/walls.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 diff --git a/worldeditadditions_commands/commands/walls.lua b/worldeditadditions_commands/commands/walls.lua new file mode 100644 index 0000000..8ba0f79 --- /dev/null +++ b/worldeditadditions_commands/commands/walls.lua @@ -0,0 +1,34 @@ +-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████ +-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ +-- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██ +worldedit.register_command("walls", { + params = "", + description = "Creates vertical walls of 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 +}) diff --git a/worldeditadditions_commands/init.lua b/worldeditadditions_commands/init.lua index 43e37a5..986b133 100644 --- a/worldeditadditions_commands/init.lua +++ b/worldeditadditions_commands/init.lua @@ -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")