From 98b3ae87ea757619bbd1fb92e54204148c13369b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 4 Apr 2021 22:22:54 +0200 Subject: [PATCH 1/2] Add -c switch to /placeschem to clean area first --- init.lua | 25 +++++++++++++++++++++---- locale/schemedit.de.tr | 4 ++-- locale/template.txt | 4 ++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/init.lua b/init.lua index 084c073..ec4d702 100644 --- a/init.lua +++ b/init.lua @@ -1299,11 +1299,16 @@ end -- [chatcommand] Place schematic minetest.register_chatcommand("placeschem", { - description = S("Place schematic at the position specified or the current player position (loaded from @1)", export_path_trunc), + description = S("Place schematic at the position specified or the current player position (loaded from @1). “-c” will clear the area first", export_path_trunc), privs = {server = true}, - params = S("[.mts] [ ]"), + params = S("[.mts] [-c] [ ]"), func = function(name, param) - local schem, p = string.match(param, "^([^ ]+) *(.*)$") + local schem, clear, p = string.match(param, "^([^ ]+) (%-c) *(.*)$") + if not schem then + schem, p = string.match(param, "^([^ ]+) *(.*)$") + end + clear = clear == "-c" + local pos = minetest.string_to_pos(p) if not schem then @@ -1323,10 +1328,22 @@ minetest.register_chatcommand("placeschem", { -- files when we reload. minetest.read_schematic circumvents that. local schematic = minetest.read_schematic(schem_path, {}) if schematic then + if clear then + local posses = {} + for z=pos.z, pos.z+schematic.size.z-1 do + for y=pos.y, pos.y+schematic.size.y-1 do + for x=pos.x, pos.x+schematic.size.x-1 do + table.insert(posses, {x=x,y=y,z=z}) + end + end + end + minetest.bulk_set_node(posses, {name="air"}) + end success = minetest.place_schematic(pos, schematic, "random", nil, false) end else - -- Legacy support for Minetest versions that do not have minetest.read_schematic + -- Legacy support for Minetest versions that do not have minetest.read_schematic. + -- Note: "-c" is ignored here. success = minetest.place_schematic(schem_path, schematic, "random", nil, false) end diff --git a/locale/schemedit.de.tr b/locale/schemedit.de.tr index 6e36483..97c99cb 100644 --- a/locale/schemedit.de.tr +++ b/locale/schemedit.de.tr @@ -71,8 +71,8 @@ The node HUD is not updated automatically and may be outdated. The node HUD only Schematic Void=Schematic-Lücke This is an utility block used in the creation of schematic files. It should be used together with a schematic creator. When saving a schematic, all nodes with a schematic void will be left unchanged when the schematic is placed again. Technically, this is equivalent to a block with the node probability set to 0.=Dies ist ein Hilfsblock, der bei der Erstellung von Schematic-Dateien benutzt wird. Er sollte zusammen mit einem Schematic-Macher benutzt werden. Wenn ein Schematic gespeichert wird, werden alle Nodes mit einer Schematic-Lücke unverändert gelassen, wenn das Schematic erneut platziert wird. Technisch gesehen ist dieses Verhalten identisch mit einem Block, der eine Node-Wahrscheinlichkeit von 0 hat. Just place the schematic void like any other block and use the schematic creator to save a portion of the world.=Platzieren Sie einfach die Schematic-Lücke wie jeden anderen Block und benutzen Sie den Schematic-Macher, um einen Teil der Welt zu speichern. -Place schematic at the position specified or the current player position (loaded from @1)=Schematic an der angegebenen Position oder der aktuellen Spielerposition platzieren (geladen von @1) -[.mts] [ ]=[.mts] [ ] +Place schematic at the position specified or the current player position (loaded from @1). “-c” will clear the area first=Schematic an der angegebenen Position oder der aktuellen Spielerposition platzieren (geladen von @1). Mit „-c“ wird das Gebiet zuerst geleert +[.mts] [-c] [ ]=[.mts] [-c] [ ] No schematic file specified.=Keinen Schematic-Namen angegeben. Schematic file could not be loaded!=Schematic-Datei konnte nicht geladen werden! Convert .mts schematic file to .lua file (loaded from @1)=„.mts“-Schematicdatei zu „.lua“-Datei konvertieren (geladen von @1) diff --git a/locale/template.txt b/locale/template.txt index f79a794..d26bed0 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -71,8 +71,8 @@ The node HUD is not updated automatically and may be outdated. The node HUD only Schematic Void= This is an utility block used in the creation of schematic files. It should be used together with a schematic creator. When saving a schematic, all nodes with a schematic void will be left unchanged when the schematic is placed again. Technically, this is equivalent to a block with the node probability set to 0.= Just place the schematic void like any other block and use the schematic creator to save a portion of the world.= -Place schematic at the position specified or the current player position (loaded from @1)= -[.mts] [ ]= +Place schematic at the position specified or the current player position (loaded from @1). “-c” will clear the area first= +[.mts] [-c] [ ]= No schematic file specified.= Schematic file could not be loaded!= Convert .mts schematic file to .lua file (loaded from @1)= From 3b9f1b867b6a427d587317da9c9e8a019f6cbb71 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 5 Apr 2021 00:57:40 +0200 Subject: [PATCH 2/2] Increase area cleaning size to full XZ extent --- init.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index ec4d702..2253cdb 100644 --- a/init.lua +++ b/init.lua @@ -1329,10 +1329,13 @@ minetest.register_chatcommand("placeschem", { local schematic = minetest.read_schematic(schem_path, {}) if schematic then if clear then + -- Clear same size for X and Z because + -- because schematic is randomly rotated + local max_xz = math.max(schematic.size.x, schematic.size.z) local posses = {} - for z=pos.z, pos.z+schematic.size.z-1 do + for z=pos.z, pos.z+max_xz-1 do for y=pos.y, pos.y+schematic.size.y-1 do - for x=pos.x, pos.x+schematic.size.x-1 do + for x=pos.x, pos.x+max_xz-1 do table.insert(posses, {x=x,y=y,z=z}) end end