From 8065e3d8041b75f22021fe0539201e66d8bcb242 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 22 Apr 2024 18:37:14 +0200 Subject: [PATCH] Allow rotation with //mtschemplace fixes #153 --- ChatCommands.md | 5 +++-- worldedit_commands/schematics.lua | 21 ++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ChatCommands.md b/ChatCommands.md index 1d3b4e9..07082fb 100644 --- a/ChatCommands.md +++ b/ChatCommands.md @@ -428,11 +428,12 @@ Save the current WorldEdit region using the Minetest Schematic format to "(world //mtschemcreate some random filename //mtschemcreate huge_base -### `//mtschemplace ` +### `//mtschemplace [rotation]` Load nodes from "(world folder)/schems/``.mts" with position 1 of the current WorldEdit region as the origin. +Valid values for `[rotation]` are 0, 90, 180 and 270. - //mtschemplace some random filename + //mtschemplace a_tree 270 //mtschemplace huge_base ### `//mtschemprob start/finish/get` diff --git a/worldedit_commands/schematics.lua b/worldedit_commands/schematics.lua index dbf8b2f..1aae07e 100644 --- a/worldedit_commands/schematics.lua +++ b/worldedit_commands/schematics.lua @@ -209,23 +209,26 @@ worldedit.register_command("mtschemplace", { privs = {worldedit=true}, require_pos = 1, parse = function(param) - if param == "" then - return false + local found, _, filename, rotation = param:find("^(.+)%s+([012789]+)$") + if found == nil then + filename = param + elseif rotation ~= "0" and rotation ~= "90" and rotation ~= "180" and rotation ~= "270" then + return false, S("Invalid rotation: @1", rotation) end - if not check_filename(param) then - return false, S("Disallowed file name: @1", param) + if not check_filename(filename) then + return false, S("Disallowed file name: @1", filename) end - return true, param + return true, filename, rotation end, - func = function(name, param) + func = function(name, filename, rotation) local pos = worldedit.pos1[name] - local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts" - if minetest.place_schematic(pos, path) == nil then + local path = minetest.get_worldpath() .. "/schems/" .. filename .. ".mts" + if minetest.place_schematic(pos, path, rotation) == nil then return false, S("failed to place Minetest schematic") end return true, S("placed Minetest schematic @1 at @2", - param, minetest.pos_to_string(pos)) + filename, minetest.pos_to_string(pos)) end, })