Allow rotation with //mtschemplace

fixes #153
This commit is contained in:
sfan5 2024-04-22 18:37:14 +02:00
parent 60b6b205ad
commit 8065e3d804
2 changed files with 15 additions and 11 deletions

@ -428,11 +428,12 @@ Save the current WorldEdit region using the Minetest Schematic format to "(world
//mtschemcreate some random filename
//mtschemcreate huge_base
### `//mtschemplace <file>`
### `//mtschemplace <file> [rotation]`
Load nodes from "(world folder)/schems/`<file>`.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`

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