Deprecate player:get/set_attribute to player:get_meta().

This commit is contained in:
Aaron Suen 2019-04-06 20:46:13 -04:00
parent a674184df0
commit 80d3d9708c
4 changed files with 10 additions and 11 deletions

View File

@ -1,13 +1,12 @@
-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore, tonumber, tostring
= math, minetest, nodecore, tonumber, tostring
local math, minetest, nodecore
= math, minetest, nodecore
local math_ceil
= math.ceil
-- LUALOCALS > ---------------------------------------------------------
local function getphealth(player)
return player:get_hp()
+ tonumber(player:get_attribute("dhp") or "0")
return player:get_hp() + player:get_meta():get_float("dhp")
end
nodecore.getphealth = getphealth
@ -17,7 +16,7 @@ local function setphealth(player, hp)
local whole = math_ceil(hp)
if whole == 0 then whole = 1 end
local dhp = hp - whole
player:set_attribute("dhp", tostring(dhp))
player:get_meta():set_float("dhp", dhp)
return player:set_hp(whole)
end
nodecore.setphealth = setphealth

View File

@ -7,7 +7,7 @@ minetest.register_on_player_hpchange(function(player, hp)
local t = player:get_hp()
if hp + t <= 0 then
hp = 1 - t
player:set_attribute("dhp", "-1")
player:get_meta():set_float("dhp", -1)
end
return hp
end, true)

View File

@ -45,7 +45,7 @@ local function envcheck(player)
local agg = cache[pname]
if not agg then
agg = {}
local raw = player:get_attribute("healthenv")
local raw = player:get_meta():get_string("healthenv")
if raw and raw ~= "" then
agg = minetest.deserialize(raw)
end
@ -57,7 +57,7 @@ local function envcheck(player)
agg.dirty = (agg.dirty or 0) + 1
if agg.dirty >= 5 then
agg.dirty = nil
player:set_attribute("healthenv",
player:get_meta():set_string("healthenv",
minetest.serialize(agg))
for k, v in pairs(agg) do
agg[k] = 1 - math_exp(-v)
@ -75,7 +75,7 @@ local function envcheck(player)
end
minetest.register_on_dieplayer(function(player)
player:set_attribute("healthenv", "")
player:get_meta():set_string("healthenv", "")
cache[player:get_player_name()] = nil
end)

View File

@ -50,7 +50,7 @@ local function playeradd(qty, player, ...)
if not pname then return end
local data = db[pname]
if not data then
data = load_check(player:get_attribute(modname))
data = load_check(player:get_meta():get_string(modname))
db[pname] = data
end
dbadd(qty, pname, ...)
@ -219,7 +219,7 @@ local function flushkey(k)
local player = minetest.get_player_by_name(k)
if player then
return player:set_attribute(modname, minetest.serialize(v))
return player:get_meta():set_string(modname, minetest.serialize(v))
end
end