]> git.lizzy.rs Git - worldedit.git/commitdiff
Warn when "misaligned" schematics are created
authorsfan5 <sfan5@live.de>
Sun, 8 Sep 2019 23:07:17 +0000 (01:07 +0200)
committersfan5 <sfan5@live.de>
Sun, 8 Sep 2019 23:07:17 +0000 (01:07 +0200)
The underlying issue is the size detection worldedit.allocate does
and can't be fixed or worked around in a simple way.

worldedit_commands/init.lua

index 9cd5eeb2bf9467ad5d3aec2abf44c4efb618f9db..d11eb9dca060f9ddaa4d6592ce5673d39d168ab5 100644 (file)
@@ -1097,6 +1097,23 @@ minetest.register_chatcommand("/restore", {
        end),\r
 })\r
 \r
+local function detect_misaligned_schematic(name, pos1, pos2)\r
+       pos1, pos2 = worldedit.sort_pos(pos1, pos2)\r
+       -- Check that allocate/save can position the schematic correctly\r
+       -- The expected behaviour is that the (0,0,0) corner of the schematic stays\r
+       -- sat pos1, this only works when the minimum position is actually present\r
+       -- in the schematic.\r
+       local node = minetest.get_node(pos1)\r
+       local have_node_at_origin = node.name ~= "air" and node.name ~= "ignore"\r
+       if not have_node_at_origin then\r
+               worldedit.player_notify(name,\r
+                       "Warning: The schematic contains excessive free space and WILL be "..\r
+                       "misaligned when allocated or loaded. To avoid this, shrink your "..\r
+                       "area to cover exactly the nodes to be saved."\r
+               )\r
+       end\r
+end\r
+\r
 minetest.register_chatcommand("/save", {\r
        params = "<file>",\r
        description = "Save the current WorldEdit region to \"(world folder)/schems/<file>.we\"",\r
@@ -1112,6 +1129,7 @@ minetest.register_chatcommand("/save", {
                end\r
                local result, count = worldedit.serialize(worldedit.pos1[name],\r
                                worldedit.pos2[name])\r
+               detect_misaligned_schematic(name, worldedit.pos1[name], worldedit.pos2[name])\r
 \r
                local path = minetest.get_worldpath() .. "/schems"\r
                -- Create directory if it does not already exist\r