if enable_damage is false, disable eating functions

This commit is contained in:
tenplus1 2022-08-02 14:10:31 +01:00
parent 0fb4e82b58
commit 96570a558e

View File

@ -485,8 +485,12 @@ local function stamina_globaltimer(dtime)
end end
-- override core.do_item_eat() so we can redirect hp_change to stamina -- stamina and eating functions disabled if damage is disabled
core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) if minetest.settings:get_bool("enable_damage")
and minetest.settings:get_bool("enable_stamina") ~= false then
-- override core.do_item_eat() so we can redirect hp_change to stamina
core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing)
if user.is_fake_player then if user.is_fake_player then
return -- abort if called by fake player (eg. pipeworks-wielder) return -- abort if called by fake player (eg. pipeworks-wielder)
@ -508,11 +512,10 @@ core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, point
end end
return itemstack return itemstack
end end
-- not local since it's called from within core context
-- not local since it's called from within core context function stamina.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
function stamina.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
if not itemstack or not user then if not itemstack or not user then
return itemstack return itemstack
@ -606,12 +609,7 @@ function stamina.eat(hp_change, replace_with_item, itemstack, user, pointed_thin
end end
return itemstack return itemstack
end end
-- stamina is disabled if damage is disabled
if minetest.settings:get_bool("enable_damage")
and minetest.settings:get_bool("enable_stamina") ~= false then
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)