From 68f7bcc72832ce753a3659f44dd26fbc4a5c066a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 9 Sep 2019 01:07:17 +0200 Subject: [PATCH] Warn when "misaligned" schematics are created 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 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 9cd5eeb..d11eb9d 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -1097,6 +1097,23 @@ minetest.register_chatcommand("/restore", { end), }) +local function detect_misaligned_schematic(name, pos1, pos2) + pos1, pos2 = worldedit.sort_pos(pos1, pos2) + -- Check that allocate/save can position the schematic correctly + -- The expected behaviour is that the (0,0,0) corner of the schematic stays + -- sat pos1, this only works when the minimum position is actually present + -- in the schematic. + local node = minetest.get_node(pos1) + local have_node_at_origin = node.name ~= "air" and node.name ~= "ignore" + if not have_node_at_origin then + worldedit.player_notify(name, + "Warning: The schematic contains excessive free space and WILL be ".. + "misaligned when allocated or loaded. To avoid this, shrink your ".. + "area to cover exactly the nodes to be saved." + ) + end +end + minetest.register_chatcommand("/save", { params = "", description = "Save the current WorldEdit region to \"(world folder)/schems/.we\"", @@ -1112,6 +1129,7 @@ minetest.register_chatcommand("/save", { end local result, count = worldedit.serialize(worldedit.pos1[name], worldedit.pos2[name]) + detect_misaligned_schematic(name, worldedit.pos1[name], worldedit.pos2[name]) local path = minetest.get_worldpath() .. "/schems" -- Create directory if it does not already exist -- 2.44.0