Replace deprecated player attribute calls

This commit is contained in:
Wuzzy 2019-03-06 05:45:16 +01:00
parent 4c8433b41c
commit 2b3922c972
7 changed files with 33 additions and 29 deletions

View File

@ -127,7 +127,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
mcl_player.player_attached[name] = false
playerphysics.remove_physics_factor(player, "speed", "mcl_beds:sleeping")
playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping")
player:set_attribute("mcl_beds:sleeping", "false")
player:get_meta():set_string("mcl_beds:sleeping", "false")
hud_flags.wielditem = true
mcl_player.player_set_animation(player, "stand" , 30)
mcl_beds.pos[name] = nil
@ -181,7 +181,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
player:set_look_horizontal(yaw)
player:set_look_vertical(0)
player:set_attribute("mcl_beds:sleeping", "true")
player:get_meta():set_string("mcl_beds:sleeping", "true")
playerphysics.add_physics_factor(player, "speed", "mcl_beds:sleeping", 0)
playerphysics.add_physics_factor(player, "jump", "mcl_beds:sleeping", 0)
player:set_pos(p)
@ -296,7 +296,7 @@ end
function mcl_beds.on_rightclick(pos, player, is_top)
-- Anti-Inception: Don't allow to sleep while you're sleeping
if player:get_attribute("mcl_beds:sleeping") == "true" then
if player:get_meta():get_string("mcl_beds:sleeping") == "true" then
return
end
if minetest.get_modpath("mcl_worlds") then
@ -343,9 +343,10 @@ end
-- Callbacks
minetest.register_on_joinplayer(function(player)
if player:get_attribute("mcl_beds:sleeping") == "true" then
local meta = player:get_meta()
if meta:get_string("mcl_beds:sleeping") == "true" then
-- Make player awake on joining server
player:set_attribute("mcl_beds:sleeping", "false")
meta:set_string("mcl_beds:sleeping", "false")
end
playerphysics.remove_physics_factor(player, "speed", "mcl_beds:sleeping")
playerphysics.remove_physics_factor(player, "jump", "mcl_beds:sleeping")

View File

@ -2,23 +2,23 @@ mcl_hunger.registered_foods = {}
if mcl_hunger.active then
function mcl_hunger.get_hunger(player)
local hunger = player:get_attribute("mcl_hunger:hunger") or 20
local hunger = player:get_meta():get_string("mcl_hunger:hunger") or 20
return tonumber(hunger)
end
function mcl_hunger.get_saturation(player)
local saturation = player:get_attribute("mcl_hunger:saturation") or mcl_hunger.SATURATION_INIT
local saturation = player:get_meta():get_string("mcl_hunger:saturation") or mcl_hunger.SATURATION_INIT
return tonumber(saturation)
end
function mcl_hunger.get_exhaustion(player)
local exhaustion = player:get_attribute("mcl_hunger:exhaustion") or 0
local exhaustion = player:get_meta():get_string("mcl_hunger:exhaustion") or 0
return tonumber(exhaustion)
end
function mcl_hunger.set_hunger(player, hunger, update_hudbars)
hunger = math.min(20, math.max(0, hunger))
player:set_attribute("mcl_hunger:hunger", tostring(hunger))
player:get_meta():set_string("mcl_hunger:hunger", tostring(hunger))
if update_hudbars ~= false then
hb.change_hudbar(player, "hunger", hunger)
mcl_hunger.update_saturation_hud(player, nil, hunger)
@ -28,7 +28,7 @@ if mcl_hunger.active then
function mcl_hunger.set_saturation(player, saturation, update_hudbar)
saturation = math.min(mcl_hunger.get_hunger(player), math.max(0, saturation))
player:set_attribute("mcl_hunger:saturation", tostring(saturation))
player:get_meta():set_string("mcl_hunger:saturation", tostring(saturation))
if update_hudbar ~= false then
mcl_hunger.update_saturation_hud(player, saturation)
end
@ -37,7 +37,7 @@ if mcl_hunger.active then
function mcl_hunger.set_exhaustion(player, exhaustion, update_hudbar)
exhaustion = math.min(mcl_hunger.EXHAUST_LVL, math.max(0.0, exhaustion))
player:set_attribute("mcl_hunger:exhaustion", tostring(exhaustion))
player:get_meta():set_string("mcl_hunger:exhaustion", tostring(exhaustion))
if update_hudbar ~= false then
mcl_hunger.update_exhaustion_hud(player, exhaustion)
end

View File

@ -75,12 +75,12 @@ function mcl_player.player_set_textures(player, textures, preview)
player_textures[name] = textures
player:set_properties({textures = textures,})
if preview then
player:set_attribute("mcl_player:preview", preview)
player:get_meta():set_string("mcl_player:preview", preview)
end
end
function mcl_player.player_get_preview(player)
local preview = player:get_attribute("mcl_player:preview")
local preview = player:get_meta():get_string("mcl_player:preview")
if not preview then
return "player.png"
else

View File

@ -72,7 +72,7 @@ while true do
end
mcl_skins.cycle_skin = function(player)
local skin_id = tonumber(player:get_attribute("mcl_skins:skin_id"))
local skin_id = tonumber(player:get_meta():get_string("mcl_skins:skin_id"))
if not skin_id then
skin_id = 0
end
@ -106,7 +106,7 @@ mcl_skins.set_player_skin = function(player, skin_id)
skin_file = skin .. ".png"
mcl_skins.skins[playername] = skin
mcl_skins.previews[playername] = preview
player:set_attribute("mcl_skins:skin_id", tostring(skin_id))
player:get_meta():set_string("mcl_skins:skin_id", tostring(skin_id))
mcl_skins.update_player_skin(player)
if minetest.get_modpath("3d_armor") then
armor.textures[playername].skin = skin_file
@ -134,7 +134,7 @@ end
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
local skin_id = player:get_attribute("mcl_skins:skin_id")
local skin_id = player:get_meta():get_string("mcl_skins:skin_id")
local set_skin
-- do we already have a skin in player attributes?
if skin_id then

View File

@ -10,7 +10,7 @@ local mg_name = minetest.get_mapgen_setting("mg_name")
mcl_spawn.get_spawn_pos = function(player)
local spawn, custom_spawn = nil, false
if player ~= nil and player:is_player() then
local attr = player:get_attribute("mcl_beds:spawn")
local attr = player:get_meta():get_string("mcl_beds:spawn")
if attr ~= nil and attr ~= "" then
spawn = minetest.string_to_pos(attr)
custom_spawn = true
@ -21,7 +21,7 @@ mcl_spawn.get_spawn_pos = function(player)
custom_spawn = false
end
if not spawn or spawn == "" then
local attr = player:get_attribute("mcl_spawn:first_spawn")
local attr = player:get_meta():get_string("mcl_spawn:first_spawn")
if attr ~= nil and attr ~= "" then
spawn = minetest.string_to_pos(attr)
custom_spawn = false
@ -36,16 +36,17 @@ end
-- changed.
mcl_spawn.set_spawn_pos = function(player, pos, message)
local spawn_changed = false
local meta = player:get_meta()
if pos == nil then
if player:get_attribute("mcl_beds:spawn") ~= "" then
if meta:get_string("mcl_beds:spawn") ~= "" then
spawn_changed = true
if message then
minetest.chat_send_player(player:get_player_name(), "Respawn position cleared!")
end
end
player:set_attribute("mcl_beds:spawn", "")
meta:set_string("mcl_beds:spawn", "")
else
local oldpos = minetest.string_to_pos(player:get_attribute("mcl_beds:spawn"))
local oldpos = minetest.string_to_pos(meta:get_string("mcl_beds:spawn"))
if oldpos then
-- We don't bother sending a message if the new spawn pos is basically the same
if vector.distance(pos, oldpos) > 0.1 then
@ -55,7 +56,7 @@ mcl_spawn.set_spawn_pos = function(player, pos, message)
end
end
end
player:set_attribute("mcl_beds:spawn", minetest.pos_to_string(pos))
meta:set_string("mcl_beds:spawn", minetest.pos_to_string(pos))
end
return spawn_changed
end
@ -99,6 +100,6 @@ end)
minetest.register_on_newplayer(function(player)
-- Remember where the player spawned first
player:set_attribute("mcl_spawn:first_spawn", minetest.pos_to_string(player:get_pos()))
player:get_meta():set_string("mcl_spawn:first_spawn", minetest.pos_to_string(player:get_pos()))
end)

View File

@ -107,7 +107,7 @@ minetest.register_globalstep(function(dtime)
if players[playerName]["shouldSprint"] == true then --Stopped
local sprinting
-- Prevent sprinting if hungry or sleeping
if (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) or (player:get_attribute("mcl_beds:sleeping") == "true")then
if (mcl_hunger.active and mcl_hunger.get_hunger(player) <= 6) or (player:get_meta():get_string("mcl_beds:sleeping") == "true")then
sprinting = false
else
sprinting = true

View File

@ -1,7 +1,7 @@
playerphysics = {}
local function calculate_attribute_product(player, attribute)
local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
local a = minetest.deserialize(player:get_meta():get_string("playerphysics:physics"))
local product = 1
if a == nil or a[attribute] == nil then
return product
@ -16,7 +16,8 @@ local function calculate_attribute_product(player, attribute)
end
function playerphysics.add_physics_factor(player, attribute, id, value)
local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
local meta = player:get_meta()
local a = minetest.deserialize(meta:get_string("playerphysics:physics"))
if a == nil then
a = { [attribute] = { [id] = value } }
elseif a[attribute] == nil then
@ -24,20 +25,21 @@ function playerphysics.add_physics_factor(player, attribute, id, value)
else
a[attribute][id] = value
end
player:set_attribute("playerphysics:physics", minetest.serialize(a))
meta:set_string("playerphysics:physics", minetest.serialize(a))
local raw_value = calculate_attribute_product(player, attribute)
player:set_physics_override({[attribute] = raw_value})
end
function playerphysics.remove_physics_factor(player, attribute, id)
local a = minetest.deserialize(player:get_attribute("playerphysics:physics"))
local meta = player:get_meta()
local a = minetest.deserialize(meta:get_string("playerphysics:physics"))
if a == nil or a[attribute] == nil then
-- Nothing to remove
return
else
a[attribute][id] = nil
end
player:set_attribute("playerphysics:physics", minetest.serialize(a))
meta:set_string("playerphysics:physics", minetest.serialize(a))
local raw_value = calculate_attribute_product(player, attribute)
player:set_physics_override({[attribute] = raw_value})
end