1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-25 21:55:25 +02:00

Add item eat callback

This commit is contained in:
rubenwardy
2014-05-20 15:21:09 +01:00
committed by ShadowNinja
parent ab75b1b923
commit 832d7973c8
3 changed files with 11 additions and 1 deletions

View File

@@ -353,6 +353,12 @@ end
function core.item_eat(hp_change, replace_with_item)
return function(itemstack, user, pointed_thing) -- closure
for _, callback in pairs(core.registered_on_item_eats) do
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
if result then
return result
end
end
if itemstack:take_item() ~= nil then
user:set_hp(user:get_hp() + hp_change)
itemstack:add_item(replace_with_item) -- note: replace_with_item is optional