Hunger: add poison API
This commit is contained in:
parent
862ed96826
commit
0a69c859c7
@ -39,8 +39,8 @@ hunger.settings = {
|
||||
exhaust_dig = get_setting("exhaust_dig", 2),
|
||||
exhaust_place = get_setting("exhaust_place", 1),
|
||||
exhaust_move = get_setting("exhaust_move", 2),
|
||||
exhaust_jump = get_setting("exhaust_jump", 3),
|
||||
exhaust_craft = get_setting("exhaust_craft", 1),
|
||||
exhaust_jump = get_setting("exhaust_jump", 4),
|
||||
exhaust_craft = get_setting("exhaust_craft", 2),
|
||||
exhaust_punch = get_setting("exhaust_punch", 5),
|
||||
exhaust_lvl = get_setting("exhaust_lvl", 192),
|
||||
heal = get_setting("heal", 1),
|
||||
@ -48,7 +48,7 @@ hunger.settings = {
|
||||
starve = get_setting("starve", 1),
|
||||
starve_lvl = get_setting("starve_lvl", 3),
|
||||
level_max = get_setting("level_max", 21),
|
||||
visual_max = get_setting("visual_max", 20),
|
||||
visual_max = get_setting("visual_max", 20)
|
||||
}
|
||||
local settings = hunger.settings
|
||||
|
||||
@ -308,9 +308,9 @@ local function hunger_globaltimer(dtime)
|
||||
end
|
||||
end
|
||||
|
||||
function core.do_item_eat(hp_change, replace_with_item, itemstack, player, pointed_thing)
|
||||
function core.do_item_eat(hp_change, replace_with_item, poison, itemstack, player, pointed_thing)
|
||||
for _, callback in ipairs(core.registered_on_item_eats) do
|
||||
local result = callback(hp_change, replace_with_item, itemstack, player, pointed_thing)
|
||||
local result = callback(hp_change, replace_with_item, poison, itemstack, player, pointed_thing)
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
@ -320,13 +320,12 @@ function core.do_item_eat(hp_change, replace_with_item, itemstack, player, point
|
||||
return itemstack
|
||||
end
|
||||
|
||||
if hp_change > 0 then
|
||||
if not poison then
|
||||
hunger.change_saturation(player, hp_change)
|
||||
hunger.set_exhaustion(player, 0)
|
||||
else
|
||||
-- assume hp_change < 0.
|
||||
hunger.change_saturation(player, -hp_change)
|
||||
hunger.poison(player, -hp_change, settings.poison_tick)
|
||||
hunger.change_saturation(player, hp_change)
|
||||
hunger.poison(player, -poison, settings.poison_tick)
|
||||
end
|
||||
|
||||
itemstack:take_item()
|
||||
|
@ -557,7 +557,7 @@ function core.item_drop(itemstack, dropper, pos)
|
||||
end
|
||||
|
||||
local enable_damage = minetest.settings:get_bool("enable_damage")
|
||||
function core.item_eat(hp_change, replace_with_item)
|
||||
function core.item_eat(hp_change, replace_with_item, poison)
|
||||
return function(itemstack, user, pointed_thing) -- closure
|
||||
if user then
|
||||
local pos = user:get_pos()
|
||||
@ -583,7 +583,7 @@ function core.item_eat(hp_change, replace_with_item)
|
||||
})
|
||||
core.sound_play("player_eat", {pos = pos, max_hear_distance = 10, gain = 0.3})
|
||||
if enable_damage then
|
||||
return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||
return core.do_item_eat(hp_change, replace_with_item, poison, itemstack, user, pointed_thing)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -886,8 +886,8 @@ hunger.poison_tick (time in seconds between poison damage)
|
||||
hunger.exhaust_dig (exhaustion for digging a node) float 3
|
||||
hunger.exhaust_place (exhaustion for placing a node) float 1
|
||||
hunger.exhaust_move (exhaustion for moving) float 2
|
||||
hunger.exhaust_jump (exhaustion for jumping) float 3
|
||||
hunger.exhaust_craft (exhaustion for crafting) float 1
|
||||
hunger.exhaust_jump (exhaustion for jumping) float 4
|
||||
hunger.exhaust_craft (exhaustion for crafting) float 2
|
||||
hunger.exhaust_punch (exhaustion for punching) float 5
|
||||
hunger.exhaust_lvl (exhaustion level at which saturation gets lowered) float 192
|
||||
hunger.heal (amount of HP a player gains per hunger.health_tick) int 1 0 20
|
||||
|
@ -2461,7 +2461,7 @@ Call these functions only at load time!
|
||||
* The provided function should check that the position is protected by the mod
|
||||
calling this function before it prints a message, if it does, to allow for
|
||||
multiple protection mods.
|
||||
* `minetest.register_on_item_eat(func(hp_change, replace_with_item, itemstack, user, pointed_thing))`
|
||||
* `minetest.register_on_item_eat(func(hp_change, replace_with_item, poison, itemstack, user, pointed_thing))`
|
||||
* Called when an item is eaten, by `minetest.item_eat`
|
||||
* Return `true` or `itemstack` to cancel the default item eat response (i.e.: hp increase)
|
||||
|
||||
@ -2766,7 +2766,7 @@ and `minetest.auth_reload` call the authetification handler.
|
||||
by default they will be sent to every player (even if not used).
|
||||
Note that this parameter is mostly just a workaround and will be removed in future releases.
|
||||
* Creates a detached inventory. If it already exists, it is cleared.
|
||||
* `minetest.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing)`:
|
||||
* `minetest.do_item_eat(hp_change, replace_with_item, poison, itemstack, user, pointed_thing)`:
|
||||
returns left over ItemStack
|
||||
* See `minetest.item_eat` and `minetest.register_on_item_eat`
|
||||
|
||||
@ -2905,11 +2905,12 @@ These functions return the leftover itemstack.
|
||||
* returns `itemstack, success`
|
||||
* `minetest.item_drop(itemstack, dropper, pos)`
|
||||
* Drop the item
|
||||
* `minetest.item_eat(hp_change, replace_with_item)`
|
||||
* `minetest.item_eat(hp_change, replace_with_item, poison)`
|
||||
* Eat the item.
|
||||
* `replace_with_item` is the itemstring which is added to the inventory.
|
||||
If the player is eating a stack, then replace_with_item goes to a
|
||||
different spot. Can be `nil`
|
||||
* `poison` is the value is how much health the player will lose due to poisoning.
|
||||
* See `minetest.do_item_eat`
|
||||
|
||||
### Defaults for the `on_punch` and `on_dig` node definition callbacks
|
||||
|
Loading…
x
Reference in New Issue
Block a user