From 2be2eea4d83084d8c23a8bb7608cc3afc330a310 Mon Sep 17 00:00:00 2001 From: theFox6 Date: Sun, 15 Oct 2023 12:00:39 +0200 Subject: [PATCH] fix old networks with lbm --- modules/network/ctrl.lua | 37 ++++++++++++++++++++++++++++++++++++- modules/network/network.lua | 5 ----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/modules/network/ctrl.lua b/modules/network/ctrl.lua index e055b7c..93336cf 100644 --- a/modules/network/ctrl.lua +++ b/modules/network/ctrl.lua @@ -97,7 +97,7 @@ me.register_node("ctrl", { end if not net then me.log("ME Network Controller without Network","error") - return false + return true end return net:get_access_level(name) >= access_level.full end, @@ -131,6 +131,39 @@ me.register_node("ctrl", { }, }) +minetest.register_lbm({ + name = "microexpansion:update_network", + label = "integrate new ME Network data", + nodenames = {"microexpansion:ctrl"}, + run_at_every_load = true, + action = function(pos) + local meta = minetest.get_meta(pos) + local net,idx = me.get_network(pos) + if not meta then + me.log("activated controller before metadata was available", "warning") + return + end + local source = meta:get_string("source") + if not net then + if source == "" then + me.log("activated controller without network", "warning") + return + else + net = me.get_network(vector.from_string(source)) + if not net then + me.log("activated controller that is linked to an unloaded controller", "info") + return + end + end + end + if not net.access then + me.log("added access table to old network", "action") + net.access = {} + end + net:fallback_access() + end +}) + -- [register node] Cable me.register_machine("cable", { description = "ME Cable", @@ -173,6 +206,7 @@ me.register_machine("cable", { return net:get_access_level(name) >= access_level.modify end, on_construct = function(pos) + --perhaps this needs to be done after the check if it can be placed me.send_event(pos,"connect") end, after_place_node = function(pos, placer) @@ -186,6 +220,7 @@ me.register_machine("cable", { --minetest.remove_node(pos) return true end + --TODO: prevent connecting multiple networks local net,cp = me.get_connected_network(pos) if not net then return false diff --git a/modules/network/network.lua b/modules/network/network.lua index e8ea704..0f4cbe1 100644 --- a/modules/network/network.lua +++ b/modules/network/network.lua @@ -353,11 +353,6 @@ function network:load() if self.strinv then self:load_inventory(self.strinv) end - --make sure someone has access to the network - if not self.access then - self.access = {} - end - self:fallback_access() end function network:serialize()