From d36beaf64f87d220a2e89e8f11891a3906ae660b Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 21 Feb 2017 16:44:26 +0100 Subject: [PATCH] Prevent sprinting if hunger level <= 6 --- mods/PLAYER/mcl_sprint/README.md | 1 + mods/PLAYER/mcl_sprint/depends.txt | 1 + mods/PLAYER/mcl_sprint/esprint.lua | 4 ++-- mods/PLAYER/mcl_sprint/init.lua | 1 + mods/PLAYER/mcl_sprint/wsprint.lua | 16 ++++++++-------- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/mods/PLAYER/mcl_sprint/README.md b/mods/PLAYER/mcl_sprint/README.md index c8a8e99c..bf02b909 100644 --- a/mods/PLAYER/mcl_sprint/README.md +++ b/mods/PLAYER/mcl_sprint/README.md @@ -19,6 +19,7 @@ What a player has to do to start sprinting. 0 = double tap w, 1 = press e. Note that if you have the fast privlige, and have the fast speed turned on, you will run very, very fast. You can toggle this by pressing j. +NOTE: Method 0 is UNTESTED! mcl_sprint.SPEED (default 1.5) diff --git a/mods/PLAYER/mcl_sprint/depends.txt b/mods/PLAYER/mcl_sprint/depends.txt index db2aacba..73b34163 100644 --- a/mods/PLAYER/mcl_sprint/depends.txt +++ b/mods/PLAYER/mcl_sprint/depends.txt @@ -1 +1,2 @@ playerplus +mcl_hunger diff --git a/mods/PLAYER/mcl_sprint/esprint.lua b/mods/PLAYER/mcl_sprint/esprint.lua index 886d5146..e7599b45 100644 --- a/mods/PLAYER/mcl_sprint/esprint.lua +++ b/mods/PLAYER/mcl_sprint/esprint.lua @@ -61,8 +61,8 @@ minetest.register_globalstep(function(dtime) --Adjust player states if players[playerName]["shouldSprint"] == true then --Stopped local sprinting - -- Prevent sprinting if standing on soul sand - if playerplus[playerName].nod_stand == "mcl_nether:soul_sand" then + -- Prevent sprinting if standing on soul sand or hungry + if playerplus[playerName].nod_stand == "mcl_nether:soul_sand" or mcl_hunger.get_hunger(player) <= 6 then sprinting = false else sprinting = true diff --git a/mods/PLAYER/mcl_sprint/init.lua b/mods/PLAYER/mcl_sprint/init.lua index 0437c0cc..49a7705a 100644 --- a/mods/PLAYER/mcl_sprint/init.lua +++ b/mods/PLAYER/mcl_sprint/init.lua @@ -15,6 +15,7 @@ mcl_sprint.SPEED = 1.3 mcl_sprint.TIMEOUT = 0.5 --Only used if mcl_sprint.METHOD = 0 if mcl_sprint.METHOD == 0 then + -- UNTESTED dofile(minetest.get_modpath("mcl_sprint") .. "/wsprint.lua") elseif mcl_sprint.METHOD == 1 then dofile(minetest.get_modpath("mcl_sprint") .. "/esprint.lua") diff --git a/mods/PLAYER/mcl_sprint/wsprint.lua b/mods/PLAYER/mcl_sprint/wsprint.lua index 70b40ef5..05c7cdb3 100644 --- a/mods/PLAYER/mcl_sprint/wsprint.lua +++ b/mods/PLAYER/mcl_sprint/wsprint.lua @@ -60,6 +60,8 @@ minetest.register_globalstep(function(dtime) end end + -- Prevent sprinting if standing on soul sand or hungry + local can_sprint = (playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand") and (mcl_hunger.get_hunger(player) <= 6) --Adjust player states if players[playerName]["moving"] == false and playerInfo["state"] == 3 then --Stopped setState(playerName, 0) @@ -67,18 +69,16 @@ minetest.register_globalstep(function(dtime) setState(playerName, 1) elseif players[playerName]["moving"] == false and playerInfo["state"] == 1 then --Primed local sprinting - -- Prevent sprinting if standing on soul sand - if not playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then - setState(playerName, 2) - else + if can_sprint then setState(playerName, 0) + else + setState(playerName, 2) end elseif players[playerName]["moving"] == true and playerInfo["state"] == 2 then --Sprinting - -- Prevent sprinting if standing on soul sand - if not playerplus[playerName].nod_stand ~= "mcl_nether:soul_sand" then - setState(playerName, 3) - else + if can_sprint then setState(playerName, 1) + else + setState(playerName, 3) end end