From 63794bea753f3fd8e1a96298db93f8ea9f84675e Mon Sep 17 00:00:00 2001 From: Panquesito7 Date: Wed, 28 Aug 2019 12:44:28 -0500 Subject: [PATCH 1/9] Use "mod.conf" for optional dependencies and description (#16) * Update mod.conf * Delete description.txt No longer needed. * Delete depends.txt No longer needed. --- depends.txt | 4 ---- description.txt | 1 - mod.conf | 2 ++ 3 files changed, 2 insertions(+), 5 deletions(-) delete mode 100644 depends.txt delete mode 100644 description.txt diff --git a/depends.txt b/depends.txt deleted file mode 100644 index 77322de..0000000 --- a/depends.txt +++ /dev/null @@ -1,4 +0,0 @@ -player_monoids? -hudbars? -hbhunger? -hunger_ng? diff --git a/description.txt b/description.txt deleted file mode 100644 index 4de59ff..0000000 --- a/description.txt +++ /dev/null @@ -1 +0,0 @@ -A flexible sprint mod supporting stamina, hunger and monoids. diff --git a/mod.conf b/mod.conf index 4433f1a..07be93e 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,3 @@ name = hbsprint +optional_depends = player_monoids, hudbars, hbhunger, hunger_ng +description = A flexible sprint mod supporting stamina, hunger and monoids. From ee2cc8bff1e18ead3e708c8440c7efa3e45a9fd1 Mon Sep 17 00:00:00 2001 From: ClockGen <12116711+ClockGen@users.noreply.github.com> Date: Fri, 30 Aug 2019 13:01:07 +0300 Subject: [PATCH 2/9] Fixed sprinting in water and stamina regen with multiple players (#15) --- init.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index b8b9470..175e78b 100644 --- a/init.lua +++ b/init.lua @@ -17,8 +17,6 @@ local autohide = minetest.settings:get_bool("hudbars_autohide_stamina") ~= local sprint_timer_step = 0.5 local sprint_timer = 0 -local stamina_timer = 0 -local breath_timer = 0 local mod_hudbars = minetest.get_modpath("hudbars") or false local mod_player_monoids = minetest.get_modpath("player_monoids") or false @@ -153,12 +151,12 @@ end) minetest.register_globalstep(function(dtime) sprint_timer = sprint_timer + dtime - stamina_timer = stamina_timer + dtime - breath_timer = breath_timer + dtime if sprint_timer >= sprint_timer_step then for _,player in ipairs(minetest.get_connected_players()) do local ctrl = player:get_player_control() local key_press = false + player:get_meta():set_float("hbsprint_stamina_timer", player:get_meta():get_float("hbsprint_stamina_timer") + sprint_timer) + player:get_meta():set_float("hbsprint_breath_timer", player:get_meta():get_float("hbsprint_breath_timer") + sprint_timer) if key == "Use" and dir then key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right elseif key == "Use" and not dir then @@ -184,8 +182,8 @@ minetest.register_globalstep(function(dtime) end if ground ~= nil then local ground_def = minetest.registered_nodes[ground.name] - if ground_def then - walkable = minetest.registered_nodes[ground.name].walkable + if ground_def and (minetest.registered_nodes[ground.name].walkable or minetest.registered_nodes[ground.name].liquidtype ~= "none") then + walkable = true end end if player_stamina > 0 and hunger > starve_limit and walkable then @@ -194,9 +192,9 @@ minetest.register_globalstep(function(dtime) if stamina then drain_stamina(player) end if starve then drain_hunger(player, hunger, name) end if breath then - if breath_timer >= 2 then + if player:get_meta():get_float("hbsprint_breath_timer") >= 2 then drain_breath(player) - breath_timer = 0 + player:get_meta():set_float("hbsprint_breath_timer", 0) end end if particles then create_particles(player, name, pos, ground) end @@ -207,9 +205,9 @@ minetest.register_globalstep(function(dtime) else stop_sprint(player) player:get_meta():set_string("hbsprint:sprinting", "false") - if stamina_timer >= replenish then + if player:get_meta():get_float("hbsprint_stamina_timer") >= replenish then if stamina then replenish_stamina(player) end - stamina_timer = 0 + player:get_meta():set_float("hbsprint_stamina_timer", 0) end end end From 93ccb5c820dd6d841a4fc842ccf2e7b535b6a642 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 17 Oct 2019 16:01:38 +0200 Subject: [PATCH 3/9] remove unused key configurability --- init.lua | 11 ++--------- settingtypes.txt | 3 --- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/init.lua b/init.lua index 175e78b..f06f44d 100644 --- a/init.lua +++ b/init.lua @@ -2,7 +2,6 @@ local speed = tonumber(minetest.settings:get ("sprint_speed")) or 1.3 local jump = tonumber(minetest.settings:get ("sprint_jump")) or 1.1 -local key = minetest.settings:get ("sprint_key") or "Use" local dir = minetest.settings:get_bool("sprint_forward_only") ~= false local particles = tonumber(minetest.settings:get ("sprint_particles")) or 2 local stamina = minetest.settings:get_bool("sprint_stamina") ~= false @@ -26,7 +25,6 @@ if minetest.get_modpath("hbhunger") then starve = "hbhunger" elseif minetest.get_modpath("hunger_ng") then starve = "hunger_ng" - --starve_drain = starve_drain * -1 else starve = false end @@ -157,16 +155,11 @@ minetest.register_globalstep(function(dtime) local key_press = false player:get_meta():set_float("hbsprint_stamina_timer", player:get_meta():get_float("hbsprint_stamina_timer") + sprint_timer) player:get_meta():set_float("hbsprint_breath_timer", player:get_meta():get_float("hbsprint_breath_timer") + sprint_timer) - if key == "Use" and dir then + if dir then key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right - elseif key == "Use" and not dir then + else key_press = ctrl.aux1 end - -- if key == "W" and dir then - -- key_press = ctrl.aux1 and ctrl.up or key_press and ctrl.up - -- elseif key == "W" then - -- key_press = ctrl.aux1 or key_press and key_tap - -- end if key_press then local name = player:get_player_name() diff --git a/settingtypes.txt b/settingtypes.txt index dfeec5f..2014a0d 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -4,9 +4,6 @@ sprint_speed (Sprint speed multiplier) float 1.3 #Sprint jump multiplier sprint_jump (Sprint jump multiplier) float 1.1 -#Use a key to sprint -sprint_key (Sprint key) enum Use Use - #Require player to move forward only to be able to sprint sprint_forward_only (Sprint forward only) bool true From df1c083dd202dff4ef4ab85042c03781a259b48e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 17 Oct 2019 16:09:23 +0200 Subject: [PATCH 4/9] re-do settings --- init.lua | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/init.lua b/init.lua index f06f44d..5aac7d1 100644 --- a/init.lua +++ b/init.lua @@ -1,32 +1,38 @@ -- Vars -local speed = tonumber(minetest.settings:get ("sprint_speed")) or 1.3 -local jump = tonumber(minetest.settings:get ("sprint_jump")) or 1.1 -local dir = minetest.settings:get_bool("sprint_forward_only") ~= false -local particles = tonumber(minetest.settings:get ("sprint_particles")) or 2 -local stamina = minetest.settings:get_bool("sprint_stamina") ~= false -local stamina_drain = tonumber(minetest.settings:get ("sprint_stamina_drain")) or 2 -local replenish = tonumber(minetest.settings:get ("sprint_stamina_replenish")) or 2 -local starve = minetest.settings:get_bool("sprint_starve") ~= false -local starve_drain = tonumber(minetest.settings:get ("sprint_starve_drain")) or 0.5 -local starve_limit = tonumber(minetest.settings:get ("sprint_starve_limit")) or 6 -local breath = minetest.settings:get_bool("sprint_breath") ~= false -local breath_drain = tonumber(minetest.settings:get ("sprint_breath_drain")) or 1 -local autohide = minetest.settings:get_bool("hudbars_autohide_stamina") ~= false +local function setting_get(name, default) + return minetest.settings:get(name) or default +end + +local speed = tonumber(setting_get("sprint_speed", "1.3")) +local jump = tonumber(setting_get("sprint_jump", "1.1")) +local dir = minetest.is_yes(setting_get("sprint_forward_only", "false")) +local particles = tonumber(setting_get("sprint_particles", "2")) +local stamina = minetest.is_yes(setting_get("sprint_stamina", "true")) +local stamina_drain = tonumber(setting_get("sprint_stamina_drain", "2")) +local replenish = tonumber(setting_get("sprint_stamina_replenish", "2")) +local starve = minetest.is_yes(setting_get("sprint_starve", "true")) +local starve_drain = tonumber(setting_get("sprint_starve_drain", "0.5")) +local starve_limit = tonumber(setting_get("sprint_starve_limit", "6")) +local breath = minetest.is_yes(setting_get("sprint_breath", "true")) +local breath_drain = tonumber(setting_get("sprint_breath_drain", "1")) +local autohide = minetest.is_yes(setting_get("hudbards_autohide_stamina", "false")) local sprint_timer_step = 0.5 local sprint_timer = 0 -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" -elseif minetest.get_modpath("hunger_ng") then - starve = "hunger_ng" -else - starve = false +local mod_hudbars = minetest.get_modpath("hudbars") ~= nil +local mod_player_monoids = minetest.get_modpath("player_monoids") ~= nil +local mod_playerphysics = minetest.get_modpath("playerphysics") ~= nil + +if starve then + if minetest.get_modpath("hbhunger") then + starve = "hbhunger" + elseif minetest.get_modpath("hunger_ng") then + starve = "hunger_ng" + else + starve = false + end end if minetest.settings:get_bool("creative_mode") then starve = false From 6634757361881f0571dbc85ad9471b41841381e3 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 17 Oct 2019 16:17:44 +0200 Subject: [PATCH 5/9] move some vars out of metadata --- init.lua | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 5aac7d1..94f0429 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,9 @@ local autohide = minetest.is_yes(setting_get("hudbards_autohide_stamina", " local sprint_timer_step = 0.5 local sprint_timer = 0 +local sprinting = {} +local stamina_timer = {} +local breath_timer = {} local mod_hudbars = minetest.get_modpath("hudbars") ~= nil local mod_player_monoids = minetest.get_modpath("player_monoids") ~= nil @@ -40,7 +43,7 @@ end -- Functions local function start_sprint(player) - if player:get_meta():get("hbsprint:sprinting") == "false" then + if not sprinting[player:get_player_name()] then if mod_player_monoids then player_monoids.speed:add_change(player, speed, "hbsprint:speed") player_monoids.jump:add_change(player, jump, "hbsprint:jump") @@ -54,7 +57,7 @@ local function start_sprint(player) end local function stop_sprint(player) - if player:get_meta():get("hbsprint:sprinting") == "true" then + if sprinting[player:get_player_name()] then if mod_player_monoids then player_monoids.speed:del_change(player, "hbsprint:speed") player_monoids.jump:del_change(player, "hbsprint:jump") @@ -159,8 +162,8 @@ minetest.register_globalstep(function(dtime) for _,player in ipairs(minetest.get_connected_players()) do local ctrl = player:get_player_control() local key_press = false - player:get_meta():set_float("hbsprint_stamina_timer", player:get_meta():get_float("hbsprint_stamina_timer") + sprint_timer) - player:get_meta():set_float("hbsprint_breath_timer", player:get_meta():get_float("hbsprint_breath_timer") + sprint_timer) + stamina_timer[player:get_player_name()] = (stamina_timer[player:get_player_name()] or 0) + sprint_timer + breath_timer[player:get_player_name()] = (breath_timer[player:get_player_name()] or 0) + sprint_timer if dir then key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right else @@ -187,26 +190,26 @@ minetest.register_globalstep(function(dtime) end if player_stamina > 0 and hunger > starve_limit and walkable then start_sprint(player) - player:get_meta():set_string("hbsprint:sprinting", "true") + sprinting[name] = true if stamina then drain_stamina(player) end if starve then drain_hunger(player, hunger, name) end if breath then - if player:get_meta():get_float("hbsprint_breath_timer") >= 2 then + if breath_timer[name] >= 2 then drain_breath(player) - player:get_meta():set_float("hbsprint_breath_timer", 0) + breath_timer[name] = 0 end end if particles then create_particles(player, name, pos, ground) end else stop_sprint(player) - player:get_meta():set_string("hbsprint:sprinting", "false") + sprinting[name] = false end else stop_sprint(player) - player:get_meta():set_string("hbsprint:sprinting", "false") - if player:get_meta():get_float("hbsprint_stamina_timer") >= replenish then + sprinting[player:get_player_name()] = false + if stamina_timer[player:get_player_name()] >= replenish then if stamina then replenish_stamina(player) end - player:get_meta():set_float("hbsprint_stamina_timer", 0) + stamina_timer[player:get_player_name()] = 0 end end end From dabdb17ce00092b6f3258499bc0107908c4a411d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 17 Oct 2019 16:43:56 +0200 Subject: [PATCH 6/9] refactor --- init.lua | 203 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 112 insertions(+), 91 deletions(-) diff --git a/init.lua b/init.lua index 94f0429..fddab1e 100644 --- a/init.lua +++ b/init.lua @@ -43,7 +43,8 @@ end -- Functions local function start_sprint(player) - if not sprinting[player:get_player_name()] then + local name = player:get_player_name() + if not sprinting[name] then if mod_player_monoids then player_monoids.speed:add_change(player, speed, "hbsprint:speed") player_monoids.jump:add_change(player, jump, "hbsprint:jump") @@ -53,11 +54,13 @@ local function start_sprint(player) else player:set_physics_override({speed = speed, jump = jump}) end + sprinting[name] = true end end local function stop_sprint(player) - if sprinting[player:get_player_name()] then + local name = player:get_player_name() + if sprinting[name] then if mod_player_monoids then player_monoids.speed:del_change(player, "hbsprint:speed") player_monoids.jump:del_change(player, "hbsprint:jump") @@ -67,13 +70,15 @@ local function stop_sprint(player) else player:set_physics_override({speed = 1, jump = 1}) end + sprinting[name] = false end end local function drain_stamina(player) - local player_stamina = tonumber(player:get_meta():get("hbsprint:stamina")) + local player_stamina = player:get_meta():get_float("hbsprint:stamina") if player_stamina > 0 then - player:get_meta():set_float("hbsprint:stamina", player_stamina - stamina_drain) + player_stamina = math.max(0, player_stamina - stamina_drain) + player:get_meta():set_float("hbsprint:stamina", player_stamina) end if mod_hudbars then if autohide and player_stamina < 20 then hb.unhide_hudbar(player, "stamina") end @@ -82,55 +87,56 @@ local function drain_stamina(player) end local function replenish_stamina(player) - local player_stamina = tonumber(player:get_meta():get("hbsprint:stamina")) + local player_stamina = player:get_meta():get_float("hbsprint:stamina") if player_stamina < 20 then - player:get_meta():set_float("hbsprint:stamina", player_stamina + stamina_drain) + player_stamina = math.min(20, player_stamina + stamina_drain) + player:get_meta():set_float("hbsprint:stamina", player_stamina) end if mod_hudbars then hb.change_hudbar(player, "stamina", player_stamina) - if autohide and player_stamina == 20 then hb.hide_hudbar(player, "stamina") end + if autohide and player_stamina >= 20 then hb.hide_hudbar(player, "stamina") end end end -local function drain_hunger(player, hunger, name) - if hunger > 0 then - local newhunger = hunger - starve_drain - if starve == "hbhunger" then - hbhunger.hunger[name] = newhunger - hbhunger.set_hunger_raw(player) - elseif starve == "hunger_ng" then - hunger_ng.alter_hunger(name, - starve_drain, "Sprinting") - end +local function drain_hunger(player, name) + if starve == "hbhunger" then + local hunger = tonumber(hbhunger.hunger[name]) - starve_drain + hbhunger.hunger[name] = math.max(0, hunger) + hbhunger.set_hunger_raw(player) + elseif starve == "hunger_ng" then + hunger_ng.alter_hunger(name, -starve_drain, "Sprinting") end end local function drain_breath(player) local player_breath = player:get_breath() if player_breath < 11 then - player_breath = player_breath - breath_drain - if player_breath > 0 then - player:set_breath(player_breath) - end + player_breath = math.max(0, player_breath - breath_drain) + player:set_breath(player_breath) end end local function create_particles(player, name, pos, ground) - if ground and ground.name ~= "air" and ground.name ~= "ignore" then - local def = minetest.registered_nodes[ground.name] - local tile = def.tiles[1] or def.inventory_image or "" - if type(tile) == "string" then - for i = 1, particles do - minetest.add_particle({ - pos = {x = pos.x + math.random(-1,1) * math.random() / 2, y = pos.y + 0.1, z = pos.z + math.random(-1,1) * math.random() / 2}, - velocity = {x = 0, y = 5, z = 0}, - acceleration = {x = 0, y = -13, z = 0}, - expirationtime = math.random(), - size = math.random() + 0.5, - vertical = false, - texture = tile, - }) - end - end + if not ground or ground.name == "air" or ground.name == "ignore" then + return + end + local def = minetest.registered_nodes[ground.name] + local tile = def.tiles[1] or def.inventory_image + if type(tile) ~= "string" then + return + end + + local rand = function() return math.random(-1,1) * math.random() / 2 end + for i = 1, particles do + minetest.add_particle({ + pos = {x = pos.x + rand(), y = pos.y + 0.1, z = pos.z + rand()}, + velocity = {x = 0, y = 5, z = 0}, + acceleration = {x = 0, y = -13, z = 0}, + expirationtime = math.random(), + size = math.random() + 0.5, + vertical = false, + texture = tile, + }) end end @@ -152,66 +158,81 @@ if mod_hudbars and stamina then end minetest.register_on_joinplayer(function(player) - if mod_hudbars and stamina then hb.init_hudbar(player, "stamina", 20, 20, autohide) end - player:get_meta():set_float("hbsprint:stamina", 20) + if stamina then + if mod_hudbars then + hb.init_hudbar(player, "stamina", 20, 20, autohide) + end + player:get_meta():set_float("hbsprint:stamina", 20) + end end) +local function sprint_step(player, dtime) + local name = player:get_player_name() + + if stamina then + stamina_timer[name] = (stamina_timer[name] or 0) + dtime + end + if breath then + breath_timer[name] = (breath_timer[name] or 0) + dtime + end + + local ctrl = player:get_player_control() + local key_press + if dir then + key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right + else + key_press = ctrl.aux1 + end + + if not key_press then + stop_sprint(player) + if stamina and stamina_timer[name] >= replenish then + replenish_stamina(player) + stamina_timer[name] = 0 + end + return + end + + 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 + if ground ~= nil then + local ground_def = minetest.registered_nodes[ground.name] + walkable = ground_def and (ground_def.walkable or ground_def.liquidtype ~= "none") + end + + local player_stamina = 1 + if stamina then + player_stamina = player:get_meta():get_float("hbsprint:stamina") + end + local hunger = 30 + if starve == "hbhunger" then + hunger = tonumber(hbhunger.hunger[name]) + elseif starve == "hunger_ng" then + hunger = hunger_ng.get_hunger_information(name).hunger.exact + end + + if player_stamina > 0 and hunger > starve_limit and walkable then + start_sprint(player) + if stamina then drain_stamina(player) end + if starve then drain_hunger(player, name) end + if breath and breath_timer[name] >= 2 then + drain_breath(player) + breath_timer[name] = 0 + end + if particles then + create_particles(player, name, pos, ground) + end + else + stop_sprint(player) + end +end + minetest.register_globalstep(function(dtime) sprint_timer = sprint_timer + dtime if sprint_timer >= sprint_timer_step then - for _,player in ipairs(minetest.get_connected_players()) do - local ctrl = player:get_player_control() - local key_press = false - stamina_timer[player:get_player_name()] = (stamina_timer[player:get_player_name()] or 0) + sprint_timer - breath_timer[player:get_player_name()] = (breath_timer[player:get_player_name()] or 0) + sprint_timer - if dir then - key_press = ctrl.aux1 and ctrl.up and not ctrl.left and not ctrl.right - else - key_press = ctrl.aux1 - end - - if key_press then - local name = player:get_player_name() - local hunger = 30 - 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_meta():get("hbsprint:stamina")) - if starve == "hbhunger" then - hunger = tonumber(hbhunger.hunger[name]) - elseif starve == "hunger_ng" then - hunger = hunger_ng.get_hunger_information(name).hunger.exact - end - if ground ~= nil then - local ground_def = minetest.registered_nodes[ground.name] - if ground_def and (minetest.registered_nodes[ground.name].walkable or minetest.registered_nodes[ground.name].liquidtype ~= "none") then - walkable = true - end - end - if player_stamina > 0 and hunger > starve_limit and walkable then - start_sprint(player) - sprinting[name] = true - if stamina then drain_stamina(player) end - if starve then drain_hunger(player, hunger, name) end - if breath then - if breath_timer[name] >= 2 then - drain_breath(player) - breath_timer[name] = 0 - end - end - if particles then create_particles(player, name, pos, ground) end - else - stop_sprint(player) - sprinting[name] = false - end - else - stop_sprint(player) - sprinting[player:get_player_name()] = false - if stamina_timer[player:get_player_name()] >= replenish then - if stamina then replenish_stamina(player) end - stamina_timer[player:get_player_name()] = 0 - end - end + for _, player in ipairs(minetest.get_connected_players()) do + sprint_step(player, sprint_timer) end sprint_timer = 0 end From 8daf632e9d7d7c487a109f7da8c95312435982b2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 17 Oct 2019 17:00:35 +0200 Subject: [PATCH 7/9] more improvements --- init.lua | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index fddab1e..dcec9da 100644 --- a/init.lua +++ b/init.lua @@ -40,6 +40,7 @@ end if minetest.settings:get_bool("creative_mode") then starve = false end + -- Functions local function start_sprint(player) @@ -110,22 +111,28 @@ end local function drain_breath(player) local player_breath = player:get_breath() - if player_breath < 11 then + if player_breath < player:get_properties().breath_max then player_breath = math.max(0, player_breath - breath_drain) player:set_breath(player_breath) end end -local function create_particles(player, name, pos, ground) - if not ground or ground.name == "air" or ground.name == "ignore" then - return - end +local function is_walkable(ground) + local ground_def = minetest.registered_nodes[ground.name] + return ground_def and (ground_def.walkable and ground_def.liquidtype == "none") +end + +local function create_particles(player, name, ground) local def = minetest.registered_nodes[ground.name] local tile = def.tiles[1] or def.inventory_image - if type(tile) ~= "string" then + if type(tile) == "table" then + tile = tile.name + end + if not tile then return end + local pos = player:get_pos() local rand = function() return math.random(-1,1) * math.random() / 2 end for i = 1, particles do minetest.add_particle({ @@ -169,6 +176,10 @@ end) local function sprint_step(player, dtime) local name = player:get_player_name() + if minetest.get_player_privs(name).fast then + return + end + if stamina then stamina_timer[name] = (stamina_timer[name] or 0) + dtime end @@ -193,12 +204,17 @@ local function sprint_step(player, dtime) return end - 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 - if ground ~= nil then - local ground_def = minetest.registered_nodes[ground.name] - walkable = ground_def and (ground_def.walkable or ground_def.liquidtype ~= "none") + local ground_pos = player:get_pos() + ground_pos.y = math.floor(ground_pos.y) + -- check if player is reasonably near a walkable node + local ground + for _, y_off in ipairs({0, -1, -2}) do + local testpos = vector.add(ground_pos, {x=0, y=y_off, z=0}) + local testnode = minetest.get_node_or_nil(testpos) + if testnode ~= nil and is_walkable(testnode) then + ground = testnode + break + end end local player_stamina = 1 @@ -212,7 +228,7 @@ local function sprint_step(player, dtime) hunger = hunger_ng.get_hunger_information(name).hunger.exact end - if player_stamina > 0 and hunger > starve_limit and walkable then + if player_stamina > 0 and hunger > starve_limit and ground then start_sprint(player) if stamina then drain_stamina(player) end if starve then drain_hunger(player, name) end @@ -221,7 +237,7 @@ local function sprint_step(player, dtime) breath_timer[name] = 0 end if particles then - create_particles(player, name, pos, ground) + create_particles(player, name, ground) end else stop_sprint(player) From 18f6aec37de961bfa8c2006ff1130983112b54cc Mon Sep 17 00:00:00 2001 From: sfan5 Date: Thu, 17 Oct 2019 17:36:23 +0200 Subject: [PATCH 8/9] update README --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c080bd7..c9d48b1 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,14 @@ A flexible sprint mod supporting stamina, hunger and coexistance with other phys ## Notes hbSprint can be played with Minetest 0.4.16 or above. -It has no dependencies, but it supports on [hudbars](http://repo.or.cz/w/minetest_hudbars.git), [hbhunger](http://repo.or.cz/w/minetest_hbhunger.git) and [player_monoids](https://github.com/minetest-mods/player_monoids). +It has no dependencies, but supports [hudbars](https://repo.or.cz/minetest_hudbars.git) and [player_monoids](https://github.com/minetest-mods/player_monoids). + +Compatible hunger mods: [hbhunger](https://repo.or.cz/minetest_hbhunger.git) or [hunger_ng](https://gitlab.com/4w/hunger_ng). ## List of features - Displays and drains stamina (by default, if hudbars is present). Hides stamina bar if full. -- Displays and drains satiation (by default, if hbhunger is present) +- Displays and drains satiation (by default, if compatible hunger mod found) - Drains air faster while sprinting on walkable ground but in water (by default) - Requires only forward key to be pressed, not left and right (by default) - Requires walkable ground (no water surface sprinting) @@ -32,6 +34,6 @@ It has no dependencies, but it supports on [hudbars](http://repo.or.cz/w/minetes You can report bugs or suggest ideas by [filing an issue](http://github.com/tacotexmex/hbsprint/issues/new). ## Links -* [Download ZIP](https://github.com/tacotexmex/hbsprint/archive/master.zip) -* [Source](https://github.com/tacotexmex/hbsprint/) +* [Download ZIP](https://github.com/minetest-mods/hbsprint/archive/master.zip) +* [Source](https://github.com/minetest-mods/hbsprint) * [Forum thread](https://forum.minetest.net/viewtopic.php?f=9&t=18069&p=282981) From 25472427e59899efa0b39cfad884dda03bacc06c Mon Sep 17 00:00:00 2001 From: tuedel Date: Thu, 24 Oct 2019 15:59:38 +0200 Subject: [PATCH 9/9] Fix typo in autohide setting, default to true again --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index dcec9da..b0adc9d 100644 --- a/init.lua +++ b/init.lua @@ -16,7 +16,7 @@ local starve_drain = tonumber(setting_get("sprint_starve_drain", "0.5")) local starve_limit = tonumber(setting_get("sprint_starve_limit", "6")) local breath = minetest.is_yes(setting_get("sprint_breath", "true")) local breath_drain = tonumber(setting_get("sprint_breath_drain", "1")) -local autohide = minetest.is_yes(setting_get("hudbards_autohide_stamina", "false")) +local autohide = minetest.is_yes(setting_get("hudbars_autohide_stamina", "true")) local sprint_timer_step = 0.5 local sprint_timer = 0