diff options
author | BlockMen <nmuelll@web.de> | 2015-07-15 01:34:38 +0200 |
---|---|---|
committer | BlockMen <nmuelll@web.de> | 2015-07-15 02:24:17 +0200 |
commit | 12e4fa8a9238b762a7648700952ce8c4208d013c (patch) | |
tree | 4c4b6a6f66ac4baa7320ddfced68344b86aeb943 /functions.lua | |
parent | 2a5acfa7140c2d12ae14abcd91254782360f735e (diff) |
Push to Version 1.1v1.1
Diffstat (limited to 'functions.lua')
-rw-r--r-- | functions.lua | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/functions.lua b/functions.lua index 80f356f..57db844 100644 --- a/functions.lua +++ b/functions.lua @@ -193,6 +193,20 @@ local function poisenp(tick, time, time_left, player) end end +-- wrapper for minetest.item_eat (this way we make sure other mods can't break this one) +local org_eat = core.do_item_eat +core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) + local old_itemstack = itemstack + itemstack = hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) + for _, callback in pairs(core.registered_on_item_eats) do + local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack) + if result then + return result + end + end + return itemstack +end + function hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) local item = itemstack:get_name() local def = food[item] @@ -236,7 +250,20 @@ function hunger.item_eat(hunger_change, replace_with_item, poisen, heal, sound) end minetest.sound_play(sound, {to_player = name, gain = 0.7}) - itemstack:add_item(replace_with_item) + if replace_with_item then + if itemstack:is_empty() then + itemstack:add_item(replace_with_item) + else + 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 return itemstack |