summaryrefslogtreecommitdiff
path: root/legacy.lua
blob: 596ada3a2b061200553fbf0c6a204bc7ed28ddb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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