blockexchange change notification

This commit is contained in:
BuckarooBanzay 2024-02-29 13:26:53 +01:00
parent 9cd093046d
commit cf7442ad2e
3 changed files with 16 additions and 6 deletions

View File

@ -14,5 +14,5 @@ read_globals = {
"minetest",
-- mods
"mapsync", "mtt"
"mapsync", "mtt", "blockexchange"
}

View File

@ -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

View File

@ -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()