diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index d8d0dbee3..00f319080 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -72,6 +72,7 @@ end local function setSprinting(playerName, sprinting) --Sets the state of a player (0=stopped/moving, 1=sprinting) local player = minetest.get_player_by_name(playerName) local controls = player:get_player_control() + local isNotColliding = mcl_playerinfo:collision_detect(player:get_pos(),player) if players[playerName] then players[playerName].sprinting = sprinting local fov_old = players[playerName].fov @@ -163,75 +164,81 @@ minetest.register_globalstep(function(dtime) --Loop through all connected players for playerName, playerInfo in pairs(players) do local player = get_player_by_name(playerName) + if player then - 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 + local playerPos = player:get_pos() + 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}) + local isNotColliding = mcl_playerinfo:collision_detect(player:get_pos(),player) + local ctrl = player:get_player_control() - 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 + --Check if the player should be sprinting + + if not isNotColliding and ctrl.aux1 and ctrl.up and not ctrl.sneak then + print("uwu") + players[playerName]["shouldSprint"] = false + elseif isNotColliding and players[playerName]["clientSprint"] or ctrl.aux1 and ctrl.up and not ctrl.sneak then + players[playerName]["shouldSprint"] = true else - setSprinting(playerName, 0) + players[playerName]["shouldSprint"] = false + end + --If the player is sprinting, create particles behind and cause exhaustion + if isNotColliding and playerInfo["sprinting"] == true and players[playerName]["shouldSprint"] and not player:get_attach() and gameTime % 0.1 == 0 then + + -- Exhaust player for sprinting + 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(.5, 1.4), + time = 1, + minpos = {x=-0.3, y=0.1, z=-0.3}, + maxpos = {x=0.3, y=0.1, z=0.3}, + 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