Skip to content

Commit 8065e3d

Browse files
committed
Allow rotation with //mtschemplace
fixes #153
1 parent 60b6b20 commit 8065e3d

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

ChatCommands.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,12 @@ Save the current WorldEdit region using the Minetest Schematic format to "(world
428428
//mtschemcreate some random filename
429429
//mtschemcreate huge_base
430430

431-
### `//mtschemplace <file>`
431+
### `//mtschemplace <file> [rotation]`
432432

433433
Load nodes from "(world folder)/schems/`<file>`.mts" with position 1 of the current WorldEdit region as the origin.
434+
Valid values for `[rotation]` are 0, 90, 180 and 270.
434435

435-
//mtschemplace some random filename
436+
//mtschemplace a_tree 270
436437
//mtschemplace huge_base
437438

438439
### `//mtschemprob start/finish/get`

worldedit_commands/schematics.lua

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,26 @@ worldedit.register_command("mtschemplace", {
209209
privs = {worldedit=true},
210210
require_pos = 1,
211211
parse = function(param)
212-
if param == "" then
213-
return false
212+
local found, _, filename, rotation = param:find("^(.+)%s+([012789]+)$")
213+
if found == nil then
214+
filename = param
215+
elseif rotation ~= "0" and rotation ~= "90" and rotation ~= "180" and rotation ~= "270" then
216+
return false, S("Invalid rotation: @1", rotation)
214217
end
215-
if not check_filename(param) then
216-
return false, S("Disallowed file name: @1", param)
218+
if not check_filename(filename) then
219+
return false, S("Disallowed file name: @1", filename)
217220
end
218-
return true, param
221+
return true, filename, rotation
219222
end,
220-
func = function(name, param)
223+
func = function(name, filename, rotation)
221224
local pos = worldedit.pos1[name]
222225

223-
local path = minetest.get_worldpath() .. "/schems/" .. param .. ".mts"
224-
if minetest.place_schematic(pos, path) == nil then
226+
local path = minetest.get_worldpath() .. "/schems/" .. filename .. ".mts"
227+
if minetest.place_schematic(pos, path, rotation) == nil then
225228
return false, S("failed to place Minetest schematic")
226229
end
227230
return true, S("placed Minetest schematic @1 at @2",
228-
param, minetest.pos_to_string(pos))
231+
filename, minetest.pos_to_string(pos))
229232
end,
230233
})
231234

0 commit comments

Comments
 (0)