From 6801e6556d1150af7aa4b888c869bee6cf0a4c3d Mon Sep 17 00:00:00 2001 From: Guy Liner Date: Thu, 6 Jan 2022 22:00:15 -0500 Subject: [PATCH] Rearranged some conditionals --- mods/PLAYER/mcl_sprint/init.lua | 132 ++++++++++++++++---------------- 1 file changed, 65 insertions(+), 67 deletions(-) diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index b6a9401bbb..26dad5be86 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -164,77 +164,75 @@ minetest.register_globalstep(function(dtime) for playerName, playerInfo in pairs(players) do local player = get_player_by_name(playerName) if player then - local ctrl = player:get_player_control() - - --Check if the player should be sprinting - if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then - if not mcl_playerinfo:collision_detect(player:get_pos(),player) then - players[playerName]["shouldSprint"] = true - end - elseif mcl_playerinfo:collision_detect(player:get_pos(),player) then - players[playerName]["shouldSprint"] = false + if mcl_playerinfo:collision_detect(player:get_pos(),player) then + local ctrl = player:get_player_control() + --Check if the player should be sprinting + if players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then + players[playerName]["shouldSprint"] = true + else + players[playerName]["shouldSprint"] = false + end + + local playerPos = player:get_pos() + --If the player is sprinting, create particles behind and cause exhaustion + if playerInfo["sprinting"] == true and players[playerName]["shouldSprint"] and not player:get_attach() and gameTime % 0.1 == 0 then + -- Exhaust player for sprinting + local lastPos = players[playerName].lastPos + local dist = vector.distance({x=lastPos.x, y=0, z=lastPos.z}, {x=playerPos.x, y=0, z=playerPos.z}) + players[playerName].sprintDistance = players[playerName].sprintDistance + dist + if players[playerName].sprintDistance >= 1 then + local superficial = math.floor(players[playerName].sprintDistance) + exhaust(playerName, mcl_hunger.EXHAUST_SPRINT * superficial) + players[playerName].sprintDistance = players[playerName].sprintDistance - superficial + end + + -- Sprint node particles + local playerNode = get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]}) + local def = registered_nodes[playerNode.name] + if def and def.walkable then + add_particlespawner({ + amount = math.random(1, 2), + time = 1, + minpos = {x=-0.5, y=0.1, z=-0.5}, + maxpos = {x=0.5, y=0.1, z=0.5}, + minvel = {x=0, y=5, z=0}, + maxvel = {x=0, y=5, z=0}, + minacc = {x=0, y=-13, z=0}, + maxacc = {x=0, y=-13, z=0}, + minexptime = 0.1, + maxexptime = 1, + minsize = 0.5, + maxsize = 1.5, + collisiondetection = true, + attached = player, + vertical = false, + node = playerNode, + node_tile = get_top_node_tile(playerNode.param2, def.paramtype2), + }) + end + end + + --Adjust player states + players[playerName].lastPos = playerPos + if players[playerName]["shouldSprint"] == true then --Stopped + local sprinting + -- Prevent sprinting if hungry or sleeping + if (mcl_hunger.active and get_hunger(player) <= 6) + or (player:get_meta():get_string("mcl_beds:sleeping") == "true") then + sprinting = false + cancelClientSprinting(playerName) + else + sprinting = true + end + setSprinting(playerName, sprinting) + elseif players[playerName]["shouldSprint"] == false then + setSprinting(playerName, false) + end else - players[playerName]["shouldSprint"] = false + setSprinting(playerName, 0) end - - local playerPos = player:get_pos() - --If the player is sprinting, create particles behind and cause exhaustion - if playerInfo["sprinting"] == true and players[playerName]["shouldSprint"] and not player:get_attach() and gameTime % 0.1 == 0 then - -- Exhaust player for sprinting - local lastPos = players[playerName].lastPos - local dist = vector.distance({x=lastPos.x, y=0, z=lastPos.z}, {x=playerPos.x, y=0, z=playerPos.z}) - players[playerName].sprintDistance = players[playerName].sprintDistance + dist - if players[playerName].sprintDistance >= 1 then - local superficial = math.floor(players[playerName].sprintDistance) - exhaust(playerName, mcl_hunger.EXHAUST_SPRINT * superficial) - players[playerName].sprintDistance = players[playerName].sprintDistance - superficial - end - - -- Sprint node particles - local playerNode = get_node({x=playerPos["x"], y=playerPos["y"]-1, z=playerPos["z"]}) - local def = registered_nodes[playerNode.name] - if def and def.walkable then - add_particlespawner({ - amount = math.random(1, 2), - time = 1, - minpos = {x=-0.5, y=0.1, z=-0.5}, - maxpos = {x=0.5, y=0.1, z=0.5}, - minvel = {x=0, y=5, z=0}, - maxvel = {x=0, y=5, z=0}, - minacc = {x=0, y=-13, z=0}, - maxacc = {x=0, y=-13, z=0}, - minexptime = 0.1, - maxexptime = 1, - minsize = 0.5, - maxsize = 1.5, - collisiondetection = true, - attached = player, - vertical = false, - node = playerNode, - node_tile = get_top_node_tile(playerNode.param2, def.paramtype2), - }) - end - end - - --Adjust player states - players[playerName].lastPos = playerPos - if players[playerName]["shouldSprint"] == true then --Stopped - local sprinting - -- Prevent sprinting if hungry or sleeping - if (mcl_hunger.active and get_hunger(player) <= 6) - or (player:get_meta():get_string("mcl_beds:sleeping") == "true") then - sprinting = false - cancelClientSprinting(playerName) - else - sprinting = true - end - setSprinting(playerName, sprinting) - elseif players[playerName]["shouldSprint"] == false then - setSprinting(playerName, false) - end - end end end)