From b2e8c082659b7787060d45733d3f4f94f1b5d76f Mon Sep 17 00:00:00 2001 From: tacotexmex Date: Sun, 10 Feb 2019 09:26:31 +0100 Subject: [PATCH 1/3] Replace deprecated player attributes with player meta --- init.lua | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index 1bf3c13..f24dc75 100644 --- a/init.lua +++ b/init.lua @@ -37,7 +37,7 @@ end -- Functions local function start_sprint(player) - if player:get_attribute("hbsprint:sprinting") == "false" then + if player:get_meta():get("hbsprint:sprinting") == "false" then if monoids then player_monoids.speed:add_change(player, speed, "hbsprint:speed") player_monoids.jump:add_change(player, jump, "hbsprint:jump") @@ -48,7 +48,7 @@ local function start_sprint(player) end local function stop_sprint(player) - if player:get_attribute("hbsprint:sprinting") == "true" then + if player:get_meta():get("hbsprint:sprinting") == "true" then if monoids then player_monoids.speed:del_change(player, "hbsprint:speed") player_monoids.jump:del_change(player, "hbsprint:jump") @@ -59,9 +59,9 @@ local function stop_sprint(player) end local function drain_stamina(player) - local player_stamina = tonumber(player:get_attribute("hbsprint:stamina")) + local player_stamina = tonumber(player:get_meta():get("hbsprint:stamina")) if player_stamina > 0 then - player:set_attribute("hbsprint:stamina", player_stamina - stamina_drain) + player:get_meta():set_float("hbsprint:stamina", player_stamina - stamina_drain) end if hudbars then if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end @@ -70,9 +70,9 @@ local function drain_stamina(player) end local function replenish_stamina(player) - local player_stamina = tonumber(player:get_attribute("hbsprint:stamina")) + local player_stamina = tonumber(player:get_meta():get("hbsprint:stamina")) if player_stamina < 20 then - player:set_attribute("hbsprint:stamina", player_stamina + stamina_drain) + player:get_meta():set_float("hbsprint:stamina", player_stamina + stamina_drain) end if hudbars then hb.change_hudbar(player, "stamina", player_stamina) @@ -87,7 +87,7 @@ local function drain_hunger(player, hunger, name) hbhunger.hunger[name] = newhunger hbhunger.set_hunger_raw(player) elseif starve == "hunger_ng" then - player:set_attribute("hunger_ng:hunger", newhunger) + player:get_meta():set_int("hunger_ng:hunger", newhunger) end end end @@ -141,7 +141,7 @@ end minetest.register_on_joinplayer(function(player) if hudbars and stamina then hb.init_hudbar(player, "stamina", 20, 20, autohide) end - player:set_attribute("hbsprint:stamina", 20) + player:get_meta():set_float("hbsprint:stamina", 20) end) minetest.register_globalstep(function(dtime) @@ -169,11 +169,11 @@ minetest.register_globalstep(function(dtime) local pos = player:get_pos() local ground = minetest.get_node_or_nil({x=pos.x, y=pos.y-1, z=pos.z}) local walkable = false - local player_stamina = tonumber(player:get_attribute("hbsprint:stamina")) + local player_stamina = tonumber(player:get_meta():get("hbsprint:stamina")) if starve == "hbhunger" then hunger = tonumber(hbhunger.hunger[name]) elseif starve == "hunger_ng" then - hunger = tonumber(player:get_attribute("hunger_ng:hunger")) + hunger = tonumber(player:get_meta():get("hunger_ng:hunger")) end if ground ~= nil then local ground_def = minetest.registered_nodes[ground.name] @@ -183,7 +183,7 @@ minetest.register_globalstep(function(dtime) end if player_stamina > 0 and hunger > starve_limit and walkable then start_sprint(player) - player:set_attribute("hbsprint:sprinting", "true") + player:get_meta():set_string("hbsprint:sprinting", "true") if stamina then drain_stamina(player) end if starve then drain_hunger(player, hunger, name) end if breath then @@ -195,11 +195,11 @@ minetest.register_globalstep(function(dtime) if particles then create_particles(player, name, pos, ground) end else stop_sprint(player) - player:set_attribute("hbsprint:sprinting", "false") + player:get_meta():set_string("hbsprint:sprinting", "false") end else stop_sprint(player) - player:set_attribute("hbsprint:sprinting", "false") + player:get_meta():set_string("hbsprint:sprinting", "false") if stamina_timer >= replenish then if stamina then replenish_stamina(player) end stamina_timer = 0 From 13cc9d522a3e1fcc91e1901ec74ffc108000142c Mon Sep 17 00:00:00 2001 From: tacotexmex Date: Sun, 10 Feb 2019 09:26:50 +0100 Subject: [PATCH 2/3] Add support for new hunger_ng API --- init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index f24dc75..f946500 100644 --- a/init.lua +++ b/init.lua @@ -87,7 +87,7 @@ local function drain_hunger(player, hunger, name) hbhunger.hunger[name] = newhunger hbhunger.set_hunger_raw(player) elseif starve == "hunger_ng" then - player:get_meta():set_int("hunger_ng:hunger", newhunger) + hunger_ng.alter_hunger(name, - starve_drain, "Sprinting") end end end @@ -173,7 +173,7 @@ minetest.register_globalstep(function(dtime) if starve == "hbhunger" then hunger = tonumber(hbhunger.hunger[name]) elseif starve == "hunger_ng" then - hunger = tonumber(player:get_meta():get("hunger_ng:hunger")) + hunger = hunger_ng.get_hunger_information(name).hunger.exact end if ground ~= nil then local ground_def = minetest.registered_nodes[ground.name] From 05712baabf3ccaa86cb78ebe5d8d0339c8ec8e34 Mon Sep 17 00:00:00 2001 From: tacotexmex Date: Sat, 23 Feb 2019 05:16:24 +0100 Subject: [PATCH 3/3] Add support for playerphysics --- init.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index f946500..8e28d7a 100644 --- a/init.lua +++ b/init.lua @@ -20,8 +20,9 @@ local sprint_timer = 0 local stamina_timer = 0 local breath_timer = 0 -local hudbars = minetest.get_modpath("hudbars") or false -local monoids = minetest.get_modpath("player_monoids") or false +local mod_hudbars = minetest.get_modpath("hudbars") or false +local mod_player_monoids = minetest.get_modpath("player_monoids") or false +local mod_playerphysics = minetest.get_modpath("playerphysics") or false local starve if minetest.get_modpath("hbhunger") then starve = "hbhunger" @@ -38,9 +39,12 @@ end local function start_sprint(player) if player:get_meta():get("hbsprint:sprinting") == "false" then - if monoids then + if mod_player_monoids then player_monoids.speed:add_change(player, speed, "hbsprint:speed") player_monoids.jump:add_change(player, jump, "hbsprint:jump") + elseif mod_playerphysics then + playerphysics.add_physics_factor(player, "speed", "hbsprint:speed", speed) + playerphysics.add_physics_factor(player, "jump", "hbsprint:jump", jump) else player:set_physics_override({speed = speed, jump = jump}) end @@ -49,9 +53,12 @@ end local function stop_sprint(player) if player:get_meta():get("hbsprint:sprinting") == "true" then - if monoids then + if mod_player_monoids then player_monoids.speed:del_change(player, "hbsprint:speed") player_monoids.jump:del_change(player, "hbsprint:jump") + elseif mod_playerphysics then + playerphysics.remove_physics_factor(player, "speed", "hbsprint:speed") + playerphysics.remove_physics_factor(player, "jump", "hbsprint:jump") else player:set_physics_override({speed = 1, jump = 1}) end