minetest/minetest — pull request #1318 by rubenwardy (2014-05-20 14:23:11+00:00)
Title: Add item eat callback

This pull request, as requested in this thread, adds a callback to builtin item eat function.

**Current Problem**
Currently, modders need to override the nodedef.on_use function in the food they want to support, which requires a list of foods and their values.

**Solution**
With this pull request, modders can just add a callback to minetest.item_eat and then override the default eat behaviour. They do not need a list of foods and their values.

**The API**
The call back is registered using minetest.register_on_item_eat, and will look like the following.

```
minetest.register_on_item_eat(
function(hp_change, replace_with_item, itemstack, user, pointed_thing)
if itemstack:take_item() ~= nil then
hunger.changeHunger(hp_change)
end
return itemstack
end
)
```

**Why is this useful? Why can't they just add it to on_use?**
This is not useful if you create the food in your own mod. However, it is useful if you want to override how food is handled in other mods. For example, adding hunger, diets and immersive sound. It means you don't need to have a list of foods and their values.

Old pull: #1255