diff options
author | BlockMen <nmuelll@web.de> | 2015-04-02 16:08:02 +0200 |
---|---|---|
committer | BlockMen <nmuelll@web.de> | 2015-04-03 12:33:53 +0200 |
commit | 1071c7f13e491b2f3bc09bbbcb1bd6aaed6071c5 (patch) | |
tree | fbc4937b87c213cea5822d8b86eff2cafee36965 /legacy.lua | |
parent | 69a993861ef19f17626c72f6b0f9c03e137c5051 (diff) |
Rewrite mod, push to 2.0
- Seperated hunger -> https://github.com/BlockMen/hunger
- Added API
Diffstat (limited to 'legacy.lua')
-rw-r--r-- | legacy.lua | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/legacy.lua b/legacy.lua new file mode 100644 index 0000000..596ada3 --- /dev/null +++ b/legacy.lua @@ -0,0 +1,61 @@ +-- Armor +function hud.set_armor() +end + +if hud.show_armor then + local shields = minetest.get_modpath("shields") ~= nil + local armor_org_func = armor.update_armor + + local function get_armor_lvl(def) + -- items/protection based display + local lvl = def.level or 0 + local max = 63 -- full diamond armor + if shields then + max = 84.14 -- full diamond armor + diamond shield + end + -- TODO: is there a sane way to read out max values? + local ret = lvl/max + if ret > 1 then + ret = 1 + end + + return tonumber(20 * ret) + end + + function armor.update_armor(self, player) + armor_org_func(self, player) + local name = player:get_player_name() + local def = self.def + local armor_lvl = 0 + if def[name] and def[name].level then + armor_lvl = get_armor_lvl(def[name]) + end + hud.change_item(player, "armor", {number = armor_lvl}) + end +end + +-- Hunger related functions +if not hud.show_hunger then + function hud.set_hunger() + hud.notify_hunger(1, true) + end + + function hud.get_hunger() + hud.notify_hunger(1, true) + end + + function hud.item_eat(hp_change, replace_with_item) + return function(itemstack, user, pointed_thing) + hud.notify_hunger(1, true) + local func = minetest.item_eat(hp_change, replace_with_item) + return func(itemstack, user, pointed_thing) + end + end + + function hud.save_hunger() + hud.notify_hunger(1, true) + end + function hud.load_hunger(player) + hud.notify_hunger(1, true) + end +end |