aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2014-05-20 15:21:09 +0100
committerShadowNinja <shadowninja@minetest.net>2014-05-26 18:41:58 -0400
commit832d7973c8028d743eb331cb3d499692cebdc724 (patch)
treec7f8fd191e5d981b3fc71c7ee726fe86dc158854 /builtin
parentab75b1b923db157a7d05c5498456a0fd1faee883 (diff)
downloadminetest-832d7973c8028d743eb331cb3d499692cebdc724.tar.gz
minetest-832d7973c8028d743eb331cb3d499692cebdc724.tar.bz2
minetest-832d7973c8028d743eb331cb3d499692cebdc724.zip
Add item eat callback
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/item.lua6
-rw-r--r--builtin/game/register.lua3
2 files changed, 8 insertions, 1 deletions
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index 8fd172aab..11a36bdc3 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -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
diff --git a/builtin/game/register.lua b/builtin/game/register.lua
index 8908f51f6..1c9e62422 100644
--- a/builtin/game/register.lua
+++ b/builtin/game/register.lua
@@ -8,7 +8,7 @@ local register_item_raw = core.register_item_raw
core.register_item_raw = nil
local register_alias_raw = core.register_alias_raw
-core.register_item_raw = nil
+core.register_alias_raw = nil
--
-- Item / entity / ABM registration functions
@@ -407,4 +407,5 @@ core.registered_on_cheats, core.register_on_cheat = make_registration()
core.registered_on_crafts, core.register_on_craft = make_registration()
core.registered_craft_predicts, core.register_craft_predict = make_registration()
core.registered_on_protection_violation, core.register_on_protection_violation = make_registration()
+core.registered_on_item_eats, core.register_on_item_eat = make_registration()