From abe8368e328bfaa384035751fcc63f8903bed36c Mon Sep 17 00:00:00 2001 From: upsilon Date: Tue, 2 May 2017 18:11:24 +0200 Subject: [PATCH] Make the mod working with current stable release --- moremesecons_jammer/init.lua | 16 +++++++++++++--- moremesecons_teleporter/init.lua | 23 ++++++++++++++++++----- moremesecons_wireless/init.lua | 25 +++++++++++++++++++------ 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/moremesecons_jammer/init.lua b/moremesecons_jammer/init.lua index 721dc37..c424b82 100644 --- a/moremesecons_jammer/init.lua +++ b/moremesecons_jammer/init.lua @@ -4,10 +4,20 @@ local set = vector.set_data_to_pos local remove = vector.remove_data_from_pos local jammers -local storage = minetest.get_mod_storage() -jammers = minetest.deserialize(storage:get_string("jammers")) or {} +local enable_lbm = moremesecons.setting("jammer", "enable_lbm", false) +local storage +if not minetest.get_mod_storage then + enable_lbm = true -- No mod storage (<= 0.4.15-stable): force registration of LBM + jammers = {} +else + storage = minetest.get_mod_storage() + jammers = minetest.deserialize(storage:get_string("jammers")) or {} +end local function update_mod_storage() + if not storage then + return + end storage:set_string("jammers", minetest.serialize(jammers)) end @@ -133,7 +143,7 @@ minetest.register_craft({ {"", "moremesecons_wireless:jammer_off", ""}} }) -if moremesecons.setting("jammer", "enable_lbm", false) then +if enable_lbm then minetest.register_lbm({ name = "moremesecons_jammer:add_jammer", nodenames = {"moremesecons_jammer:jammer_on"}, diff --git a/moremesecons_teleporter/init.lua b/moremesecons_teleporter/init.lua index baf5e8f..4a266f2 100644 --- a/moremesecons_teleporter/init.lua +++ b/moremesecons_teleporter/init.lua @@ -1,12 +1,25 @@ local teleporters local teleporters_rids -local storage = minetest.get_mod_storage() -teleporters = minetest.deserialize(storage:get_string("teleporters")) or {} -teleporters_rids = minetest.deserialize(storage:get_string("teleporters_rids")) or {} -jammers = minetest.deserialize(storage:get_string("jammers")) or {} +local enable_lbm = moremesecons.setting("teleporter", "enable_lbm", false) +local storage +if not minetest.get_mod_storage then + enable_lbm = true -- No mod storage (<= 0.4.15-stable): force registration of LBM + teleporters = {} + teleporters_rids = {} + jammers = {} +else + storage = minetest.get_mod_storage() + + teleporters = minetest.deserialize(storage:get_string("teleporters")) or {} + teleporters_rids = minetest.deserialize(storage:get_string("teleporters_rids")) or {} + jammers = minetest.deserialize(storage:get_string("jammers")) or {} +end local function update_mod_storage() + if not storage then + return + end storage:set_string("teleporters", minetest.serialize(teleporters)) storage:set_string("teleporters_rids", minetest.serialize(teleporters_rids)) end @@ -100,7 +113,7 @@ minetest.register_node("moremesecons_teleporter:teleporter", { end, }) -if moremesecons.setting("teleporter", "enable_lbm", false) then +if enable_lbm then minetest.register_lbm({ name = "moremesecons_teleporter:add_teleporter", nodenames = {"moremesecons_teleporter:teleporter"}, diff --git a/moremesecons_wireless/init.lua b/moremesecons_wireless/init.lua index 78f46e3..a2bec38 100644 --- a/moremesecons_wireless/init.lua +++ b/moremesecons_wireless/init.lua @@ -2,12 +2,25 @@ local wireless local wireless_meta -- This table contains wireless metadatas, it is a lot faster to access local jammers -local storage = minetest.get_mod_storage() -wireless = minetest.deserialize(storage:get_string("wireless")) or {} -wireless_meta = minetest.deserialize(storage:get_string("wireless_meta")) or {owners = {}, channels = {}, ids = {}} -jammers = minetest.deserialize(storage:get_string("jammers")) or {} +local enable_lbm = moremesecons.setting("wireless", "enable_lbm", false) +local storage +if not minetest.get_mod_storage then + enable_lbm = true -- No mod storage (<= 0.4.15-stable): force registration of LBM + wireless = {} + wireless_meta = {owners = {}, channels = {}, ids = {}} + jammers = {} +else + storage = minetest.get_mod_storage() + + wireless = minetest.deserialize(storage:get_string("wireless")) or {} + wireless_meta = minetest.deserialize(storage:get_string("wireless_meta")) or {owners = {}, channels = {}, ids = {}} + jammers = minetest.deserialize(storage:get_string("jammers")) or {} +end local function update_mod_storage() + if not storage then + return + end storage:set_string("wireless", minetest.serialize(wireless)) storage:set_string("wireless_meta", minetest.serialize(wireless_meta)) storage:set_string("jammers", minetest.serialize(jammers)) @@ -364,7 +377,7 @@ minetest.register_craft({ } }) -if moremesecons.setting("wireless", "enable_lbm", false) then +if enable_lbm then minetest.register_lbm({ name = "moremesecons_wireless:add_jammer", nodenames = {"moremesecons_wireless:jammer_on"}, @@ -382,7 +395,7 @@ end -- Legacy -if storage:get_string("wireless_rids") and storage:get_string("wireless_rids") ~= "" then +if storage and storage:get_string("wireless_rids") and storage:get_string("wireless_rids") ~= "" then -- Upgrade mod storage! local wireless_rids = minetest.deserialize(storage:get_string("wireless_rids")) local old_wireless = table.copy(wireless)