diff --git a/.luacheckrc b/.luacheckrc index 3220320..8b250b8 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,5 +14,5 @@ read_globals = { "minetest", -- mods - "mapsync", "mtt" + "mapsync", "mtt", "blockexchange" } diff --git a/mod.conf b/mod.conf index 81bdeea..ebbcb45 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = pick_and_place description = Pick and place utility depends = wield_events -optional_depends = mapsync, mtt +optional_depends = mapsync, mtt, blockexchange min_minetest_version = 5.5.0 \ No newline at end of file diff --git a/place_tool.lua b/place_tool.lua index 2e0779c..82a457f 100644 --- a/place_tool.lua +++ b/place_tool.lua @@ -1,6 +1,7 @@ local FORMSPEC_NAME = "pick_and_place:place" local has_mapsync = minetest.get_modpath("mapsync") +local has_blockexchange = minetest.get_modpath("blockexchange") local function get_pos(meta, player) local size = minetest.string_to_pos(meta:get_string("size")) @@ -15,6 +16,16 @@ local function get_pos(meta, player) return pos1, pos2 end +-- notify supported mods of changes +local function notify_change(pos1, pos2) + if has_blockexchange then + blockexchange.mark_changed(pos1, pos2) + end + if has_mapsync then + mapsync.mark_changed(pos1, pos2) + end +end + minetest.register_tool("pick_and_place:place", { description = "Placement tool", inventory_image = "pick_and_place_plus.png^[colorize:#0000ff", @@ -34,12 +45,15 @@ minetest.register_tool("pick_and_place:place", { if controls.aux1 then -- removal pick_and_place.remove_area(pos1, pos2) + notify_change(pos1, pos2) else -- placement local schematic = meta:get_string("schematic") local success, msg = pick_and_place.deserialize(pos1, schematic) if not success then minetest.chat_send_player(playername, "Placement error: " .. msg) + else + notify_change(pos1, pos2) end end end, @@ -69,10 +83,6 @@ minetest.register_tool("pick_and_place:place", { -- build preview pick_and_place.show_preview(playername, "pick_and_place_plus.png", "#0000ff", pos1, pos2) end - - if has_mapsync then - mapsync.mark_changed(pos1, pos2) - end end, on_deselect = function(_, player) local playername = player:get_player_name()