Fix HUD, re-enable hunger
parent
52d97b6a32
commit
4091da81a2
|
@ -15,7 +15,7 @@ default.armor_update_visual = function(player)
|
|||
if textures == "" then textures = "default_armor_trans.png" end
|
||||
default.player_set_textures(player, {"character.png",
|
||||
textures:sub(1),
|
||||
"default_trans.png",--to show no wielded items
|
||||
"default_trans.png",
|
||||
"default_trans.png",
|
||||
})
|
||||
end
|
||||
|
@ -71,13 +71,13 @@ default.armor_update = function(player, heal, list, old_hp)
|
|||
end
|
||||
if default.hud ~= nil then
|
||||
default.hud.armor[name] = lvl*(items*5)
|
||||
default.hud.event_handler(player, "armor_changed")
|
||||
end
|
||||
default.armor_update_visual(player)
|
||||
if heal and heal_max > math.random(100) and player:get_hp() > 0 then
|
||||
--player:set_hp(old_hp)
|
||||
return true
|
||||
end
|
||||
--default.armor_update_visual(player)
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
|
|
|
@ -16,14 +16,14 @@ local armor_hud_bg = {}
|
|||
|
||||
-- default settings
|
||||
-- statbar positions
|
||||
HUD_HEALTH_POS = {x=0.5,y=0.9}
|
||||
HUD_HEALTH_OFFSET = {x=-175, y=2}
|
||||
HUD_HUNGER_POS = {x=0.5,y=0.9}
|
||||
HUD_HUNGER_OFFSET = {x=15, y=2}
|
||||
HUD_AIR_POS = {x=0.5,y=0.9}
|
||||
HUD_AIR_OFFSET = {x=15,y=-15}
|
||||
HUD_ARMOR_POS = {x=0.5,y=0.9}
|
||||
HUD_ARMOR_OFFSET = {x=-175, y=-15}
|
||||
HUD_HEALTH_POS = {x=0.5,y=1}
|
||||
HUD_HEALTH_OFFSET = {x=-262, y=-87}
|
||||
HUD_HUNGER_POS = {x=0.5,y=1}
|
||||
HUD_HUNGER_OFFSET = {x=15, y=-87}
|
||||
HUD_AIR_POS = {x=0.5,y=1}
|
||||
HUD_AIR_OFFSET = {x=15,y=-110}
|
||||
HUD_ARMOR_POS = {x=0.5,y=1}
|
||||
HUD_ARMOR_OFFSET = {x=-262, y=-110}
|
||||
|
||||
HUD_TICK = 0.2
|
||||
HUD_HUNGER_TICK = 300
|
||||
|
@ -33,13 +33,13 @@ if HUD_ENABLE_HUNGER == nil then
|
|||
HUD_ENABLE_HUNGER = minetest.setting_getbool("enable_damage")
|
||||
end
|
||||
|
||||
HUD_SHOW_ARMOR = false
|
||||
if minetest.get_modpath("3d_armor") ~= nil then
|
||||
HUD_SHOW_ARMOR = true
|
||||
HUD_SHOW_ARMOR = minetest.setting_getbool("hud_armor_enable")
|
||||
if HUD_SHOW_ARMOR == nil then
|
||||
HUD_SHOW_ARMOR = minetest.setting_getbool("enable_damage")
|
||||
end
|
||||
|
||||
local function hide_builtin(player)
|
||||
player:hud_set_flags({crosshair = true, hotbar = true, healthbar = false, wielditem = true, breathbar = false})
|
||||
player:hud_set_flags({crosshair = true, hotbar = true, healthbar = false, wielditem = true, breathbar = true})
|
||||
end
|
||||
|
||||
local function custom_hud(player)
|
||||
|
@ -57,7 +57,7 @@ local function custom_hud(player)
|
|||
player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
size = {x=16, y=16},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_hunger_bg.png",
|
||||
number = 20,
|
||||
alignment = {x=-1,y=-1},
|
||||
|
@ -68,7 +68,7 @@ local function custom_hud(player)
|
|||
hunger_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
size = {x=16, y=16},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_hunger_fg.png",
|
||||
number = h,
|
||||
alignment = {x=-1,y=-1},
|
||||
|
@ -79,7 +79,7 @@ local function custom_hud(player)
|
|||
player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
size = {x=16, y=16},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_heart_bg.png",
|
||||
number = 20,
|
||||
alignment = {x=-1,y=-1},
|
||||
|
@ -88,7 +88,7 @@ local function custom_hud(player)
|
|||
health_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
size = {x=16, y=16},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_heart_fg.png",
|
||||
number = player:get_hp(),
|
||||
alignment = {x=-1,y=-1},
|
||||
|
@ -96,22 +96,23 @@ local function custom_hud(player)
|
|||
})
|
||||
|
||||
--air
|
||||
air_hud[name] = player:hud_add({
|
||||
minetest.hud_replace_builtin("breath",
|
||||
{
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_AIR_POS,
|
||||
scale = {x=1, y=1},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_air_fg.png",
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_AIR_OFFSET,
|
||||
})
|
||||
})--air_hud[name] = player:hud_add(
|
||||
|
||||
--armor
|
||||
if HUD_SHOW_ARMOR then
|
||||
armor_hud_bg[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
scale = {x=1, y=1},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_armor_bg.png",
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
|
@ -120,7 +121,7 @@ local function custom_hud(player)
|
|||
armor_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
scale = {x=1, y=1},
|
||||
size = {x=24,y=24},
|
||||
text = "default_hud_armor_fg.png",
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
|
@ -136,22 +137,22 @@ end
|
|||
|
||||
|
||||
--if HUD_ENABLE_HUNGER then dofile(minetest.get_modpath("hud").."/hunger.lua") end
|
||||
if HUD_SHOW_ARMOR then dofile(minetest.get_modpath("hud").."/armor.lua") end
|
||||
--if HUD_SHOW_ARMOR then dofile(minetest.get_modpath("hud").."/armor.lua") end
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
local function update_hud(player)
|
||||
local function update_hud(player, item)
|
||||
local name = player:get_player_name()
|
||||
--air
|
||||
--[[air
|
||||
local air = tonumber(default.hud.air[name])
|
||||
if player:get_breath() ~= air then
|
||||
air = player:get_breath()
|
||||
default.hud.air[name] = air
|
||||
if air > 10 then air = 0 end
|
||||
player:hud_change(air_hud[name], "number", air*2)
|
||||
end
|
||||
end]]
|
||||
--health
|
||||
local hp = tonumber(default.hud.health[name])
|
||||
if player:get_hp() ~= hp then
|
||||
if item == "health" and player:get_hp() ~= hp then
|
||||
if default.armor_update(player, true, false, hp) and hp > 0 then
|
||||
player:set_hp(hp)
|
||||
else
|
||||
|
@ -165,7 +166,7 @@ local function update_hud(player)
|
|||
if not arm_out then arm_out = 0 end
|
||||
local arm = tonumber(default.hud.armor[name])
|
||||
if not arm then arm = 0 end
|
||||
if arm_out ~= arm then
|
||||
if item == "armor" and arm_out ~= arm then
|
||||
default.hud.armor_out[name] = arm
|
||||
player:hud_change(armor_hud[name], "number", arm)
|
||||
if (default.player[name].armor["cnt"] == 0) and arm == 0 then
|
||||
|
@ -177,7 +178,7 @@ local function update_hud(player)
|
|||
--hunger
|
||||
local h_out = tonumber(default.hud.hunger_out[name])
|
||||
local h = tonumber(default.hud.hunger[name])
|
||||
if h_out ~= h then
|
||||
if item == "hunger" and h_out ~= h then
|
||||
default.hud.hunger_out[name] = h
|
||||
-- bar should not have more than 10 icons
|
||||
if h>20 then h=20 end
|
||||
|
@ -185,6 +186,35 @@ local function update_hud(player)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function default.hud.event_handler(player, eventname)
|
||||
if not player then return end
|
||||
|
||||
if eventname == "health_changed" then
|
||||
update_hud(player, "health")
|
||||
--update_armor()
|
||||
return true
|
||||
end
|
||||
|
||||
if eventname == "breath_changed" then
|
||||
--update_hud(player)
|
||||
return true
|
||||
end
|
||||
|
||||
if eventname == "hunger_changed" then
|
||||
update_hud(player, "hunger")
|
||||
return true
|
||||
end
|
||||
|
||||
if eventname == "armor_changed" then
|
||||
update_hud(player, "armor")
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
default.hud.get_hunger = function(player)
|
||||
local inv = player:get_inventory()
|
||||
if not inv then return nil end
|
||||
|
@ -207,10 +237,13 @@ default.hud.set_hunger = function(player)
|
|||
if value < 0 then value = 0 end
|
||||
|
||||
inv:set_stack("hunger", 1, ItemStack({name=":", count=value+1}))
|
||||
default.hud.event_handler(player, "hunger_changed")
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_playerevent(default.hud.event_handler)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local inv = player:get_inventory()
|
||||
|
@ -243,257 +276,3 @@ minetest.register_on_respawnplayer(function(player)
|
|||
default.armor_update(player)
|
||||
end)
|
||||
|
||||
local main_timer = 0
|
||||
local timer = 0
|
||||
local timer2 = 0
|
||||
minetest.after(2.5, function()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
main_timer = main_timer + dtime
|
||||
timer = timer + dtime
|
||||
timer2 = timer2 + dtime
|
||||
if main_timer > HUD_TICK or timer > 4 or timer2 > HUD_HUNGER_TICK then
|
||||
if main_timer > HUD_TICK then main_timer = 0 end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- only proceed if damage is enabled
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
local h = tonumber(default.hud.hunger[name])
|
||||
local hp = player:get_hp()
|
||||
if HUD_ENABLE_HUNGER and timer > 4 then
|
||||
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
||||
if h > 15 and hp > 0 and default.hud.air[name] > 0 then
|
||||
player:set_hp(hp+1)
|
||||
-- or damage player by 1 hp if saturation is < 2 (of 30)
|
||||
elseif h <= 1 and minetest.setting_getbool("enable_damage") then
|
||||
if hp-1 >= 0 then player:set_hp(hp-1) end
|
||||
end
|
||||
end
|
||||
-- lower saturation by 1 point after xx seconds
|
||||
if HUD_ENABLE_HUNGER and timer2 > HUD_HUNGER_TICK then
|
||||
if h > 0 then
|
||||
h = h-1
|
||||
default.hud.hunger[name] = h
|
||||
default.hud.set_hunger(player)
|
||||
end
|
||||
end
|
||||
-- update current armor level
|
||||
if HUD_SHOW_ARMOR then default.hud.get_armor(player) end
|
||||
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
if timer > 4 then timer = 0 end
|
||||
if timer2 > HUD_HUNGER_TICK then timer2 = 0 end
|
||||
end)
|
||||
end)
|
||||
|
||||
--[[
|
||||
local function costum_hud(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
--fancy hotbar
|
||||
if minetest.get_modpath("crafting") == nil then
|
||||
player:hud_set_hotbar_image("default_hud_hotbar.png")
|
||||
player:hud_set_hotbar_selected_image("default_hud_hotbar_selected.png")
|
||||
end
|
||||
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
--hunger
|
||||
if HUD_ENABLE_HUNGER then
|
||||
player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_hunger_bg.png",
|
||||
number = 20,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HUNGER_OFFSET,
|
||||
})
|
||||
|
||||
hunger_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HUNGER_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_hunger_fg.png",
|
||||
number = 20,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HUNGER_OFFSET,
|
||||
})
|
||||
end
|
||||
--health
|
||||
player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_heart_bg.png",
|
||||
number = 20,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
})
|
||||
|
||||
health_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_HEALTH_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_heart_fg.png",
|
||||
number = player:get_hp(),
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_HEALTH_OFFSET,
|
||||
})
|
||||
|
||||
--air
|
||||
air_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_AIR_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_air_fg.png",
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_AIR_OFFSET,
|
||||
})
|
||||
|
||||
--armor
|
||||
if HUD_SHOW_ARMOR then
|
||||
armor_hud_bg[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_armor_bg.png",
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_ARMOR_OFFSET,
|
||||
})
|
||||
|
||||
armor_hud[name] = player:hud_add({
|
||||
hud_elem_type = "statbar",
|
||||
position = HUD_ARMOR_POS,
|
||||
scale = {x=1, y=1},
|
||||
text = "default_hud_armor_fg.png",
|
||||
number = 0,
|
||||
alignment = {x=-1,y=-1},
|
||||
offset = HUD_ARMOR_OFFSET,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function update_hud(player)
|
||||
local name = player:get_player_name()
|
||||
--air
|
||||
local air = tonumber(default.hud.air[name])
|
||||
if player:get_breath() ~= air then
|
||||
air = player:get_breath()
|
||||
default.hud.air[name] = air
|
||||
if air > 10 then air = 0 end
|
||||
player:hud_change(air_hud[name], "number", air*2)
|
||||
end
|
||||
--health
|
||||
local hp = tonumber(default.hud.health[name])
|
||||
if player:get_hp() ~= hp then
|
||||
if default.armor_update(player, true, false, hp) and hp > 0 then
|
||||
player:set_hp(hp)
|
||||
else
|
||||
hp = player:get_hp()
|
||||
default.hud.health[name] = hp
|
||||
player:hud_change(health_hud[name], "number", hp)
|
||||
end
|
||||
end
|
||||
--armor
|
||||
local arm_out = tonumber(default.hud.armor_out[name])
|
||||
if not arm_out then arm_out = 0 end
|
||||
local arm = tonumber(default.hud.armor[name])
|
||||
if not arm then arm = 0 end
|
||||
if arm_out ~= arm then
|
||||
default.hud.armor_out[name] = arm
|
||||
player:hud_change(armor_hud[name], "number", arm)
|
||||
if (default.player[name].armor["cnt"] == 0) and arm == 0 then
|
||||
player:hud_change(armor_hud_bg[name], "number", 0)
|
||||
else
|
||||
player:hud_change(armor_hud_bg[name], "number", 20)
|
||||
end
|
||||
end
|
||||
--hunger
|
||||
local h_out = tonumber(default.hud.hunger_out[name])
|
||||
local h = tonumber(default.hud.hunger[name])
|
||||
if h_out ~= h then
|
||||
default.hud.hunger_out[name] = h
|
||||
-- bar should not have more than 10 icons
|
||||
if h>20 then h=20 end
|
||||
player:hud_change(hunger_hud[name], "number", h)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
default.hud.health[name] = player:get_hp()
|
||||
local air = player:get_breath()
|
||||
default.hud.air[name] = air
|
||||
--if HUD_ENABLE_HUNGER then default.hud.hunger[name] = default.hud.load_hunger(player) end
|
||||
if not default.hud.hunger[name] then
|
||||
default.hud.hunger[name] = 20
|
||||
end
|
||||
default.hud.hunger_out[name] = default.hud.hunger[name]
|
||||
default.hud.armor[name] = 0
|
||||
default.hud.armor_out[name] = 0
|
||||
minetest.after(0.5, function()
|
||||
hide_builtin(player)
|
||||
costum_hud(player)
|
||||
--if HUD_ENABLE_HUNGER then default.hud.save_hunger(player) end
|
||||
default.armor_update(player)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
default.hud.hunger[player:get_player_name()] = 20
|
||||
minetest.after(0.5, function()
|
||||
--if HUD_ENABLE_HUNGER then default.hud.save_hunger(player) end
|
||||
end)
|
||||
end)
|
||||
|
||||
local timer = 0
|
||||
local timer2 = 0
|
||||
minetest.after(2.5, function()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime
|
||||
timer2 = timer2 + dtime
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- only proceed if damage is enabled
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
local h = tonumber(default.hud.hunger[name])
|
||||
local hp = player:get_hp()
|
||||
if HUD_ENABLE_HUNGER and timer > 4 then
|
||||
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
||||
if h > 15 and hp > 0 then
|
||||
player:set_hp(hp+1)
|
||||
-- or damage player by 1 hp if saturation is < 2 (of 30) and player would not die
|
||||
elseif h <= 1 and minetest.setting_getbool("enable_damage") then
|
||||
if hp-1 >= 1 then player:set_hp(hp-1) end
|
||||
end
|
||||
end
|
||||
-- lower saturation by 1 point after xx seconds
|
||||
if HUD_ENABLE_HUNGER and timer2 > HUD_HUNGER_TICK then
|
||||
if h > 1 then
|
||||
h = h-1
|
||||
default.hud.hunger[name] = h
|
||||
--default.hud.save_hunger(player)
|
||||
end
|
||||
end
|
||||
-- update current armor level
|
||||
--if HUD_SHOW_ARMOR then default.hud.get_armor(player) end
|
||||
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
end
|
||||
end
|
||||
|
||||
if timer > 4 then timer = 0 end
|
||||
if timer2 > HUD_HUNGER_TICK then timer2 = 0 end
|
||||
end)
|
||||
end)]]
|
|
@ -0,0 +1,260 @@
|
|||
-- hunger mechanics
|
||||
|
||||
local main_timer = 0
|
||||
local timer = 0
|
||||
local timer2 = 0
|
||||
minetest.after(2.5, function()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
main_timer = main_timer + dtime
|
||||
timer = timer + dtime
|
||||
timer2 = timer2 + dtime
|
||||
if main_timer > HUD_TICK or timer > 4 or timer2 > HUD_HUNGER_TICK then
|
||||
if main_timer > HUD_TICK then main_timer = 0 end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- only proceed if damage is enabled
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
local h = tonumber(default.hud.hunger[name])
|
||||
local hp = player:get_hp()
|
||||
local air = player:get_breath()
|
||||
if HUD_ENABLE_HUNGER and timer > 4 then
|
||||
-- heal player by 1 hp if not dead and saturation is > 15 (of 30)
|
||||
if h > 15 and hp > 0 and air > 0 then
|
||||
player:set_hp(hp+1)
|
||||
-- or damage player by 1 hp if saturation is < 2 (of 30)
|
||||
elseif h <= 1 and minetest.setting_getbool("enable_damage") then
|
||||
if hp-1 >= 0 then player:set_hp(hp-1) end
|
||||
end
|
||||
end
|
||||
-- lower saturation by 1 point after xx seconds
|
||||
if HUD_ENABLE_HUNGER and timer2 > HUD_HUNGER_TICK then
|
||||
if h > 0 then
|
||||
h = h-1
|
||||
default.hud.hunger[name] = h
|
||||
default.hud.set_hunger(player)
|
||||
end
|
||||
end
|
||||
-- update current armor level
|
||||
--if HUD_SHOW_ARMOR then default.hud.get_armor(player) end
|
||||
|
||||
-- update all hud elements
|
||||
--update_hud(player)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
if timer > 4 then timer = 0 end
|
||||
if timer2 > HUD_HUNGER_TICK then timer2 = 0 end
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Poison player
|
||||
local function poisenp(tick, time, time_left, player)
|
||||
time_left = time_left + tick
|
||||
if time_left < time then
|
||||
minetest.after(tick, poisenp, tick, time, time_left, player)
|
||||
end
|
||||
if player:get_hp()-1 > 0 then
|
||||
player:set_hp(player:get_hp()-1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
function default.item_eat(hunger_change, replace_with_item, poisen)
|
||||
return function(itemstack, user, pointed_thing)
|
||||
if itemstack:take_item() ~= nil and user ~= nil then
|
||||
local name = user:get_player_name()
|
||||
local h = tonumber(default.hud.hunger[name])
|
||||
h=h+hunger_change
|
||||
if h>30 then h=30 end
|
||||
default.hud.hunger[name]=h
|
||||
default.hud.set_hunger(user)
|
||||
itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
|
||||
--sound:eat
|
||||
if poisen then
|
||||
poisenp(1.0, poisen, 0, user)
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
local function overwrite(name, hunger_change, replace_with_item, poisen)
|
||||
local tab = minetest.registered_items[name]
|
||||
if tab == nil then return end
|
||||
tab.on_use = default.item_eat(hunger_change, replace_with_item, poisen)
|
||||
minetest.registered_items[name] = tab
|
||||
end
|
||||
|
||||
overwrite("default:apple", 2)
|
||||
if minetest.get_modpath("farming") ~= nil then
|
||||
overwrite("farming:bread", 4)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mobs") ~= nil then
|
||||
overwrite("mobs:meat", 6)
|
||||
overwrite("mobs:meat_raw", 3)
|
||||
overwrite("mobs:rat_cooked", 5)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("moretrees") ~= nil then
|
||||
overwrite("moretrees:coconut_milk", 1)
|
||||
overwrite("moretrees:raw_coconut", 2)
|
||||
overwrite("moretrees:acorn_muffin", 3)
|
||||
overwrite("moretrees:spruce_nuts", 1)
|
||||
overwrite("moretrees:pine_nuts", 1)
|
||||
overwrite("moretrees:fir_nuts", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("dwarves") ~= nil then
|
||||
overwrite("dwarves:beer", 2)
|
||||
overwrite("dwarves:apple_cider", 1)
|
||||
overwrite("dwarves:midus", 2)
|
||||
overwrite("dwarves:tequila", 2)
|
||||
overwrite("dwarves:tequila_with_lime", 2)
|
||||
overwrite("dwarves:sake", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("animalmaterials") ~= nil then
|
||||
overwrite("animalmaterials:milk", 2)
|
||||
overwrite("animalmaterials:meat_raw", 3)
|
||||
overwrite("animalmaterials:meat_pork", 3)
|
||||
overwrite("animalmaterials:meat_beef", 3)
|
||||
overwrite("animalmaterials:meat_chicken", 3)
|
||||
overwrite("animalmaterials:meat_lamb", 3)
|
||||
overwrite("animalmaterials:meat_venison", 3)
|
||||
overwrite("animalmaterials:meat_undead", 3, "", 3)
|
||||
overwrite("animalmaterials:meat_toxic", 3, "", 5)
|
||||
overwrite("animalmaterials:meat_ostrich", 3)
|
||||
overwrite("animalmaterials:fish_bluewhite", 2)
|
||||
overwrite("animalmaterials:fish_clownfish", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("fishing") ~= nil then
|
||||
overwrite("fishing:fish_raw", 2)
|
||||
overwrite("fishing:fish", 4)
|
||||
overwrite("fishing:sushi", 6)
|
||||
overwrite("fishing:shark", 4)
|
||||
overwrite("fishing:shark_cooked", 8)
|
||||
overwrite("fishing:pike", 4)
|
||||
overwrite("fishing:pike_cooked", 8)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("glooptest") ~= nil then
|
||||
overwrite("glooptest:kalite_lump", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("bushes") ~= nil then
|
||||
overwrite("bushes:sugar", 1)
|
||||
overwrite("bushes:strawberry", 2)
|
||||
overwrite("bushes:berry_pie_raw", 3)
|
||||
overwrite("bushes:berry_pie_cooked", 4)
|
||||
overwrite("bushes:basket_pies", 15)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("bushes_classic") then
|
||||
-- bushes_classic mod, as found in the plantlife modpack
|
||||
local berries = {
|
||||
"strawberry",
|
||||
"blackberry",
|
||||
"blueberry",
|
||||
"raspberry",
|
||||
"gooseberry",
|
||||
"mixed_berry"}
|
||||
for _, berry in ipairs(berries) do
|
||||
if berry ~= "mixed_berry" then
|
||||
overwrite("bushes:"..berry, 1)
|
||||
end
|
||||
overwrite("bushes:"..berry.."_pie_raw", 2)
|
||||
overwrite("bushes:"..berry.."_pie_cooked", 5)
|
||||
overwrite("bushes:basket_"..berry, 15)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mushroom") ~= nil then
|
||||
overwrite("mushroom:brown", 1)
|
||||
overwrite("mushroom:red", 1, "", 3)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("docfarming") ~= nil then
|
||||
overwrite("docfarming:carrot", 2)
|
||||
overwrite("docfarming:cucumber", 2)
|
||||
overwrite("docfarming:corn", 2)
|
||||
overwrite("docfarming:potato", 4)
|
||||
overwrite("docfarming:bakedpotato", 5)
|
||||
overwrite("docfarming:raspberry", 3)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("farming_plus") ~= nil then
|
||||
overwrite("farming_plus:carrot_item", 3)
|
||||
overwrite("farming_plus:banana", 2)
|
||||
overwrite("farming_plus:orange_item", 2)
|
||||
overwrite("farming:pumpkin_bread", 4)
|
||||
overwrite("farming_plus:strawberry_item", 2)
|
||||
overwrite("farming_plus:tomato_item", 2)
|
||||
overwrite("farming_plus:potato_item", 4)
|
||||
overwrite("farming_plus:rhubarb_item", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mtfoods") ~= nil then
|
||||
overwrite("mtfoods:dandelion_milk", 1)
|
||||
overwrite("mtfoods:sugar", 1)
|
||||
overwrite("mtfoods:short_bread", 4)
|
||||
overwrite("mtfoods:cream", 1)
|
||||
overwrite("mtfoods:chocolate", 2)
|
||||
overwrite("mtfoods:cupcake", 2)
|
||||
overwrite("mtfoods:strawberry_shortcake", 2)
|
||||
overwrite("mtfoods:cake", 3)
|
||||
overwrite("mtfoods:chocolate_cake", 3)
|
||||
overwrite("mtfoods:carrot_cake", 3)
|
||||
overwrite("mtfoods:pie_crust", 3)
|
||||
overwrite("mtfoods:apple_pie", 3)
|
||||
overwrite("mtfoods:rhubarb_pie", 2)
|
||||
overwrite("mtfoods:banana_pie", 3)
|
||||
overwrite("mtfoods:pumpkin_pie", 3)
|
||||
overwrite("mtfoods:cookies", 2)
|
||||
overwrite("mtfoods:mlt_burger", 5)
|
||||
overwrite("mtfoods:potato_slices", 2)
|
||||
overwrite("mtfoods:potato_chips", 3)
|
||||
--mtfoods:medicine
|
||||
overwrite("mtfoods:casserole", 3)
|
||||
overwrite("mtfoods:glass_flute", 2)
|
||||
overwrite("mtfoods:orange_juice", 2)
|
||||
overwrite("mtfoods:apple_juice", 2)
|
||||
overwrite("mtfoods:apple_cider", 2)
|
||||
overwrite("mtfoods:cider_rack", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("fruit") ~= nil then
|
||||
overwrite("fruit:apple", 2)
|
||||
overwrite("fruit:pear", 2)
|
||||
overwrite("fruit:bananna", 3)
|
||||
overwrite("fruit:orange", 2)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mush45") ~= nil then
|
||||
overwrite("mush45:meal", 4)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("seaplants") ~= nil then
|
||||
overwrite("seaplants:kelpgreen", 1)
|
||||
overwrite("seaplants:kelpbrown", 1)
|
||||
overwrite("seaplants:seagrassgreen", 1)
|
||||
overwrite("seaplants:seagrassred", 1)
|
||||
overwrite("seaplants:seasaladmix", 6)
|
||||
overwrite("seaplants:kelpgreensalad", 1)
|
||||
overwrite("seaplants:kelpbrownsalad", 1)
|
||||
overwrite("seaplants:seagrassgreensalad", 1)
|
||||
overwrite("seaplants:seagrassgreensalad", 1)
|
||||
end
|
||||
|
||||
if minetest.get_modpath("mobfcooking") ~= nil then
|
||||
overwrite("mobfcooking:cooked_pork", 6)
|
||||
overwrite("mobfcooking:cooked_ostrich", 6)
|
||||
overwrite("mobfcooking:cooked_beef", 6)
|
||||
overwrite("mobfcooking:cooked_chicken", 6)
|
||||
overwrite("mobfcooking:cooked_lamb", 6)
|
||||
overwrite("mobfcooking:cooked_venison", 6)
|
||||
overwrite("mobfcooking:cooked_fish", 6)
|
||||
end
|
|
@ -28,6 +28,7 @@ dofile(minetest.get_modpath("default").."/mapgen.lua")
|
|||
dofile(minetest.get_modpath("default").."/player.lua")
|
||||
dofile(minetest.get_modpath("default").."/armor.lua")
|
||||
dofile(minetest.get_modpath("default").."/hud.lua")
|
||||
dofile(minetest.get_modpath("default").."/hunger.lua")
|
||||
dofile(minetest.get_modpath("default").."/torches.lua")
|
||||
dofile(minetest.get_modpath("default").."/trees.lua")
|
||||
|
||||
|
|
Loading…
Reference in New Issue