Files
last-hearth/mods/hearth/interactions.lua
T
2026-11-03 12:41:09 -05:00

27 lines
855 B
Lua
Executable File

-- Player interactions; survival state remains owned by the caller.
return function(hearth)
local function eat(amounts, replacement)
return function(stack, player)
if not player or not player:is_player() then return stack end
local state = hearth.players[player:get_player_name()]
if not state then return stack end
local needed = false
for key, value in pairs(amounts) do
if type(state[key]) == "number" and state[key] < 100 and value > 0 then
needed = true
end
end
if not needed then return stack end
for key, value in pairs(amounts) do
if type(state[key]) == "number" then
state[key] = math.max(0, math.min(100, state[key] + value))
end
end
if replacement then stack:replace(replacement) else stack:take_item() end
return stack
end
end
return {eat = eat}
end