From 01f2bc4065e7331c9c5b53e608fbf10855e5f0f5 Mon Sep 17 00:00:00 2001 From: mazes Date: Mon, 21 Sep 2020 07:10:33 +0200 Subject: [PATCH] getters and setters: _attribute -> get_meta():[g/s]et_string --- init.lua | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/init.lua b/init.lua index 1619539..551457e 100644 --- a/init.lua +++ b/init.lua @@ -121,8 +121,9 @@ end -- Check for the necessary number of points and grant lumberjack privs if level is reached -- local function check_points(player) - local points = tonumber(player:get_attribute("lumberjack_tree_points") or LUMBERJACK_TREE_POINTS) - points = points + tonumber(player:get_attribute("lumberjack_sapl_points") or LUMBERJACK_SAPL_POINTS) + local player_attributes = player:get_meta() + local points = tonumber(player_attributes:get_string("lumberjack_tree_points")) or LUMBERJACK_TREE_POINTS + points = points + ( tonumber(player_attributes:get_string("lumberjack_sapl_points")) or LUMBERJACK_SAPL_POINTS ) if points > 0 then return false @@ -130,8 +131,8 @@ local function check_points(player) local privs = minetest.get_player_privs(player:get_player_name()) privs.lumberjack = true minetest.set_player_privs(player:get_player_name(), privs) - player:set_attribute("lumberjack_tree_points", "-1") - player:set_attribute("lumberjack_sapl_points", "-1") + player_attributes:get_string("lumberjack_tree_points", "-1") + player_attributes:get_string("lumberjack_sapl_points", "-1") minetest.chat_send_player(player:get_player_name(), "You got lumberjack privs now") minetest.log("action", player:get_player_name().." got lumberjack privs") end @@ -142,9 +143,10 @@ end -- Maintain lumberjack points and grant lumberjack privs if level is reached -- local function needed_points(digger) - local points = tonumber(digger:get_attribute("lumberjack_tree_points") or LUMBERJACK_TREE_POINTS) + local digger_attributes = digger:get_meta() + local points = tonumber(digger_attributes:get_string("lumberjack_tree_points")) or LUMBERJACK_TREE_POINTS if points > 0 then - digger:set_attribute("lumberjack_tree_points", tostring(points - 1)) + digger_attributes:set_string("lumberjack_tree_points", tostring(points - 1)) end if points == 0 then return check_points(digger) @@ -156,10 +158,11 @@ end -- Decrement sapling points -- local function after_place_sapling(pos, placer) - if placer and placer.is_player and placer:is_player() and placer.get_attribute then - local points = tonumber(placer:get_attribute("lumberjack_sapl_points") or LUMBERJACK_SAPL_POINTS) + if placer and placer.is_player and placer:is_player() and placer.get_meta then + local placer_attributes = placer:get_meta() + local points = tonumber(placer_attributes:get_string("lumberjack_sapl_points")) or LUMBERJACK_SAPL_POINTS if points > 0 then - placer:set_attribute("lumberjack_sapl_points", tostring(points - 1)) + placer_attributes:set_string("lumberjack_sapl_points", tostring(points - 1)) end if points == 0 then check_points(placer)