fix hunger
parent
c33cc4052c
commit
7d84cda95f
|
@ -30,13 +30,12 @@ function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
|
|||
|
||||
return function(itemstack, user, pointed_thing)
|
||||
|
||||
if itemstack:take_item() ~= nil and user ~= nil then
|
||||
if itemstack:take_item() ~= nil and user ~= nil and not user.is_fake_player then
|
||||
|
||||
local name = user:get_player_name()
|
||||
local h = tonumber(hbhunger.hunger[name])
|
||||
local hp = user:get_hp()
|
||||
|
||||
if user.is_fake_player == false then
|
||||
minetest.sound_play("hbhunger_eat_generic", {
|
||||
object = user,
|
||||
max_hear_distance = 10,
|
||||
|
@ -49,14 +48,12 @@ function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
|
|||
h = h + hunger_change
|
||||
|
||||
if h > 30 then h = 30 end
|
||||
|
||||
hbhunger.hunger[name] = h
|
||||
hbhunger.set_hunger(user)
|
||||
end
|
||||
|
||||
-- Healing
|
||||
if hp < 20 and heal then
|
||||
|
||||
hp = hp + heal
|
||||
|
||||
if hp > 20 then hp = 20 end
|
||||
|
@ -80,20 +77,16 @@ function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
|
|||
local inv = user:get_inventory()
|
||||
|
||||
if inv:room_for_item("main", {name = replace_with_item}) then
|
||||
|
||||
inv:add_item("main", replace_with_item)
|
||||
else
|
||||
local pos = user:getpos()
|
||||
|
||||
pos.y = math.floor(pos.y + 0.5)
|
||||
|
||||
core.add_item(pos, replace_with_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue