From 585f2bcd3e3c54e1c1af07e3fd505865d3f1ed1d Mon Sep 17 00:00:00 2001 From: Ronoaldo JLP Date: Mon, 20 Sep 2021 15:52:37 -0300 Subject: [PATCH] Keep previous physics when entering/leaving sprint Prevent losing the 3d_armor or mobs_nether speed/jump changes from their boots. --- init.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index df4769a..c0e83ec 100644 --- a/init.lua +++ b/init.lua @@ -45,6 +45,8 @@ end -- Functions +local _previous_physics = {} + local function start_sprint(player) local name = player:get_player_name() if not sprinting[name] then @@ -55,6 +57,7 @@ local function start_sprint(player) playerphysics.add_physics_factor(player, "speed", "hbsprint:speed", speed) playerphysics.add_physics_factor(player, "jump", "hbsprint:jump", jump) else + _previous_physics[name] = player:get_physics_override() player:set_physics_override({speed = speed, jump = jump}) end sprinting[name] = true @@ -71,7 +74,8 @@ local function stop_sprint(player) 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}) + local restore = _previous_physics[name] or {} + player:set_physics_override(restore) end sprinting[name] = false end @@ -259,3 +263,4 @@ minetest.register_globalstep(function(dtime) sprint_timer = 0 end end) +