0
0
Fork 0

Add mcl_hunger API: Set and get hunger

This commit is contained in:
Wuzzy 2017-02-21 15:58:51 +01:00
parent 341e8fadb2
commit 0288f9d0a9
2 changed files with 30 additions and 0 deletions

View File

@ -3,6 +3,19 @@ This API information is WIP. The mod API is still pretty much unofficial;
this mod is mostly seen as standalone for now.
This may change in the future development of MineClone 2. Hopefully.
## Hunger level
The hunger level of the player is a whole number between 0 and 20 inclusive.
0 is starving and 20 is full. The hunger level is represented in
the HUD by a statbar with 20 half-icons.
## Functions
### `mcl_hunger.get_hunger(player)`
Returns the current hunger level of `player` (ObjectRef).
### `mcl_hunger.set_hunger(player, hunger)`
Sets the hunger level of `player` (ObjectRef) to `hunger` immediately.
`hunger` ***must*** be between 0 and 20 inclusive.
## Groups
Items in group `food=3` will make a drinking sound and no particles.
Items in group `food` with any other rating will make an eating sound and particles,

View File

@ -60,6 +60,23 @@ local function update_hud(player)
end
end
-- API START --
mcl_hunger.get_hunger = function(player)
local name = player:get_player_name()
return mcl_hunger.hunger[name]
end
mcl_hunger.set_hunger = function(player, hunger)
local name = player:get_player_name()
mcl_hunger.hunger[name] = hunger
mcl_hunger.set_hunger_raw(player)
update_hud(player)
end
-- END OF API --
-- For internal use only. Don't use the “raw” functions outside of mcl_hunger!
mcl_hunger.get_hunger_raw = function(player)
local inv = player:get_inventory()
if not inv then return nil end