mirror of
git://repo.or.cz/minetest_hbhunger.git
synced 2024-12-23 08:20:20 +01:00
Less namespace pollution, rename hunger functions
This commit is contained in:
parent
e8209a0101
commit
4f5d245e85
16
hunger.lua
16
hunger.lua
@ -1,9 +1,9 @@
|
|||||||
-- Keep these for backwards compatibility
|
-- Keep these for backwards compatibility
|
||||||
function hbhunger.save_hunger(player)
|
function hbhunger.save_hunger(player)
|
||||||
hbhunger.set_hunger(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
end
|
end
|
||||||
function hbhunger.load_hunger(player)
|
function hbhunger.load_hunger(player)
|
||||||
hbhunger.get_hunger(player)
|
hbhunger.get_hunger_raw(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- wrapper for minetest.item_eat (this way we make sure other mods can't break this one)
|
-- wrapper for minetest.item_eat (this way we make sure other mods can't break this one)
|
||||||
@ -83,7 +83,7 @@ function hbhunger.item_eat(hunger_change, replace_with_item, poisen, heal)
|
|||||||
h = h + hunger_change
|
h = h + hunger_change
|
||||||
if h > 30 then h = 30 end
|
if h > 30 then h = 30 end
|
||||||
hbhunger.hunger[name] = h
|
hbhunger.hunger[name] = h
|
||||||
hbhunger.set_hunger(user)
|
hbhunger.set_hunger_raw(user)
|
||||||
end
|
end
|
||||||
-- Healing
|
-- Healing
|
||||||
if hp < 20 and heal then
|
if hp < 20 and heal then
|
||||||
@ -427,23 +427,23 @@ function hbhunger.handle_node_actions(pos, oldnode, player, ext)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local exhaus = hbhunger.exhaustion[name]
|
local exhaus = hbhunger.exhaustion[name]
|
||||||
if exhaus == nil then return end
|
if exhaus == nil then return end
|
||||||
local new = HUNGER_EXHAUST_PLACE
|
local new = hbhunger.EXHAUST_PLACE
|
||||||
-- placenode event
|
-- placenode event
|
||||||
if not ext then
|
if not ext then
|
||||||
new = HUNGER_EXHAUST_DIG
|
new = hbhunger.EXHAUST_DIG
|
||||||
end
|
end
|
||||||
-- assume its send by main timer when movement detected
|
-- assume its send by main timer when movement detected
|
||||||
if not pos and not oldnode then
|
if not pos and not oldnode then
|
||||||
new = HUNGER_EXHAUST_MOVE
|
new = hbhunger.EXHAUST_MOVE
|
||||||
end
|
end
|
||||||
exhaus = exhaus + new
|
exhaus = exhaus + new
|
||||||
if exhaus > HUNGER_EXHAUST_LVL then
|
if exhaus > hbhunger.EXHAUST_LVL then
|
||||||
exhaus = 0
|
exhaus = 0
|
||||||
local h = tonumber(hbhunger.hunger[name])
|
local h = tonumber(hbhunger.hunger[name])
|
||||||
h = h - 1
|
h = h - 1
|
||||||
if h < 0 then h = 0 end
|
if h < 0 then h = 0 end
|
||||||
hbhunger.hunger[name] = h
|
hbhunger.hunger[name] = h
|
||||||
hbhunger.set_hunger(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
end
|
end
|
||||||
hbhunger.exhaustion[name] = exhaus
|
hbhunger.exhaustion[name] = exhaus
|
||||||
end
|
end
|
||||||
|
34
init.lua
34
init.lua
@ -21,16 +21,16 @@ hbhunger.poisonings = {}
|
|||||||
-- HUD item ids
|
-- HUD item ids
|
||||||
local hunger_hud = {}
|
local hunger_hud = {}
|
||||||
|
|
||||||
HUNGER_HUD_TICK = 0.1
|
hbhunger.HUD_TICK = 0.1
|
||||||
|
|
||||||
--Some hunger settings
|
--Some hunger settings
|
||||||
hbhunger.exhaustion = {} -- Exhaustion is experimental!
|
hbhunger.exhaustion = {} -- Exhaustion is experimental!
|
||||||
|
|
||||||
HUNGER_HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
|
hbhunger.HUNGER_TICK = 800 -- time in seconds after that 1 hunger point is taken
|
||||||
HUNGER_EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
|
hbhunger.EXHAUST_DIG = 3 -- exhaustion increased this value after digged node
|
||||||
HUNGER_EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
|
hbhunger.EXHAUST_PLACE = 1 -- exhaustion increased this value after placed
|
||||||
HUNGER_EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
|
hbhunger.EXHAUST_MOVE = 0.3 -- exhaustion increased this value if player movement detected
|
||||||
HUNGER_EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
|
hbhunger.EXHAUST_LVL = 160 -- at what exhaustion player satiation gets lowerd
|
||||||
|
|
||||||
|
|
||||||
--load custom settings
|
--load custom settings
|
||||||
@ -41,7 +41,7 @@ if set then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function custom_hud(player)
|
local function custom_hud(player)
|
||||||
hb.init_hudbar(player, "satiation", hbhunger.get_hunger(player))
|
hb.init_hudbar(player, "satiation", hbhunger.get_hunger_raw(player))
|
||||||
end
|
end
|
||||||
|
|
||||||
dofile(minetest.get_modpath("hbhunger").."/hunger.lua")
|
dofile(minetest.get_modpath("hbhunger").."/hunger.lua")
|
||||||
@ -61,7 +61,7 @@ local function update_hud(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
hbhunger.get_hunger = function(player)
|
hbhunger.get_hunger_raw = function(player)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
if not inv then return nil end
|
if not inv then return nil end
|
||||||
local hgp = inv:get_stack("hunger", 1):get_count()
|
local hgp = inv:get_stack("hunger", 1):get_count()
|
||||||
@ -74,7 +74,7 @@ hbhunger.get_hunger = function(player)
|
|||||||
return hgp-1
|
return hgp-1
|
||||||
end
|
end
|
||||||
|
|
||||||
hbhunger.set_hunger = function(player)
|
hbhunger.set_hunger_raw = function(player)
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local value = hbhunger.hunger[name]
|
local value = hbhunger.hunger[name]
|
||||||
@ -91,19 +91,19 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
inv:set_size("hunger",1)
|
inv:set_size("hunger",1)
|
||||||
hbhunger.hunger[name] = hbhunger.get_hunger(player)
|
hbhunger.hunger[name] = hbhunger.get_hunger_raw(player)
|
||||||
hbhunger.hunger_out[name] = hbhunger.hunger[name]
|
hbhunger.hunger_out[name] = hbhunger.hunger[name]
|
||||||
hbhunger.exhaustion[name] = 0
|
hbhunger.exhaustion[name] = 0
|
||||||
hbhunger.poisonings[name] = 0
|
hbhunger.poisonings[name] = 0
|
||||||
custom_hud(player)
|
custom_hud(player)
|
||||||
hbhunger.set_hunger(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
-- reset hunger (and save)
|
-- reset hunger (and save)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
hbhunger.hunger[name] = 20
|
hbhunger.hunger[name] = 20
|
||||||
hbhunger.set_hunger(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
hbhunger.exhaustion[name] = 0
|
hbhunger.exhaustion[name] = 0
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -114,8 +114,8 @@ minetest.register_globalstep(function(dtime)
|
|||||||
main_timer = main_timer + dtime
|
main_timer = main_timer + dtime
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
timer2 = timer2 + dtime
|
timer2 = timer2 + dtime
|
||||||
if main_timer > HUNGER_HUD_TICK or timer > 4 or timer2 > HUNGER_HUNGER_TICK then
|
if main_timer > hbhunger.HUD_TICK or timer > 4 or timer2 > hbhunger.HUNGER_TICK then
|
||||||
if main_timer > HUNGER_HUD_TICK then main_timer = 0 end
|
if main_timer > hbhunger.HUD_TICK then main_timer = 0 end
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in ipairs(minetest.get_connected_players()) do
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
@ -131,11 +131,11 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- lower satiation by 1 point after xx seconds
|
-- lower satiation by 1 point after xx seconds
|
||||||
if timer2 > HUNGER_HUNGER_TICK then
|
if timer2 > hbhunger.HUNGER_TICK then
|
||||||
if h > 0 then
|
if h > 0 then
|
||||||
h = h-1
|
h = h-1
|
||||||
hbhunger.hunger[name] = h
|
hbhunger.hunger[name] = h
|
||||||
hbhunger.set_hunger(player)
|
hbhunger.set_hunger_raw(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if timer > 4 then timer = 0 end
|
if timer > 4 then timer = 0 end
|
||||||
if timer2 > HUNGER_HUNGER_TICK then timer2 = 0 end
|
if timer2 > hbhunger.HUNGER_TICK then timer2 = 0 end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user