summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlockMen <nmuelll@web.de>2015-07-15 01:34:38 +0200
committerBlockMen <nmuelll@web.de>2015-07-15 02:24:17 +0200
commit12e4fa8a9238b762a7648700952ce8c4208d013c (patch)
tree4c4b6a6f66ac4baa7320ddfced68344b86aeb943
parent2a5acfa7140c2d12ae14abcd91254782360f735e (diff)
Push to Version 1.1v1.1
-rw-r--r--README.txt8
-rw-r--r--changelog.txt9
-rw-r--r--functions.lua29
-rw-r--r--init.lua1
4 files changed, 44 insertions, 3 deletions
diff --git a/README.txt b/README.txt
index c658f6e..a914736 100644
--- a/README.txt
+++ b/README.txt
@@ -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
diff --git a/init.lua b/init.lua
index efbe5e5..d7e872b 100644
--- a/init.lua
+++ b/init.lua
@@ -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)