From 96355a25348275790297f3939f5e52e1f98223b3 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 20 May 2023 17:41:18 +0200 Subject: [PATCH] Fix deprecation warning issue #120 --- tubelib/forceload.lua | 19 ++++++++++++------- tubelib_addons2/programmer.lua | 13 ++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/tubelib/forceload.lua b/tubelib/forceload.lua index 6aab0f3..3d86c59 100644 --- a/tubelib/forceload.lua +++ b/tubelib/forceload.lua @@ -75,32 +75,37 @@ local function get_node_lvm(pos) end local function add_pos(pos, player) - local lPos = minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or {} + local meta = player:get_meta() + local lPos = minetest.deserialize(meta:get_string("tubelib_forceload_blocks")) or {} if not in_list(lPos, pos) and #lPos < tubelib.max_num_forceload_blocks then lPos[#lPos+1] = pos - player:set_attribute("tubelib_forceload_blocks", minetest.serialize(lPos)) + meta:set_string("tubelib_forceload_blocks", minetest.serialize(lPos)) return true end return false end local function del_pos(pos, player) - local lPos = minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or {} + local meta = player:get_meta() + local lPos = minetest.deserialize(meta:get_string("tubelib_forceload_blocks")) or {} lPos = remove_list_elem(lPos, pos) - player:set_attribute("tubelib_forceload_blocks", minetest.serialize(lPos)) + meta:set_string("tubelib_forceload_blocks", minetest.serialize(lPos)) end local function get_pos_list(player) - return minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or {} + local meta = player:get_meta() + return minetest.deserialize(meta:get_string("tubelib_forceload_blocks")) or {} end local function set_pos_list(player, lPos) - player:set_attribute("tubelib_forceload_blocks", minetest.serialize(lPos)) + local meta = player:get_meta() + meta:set_string("tubelib_forceload_blocks", minetest.serialize(lPos)) end local function get_data(pos, player) local pos1, pos2 = calc_area(pos) - local num = #minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or 0 + local meta = player:get_meta() + local num = #minetest.deserialize(meta:get_string("tubelib_forceload_blocks")) or 0 local max = tubelib.max_num_forceload_blocks return pos1, pos2, num, max end diff --git a/tubelib_addons2/programmer.lua b/tubelib_addons2/programmer.lua index 8e0aecc..2c79e9b 100644 --- a/tubelib_addons2/programmer.lua +++ b/tubelib_addons2/programmer.lua @@ -25,19 +25,21 @@ local function join_to_string(tbl) end local function reset_programmer(itemstack, user, pointed_thing) - user:set_attribute("tubelib_prog_numbers", nil) + local meta = user:get_meta() + meta:set_string("tubelib_prog_numbers", nil) minetest.chat_send_player(user:get_player_name(), S("[Tubelib Programmer] programmer reset")) return itemstack end local function read_number(itemstack, user, pointed_thing) local pos = pointed_thing.under + local meta = user:get_meta() if pos then local number = tubelib.get_node_number(pos) if number then - local numbers = minetest.deserialize(user:get_attribute("tubelib_prog_numbers")) or {} + local numbers = minetest.deserialize(meta:get_string("tubelib_prog_numbers")) or {} numbers[number] = true - user:set_attribute("tubelib_prog_numbers", minetest.serialize(numbers)) + meta:set_string("tubelib_prog_numbers", minetest.serialize(numbers)) minetest.chat_send_player(user:get_player_name(), S("[Tubelib Programmer] number").." "..number.." "..S("read")) else minetest.chat_send_player(user:get_player_name(), S("[Tubelib Programmer] Unknown node on").." "..minetest.pos_to_string(pos)) @@ -50,11 +52,12 @@ end local function program_numbers(itemstack, placer, pointed_thing) local pos = pointed_thing.under + local pmeta = placer:get_meta() if pos then local meta = minetest.get_meta(pos) local node_number = tubelib.get_node_number(pos) - local numbers = minetest.deserialize(placer:get_attribute("tubelib_prog_numbers")) or {} - placer:set_attribute("tubelib_prog_numbers", nil) + local numbers = minetest.deserialize(pmeta:get_string("tubelib_prog_numbers")) or {} + pmeta:set_string("tubelib_prog_numbers", nil) local text = join_to_string(numbers) local player_name = placer:get_player_name() if meta and meta:get_string("owner") ~= player_name then