From 64b1df789dd7adf482457bc102e4fcf319d995ee Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 13 Nov 2020 00:59:04 +0100 Subject: [PATCH] Implement eating for disabled damage as well --- mods/hbhunger/hunger.lua | 1 - mods/hbhunger/init.lua | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/mods/hbhunger/hunger.lua b/mods/hbhunger/hunger.lua index bbca00a..5b6c4c3 100644 --- a/mods/hbhunger/hunger.lua +++ b/mods/hbhunger/hunger.lua @@ -7,7 +7,6 @@ function hbhunger.load_hunger(player) end -- wrapper for minetest.item_eat (this way we make sure other mods can't break this one) -local org_eat = minetest.do_item_eat minetest.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) local old_itemstack = itemstack itemstack = hbhunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) diff --git a/mods/hbhunger/init.lua b/mods/hbhunger/init.lua index 641d4cc..65ae474 100644 --- a/mods/hbhunger/init.lua +++ b/mods/hbhunger/init.lua @@ -184,4 +184,38 @@ minetest.register_chatcommand("satiation", { end, }) +else + +-- Eating function if damage is disabled +minetest.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) + + local def = itemstack:get_definition() + local sound + if def and def.sound then + sound = def.sound + end + if not sound then + local item = itemstack:get_name() + if minetest.get_item_group(item, "food") == 3 then + sound = "survival_thirst_drink" + elseif not sound then + sound = "hbhunger_eat_generic" + end + end + minetest.sound_play( + {name = sound or "hbhunger_eat_generic", + gain = 1}, + {object=user, + max_hear_distance = 16, + pitch = 1 + math.random(-10, 10)*0.005,}, + true + ) + local name = user and user:get_player_name() or "" + if not minetest.is_creative_enabled(name) then + itemstack:take_item() + end + return itemstack + +end + end -- 2.11.4.GIT