diff options
| -rw-r--r-- | README.txt | 8 | ||||
| -rw-r--r-- | changelog.txt | 9 | ||||
| -rw-r--r-- | functions.lua | 29 | ||||
| -rw-r--r-- | init.lua | 1 | 
4 files changed, 44 insertions, 3 deletions
| @@ -1,6 +1,6 @@  Minetest mod "Hunger"  ===================== -Version: 1.0 +Version: 1.1  (c) Copyright BlockMen (2015) @@ -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) diff --git a/changelog.txt b/changelog.txt index ba79ce2..c8a7aa8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 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 @@ -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) | 
