Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Push to Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockMen committed Jul 15, 2015
1 parent 2a5acfa commit 12e4fa8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
8 changes: 7 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Minetest mod "Hunger"
=====================
Version: 1.0
Version: 1.1

(c) Copyright BlockMen (2015)

Expand All @@ -19,6 +19,12 @@ Information:
This mod depends on the "Better HUD" mod (https://github.com/BlockMen/hud) to provide information about your current saturation.


For Modders:
~~~~~~~~~~~~
This mod alters the behavior of minetest.item_eat().
All callbacks that are registered via minetest.register_on_item_eat() are called AFTER this mod actions, so the itemstack
will have changed already when callbacks are called. You can get the original itemstack as 6th parameter of your function then.

License:
~~~~~~~~
(c) Copyright BlockMen (2015)
Expand Down
9 changes: 9 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
- Added API to register food
- Added eating sounds
- Hungerbar image changes when poisend

1.1
---
- Fixed healing after death
- Fixed healing while drowning
- Fixed crashed caused by Pipeworks mod
- Added wrapper for minetest.item_eat(). see Readme.txt for more informations
- Updated HUD-API usage
- Added beans of Farming Redo
29 changes: 28 additions & 1 deletion functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ if minetest.setting_getbool("enable_damage") then
-- for exhaustion
minetest.register_on_placenode(hunger.handle_node_actions)
minetest.register_on_dignode(hunger.handle_node_actions)
minetest.register_on_item_eat(hunger.eat)
minetest.register_on_respawnplayer(function(player)
hunger.update_hunger(player, 20)
end)
Expand Down

0 comments on commit 12e4fa8

Please sign in to comment.