Fix deprecation warning issue #120

This commit is contained in:
Joachim Stolberg 2023-05-20 17:41:18 +02:00
parent c263c77b4c
commit 96355a2534
2 changed files with 20 additions and 12 deletions

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

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