diff --git a/.luacheckrc b/.luacheckrc index 0e16316..8244bda 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -9,6 +9,7 @@ read_globals = { "core", "table.copy", "table.indexof", + "string.split", "minetest", "ItemStack", "barter", diff --git a/README.md b/README.md index 0722427..f9705a2 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ To make maintaining support easier, wrench only supports specific versions of mo - `technic` - https://github.com/mt-mods/technic OR https://github.com/minetest-mods/technic - `technic_chests` - https://github.com/mt-mods/technic - `technic_cnc` - https://github.com/mt-mods/technic +- `telemosaic` - https://github.com/mt-mods/telemosaic - `vacuum` - https://github.com/mt-mods/vacuum - `vessels` - https://github.com/minetest/minetest_game - `wine` - https://codeberg.org/tenplus1/wine diff --git a/init.lua b/init.lua index c48bb21..6c47e42 100644 --- a/init.lua +++ b/init.lua @@ -62,6 +62,7 @@ local mods = { "technic", "technic_chests", "technic_cnc", + "telemosaic", "vacuum", "vessels", "wine", diff --git a/nodes/telemosaic.lua b/nodes/telemosaic.lua new file mode 100644 index 0000000..b534bea --- /dev/null +++ b/nodes/telemosaic.lua @@ -0,0 +1,63 @@ + +local S = wrench.translator + +local function get_dest_string(meta) + local dest = meta:get("telemosaic:dest") + if dest and dest:find(":") then + -- Old version + local list = string.split(dest, ':') + local p = { + x = tonumber(list[1]), + y = tonumber(list[2]), + z = tonumber(list[3]) + } + if p.x and p.y and p.z then + return core.pos_to_string(p) + end + else + return dest + end +end + +local function save_old_pos(pos) + core.get_meta(pos):set_string("old_pos", core.pos_to_string(pos)) +end + +local function after_place(pos) + local meta = core.get_meta(pos) + local old_pos = meta:get("old_pos") + local dest = get_dest_string(meta) + if not old_pos or not dest then + return + end + local other_meta = core.get_meta(core.string_to_pos(dest)) + local other_dest = get_dest_string(other_meta) + if other_dest and old_pos == other_dest then + -- Update the connected telemosaic + other_meta:set_string("telemosaic:dest", core.pos_to_string(pos)) + end + meta:set_string("old_pos", "") +end + +local function description(pos, meta, node, player) + local suffix = node.name:match("_protected$") and "_protected" or "" + local name = core.registered_nodes["telemosaic:beacon_off"..suffix].description + local dest = get_dest_string(meta) or "" + return S("@1 with destination @2", name, dest) +end + +local def = { + metas = { + ["telemosaic:dest"] = wrench.META_TYPE_STRING, + channel = core.get_modpath("digilines") and wrench.META_TYPE_STRING or nil, + old_pos = wrench.META_TYPE_STRING, -- Temporary value used to update connected beacons + }, + description = description, + after_place = after_place, + can_pickup = save_old_pos, +} + +for _,state in ipairs({"", "_disabled", "_err"}) do + wrench.register_node("telemosaic:beacon"..state, def) + wrench.register_node("telemosaic:beacon"..state.."_protected", def) +end