Skip to content

Commit

Permalink
fix diet not effecting satiation
Browse files Browse the repository at this point in the history
  • Loading branch information
Elkien3 committed Dec 12, 2022
1 parent d4395ab commit f66a95c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
37 changes: 0 additions & 37 deletions mods/foodspoil/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,43 +116,6 @@ minetest.register_on_mods_loaded(function()
end
return org_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
end

if hbhunger then
local food = hbhunger.food
hbhunger.eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing)
local item = itemstack:get_name()
local def = food[item]
if not def then
def = {}
if type(hp_change) ~= "number" then
hp_change = 1
core.log("error", "Wrong on_use() definition for item '" .. item .. "'")
end
def.saturation = hp_change * 1.3
def.replace = replace_with_item
end

local saturation = def.saturation
local poisen = def.poisen or 0
local expire = itemstack:get_meta():get_int("ed")
if expire ~= 0 then
local usedexpiredef = minetest.registered_items[item].expiration
local expirefactor = (expire - minetest.get_day_count())/usedexpiredef
expirefactor = expirefactor + 1
if expirefactor < -1 then expirefactor = -1 end
if expirefactor > 1 then expirefactor = 1 end
if expirefactor > 0 then
saturation = saturation*expirefactor
else
poisen = poisen + saturation*expirefactor*2
saturation = 0
end
end
if poisen == 0 then poisen = nil end
local func = hbhunger.item_eat(saturation, def.replace, poisen, def.healing, def.sound)
return func(itemstack, user, pointed_thing)
end
end
end)

local foodtable = {
Expand Down
9 changes: 7 additions & 2 deletions mods/hbhunger/hunger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ function hbhunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thi
hp_change = 1
core.log("error", "Wrong on_use() definition for item '" .. item .. "'")
end
def.saturation = hp_change * 1.3
def.saturation = hp_change * 1.5
def.replace = replace_with_item
end
local func = hbhunger.item_eat(def.saturation, def.replace, def.poisen, def.healing, def.sound)
local poisen = def.poisen
if hp_change < 0 then
poisen = hp_change
hp_change = 0
end
local func = hbhunger.item_eat(hp_change*1.5, def.replace, poisen, def.healing, def.sound)
return func(itemstack, user, pointed_thing)
end

Expand Down

0 comments on commit f66a95c

Please sign in to comment.