mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Prevent eating most things at full hunger bar
This commit is contained in:
parent
eab0205c2f
commit
c2c9a2f4a4
6 changed files with 19 additions and 14 deletions
|
@ -46,6 +46,7 @@ Please read <http://minecraft.gamepedia.com/Breaking> to learn how digging times
|
|||
* `disable_suffocation=1`: Disables suffocation for full solid cubes (1)
|
||||
* `destroys_items=1`: If an item happens to be *inside* this node, the item will be destroyed
|
||||
* `no_eat_delay=1`: Only for foodstuffs. When eating this, all eating delays are ignored.
|
||||
* `can_eat_when_full=1`: Only for foodstuffs. This item can be eaten when the user has a full hunger bar
|
||||
|
||||
#### Footnotes
|
||||
|
||||
|
|
|
@ -152,6 +152,6 @@ minetest.register_craftitem("mcl_core:apple_gold", {
|
|||
-- TODO: Reduce to 4 when it's ready
|
||||
on_place = minetest.item_eat(8),
|
||||
on_secondary_use = minetest.item_eat(8),
|
||||
groups = { food = 2, eatable = 8 },
|
||||
groups = { food = 2, eatable = 8, can_eat_when_full = 1 },
|
||||
_mcl_saturation = 9.6,
|
||||
})
|
||||
|
|
|
@ -256,7 +256,7 @@ minetest.register_craftitem("mcl_end:chorus_fruit", {
|
|||
-- TODO: Teleport player
|
||||
on_place = minetest.item_eat(4),
|
||||
on_secondary_use = minetest.item_eat(4),
|
||||
groups = { food = 2, eatable = 4 },
|
||||
groups = { food = 2, eatable = 4, can_eat_when_full = 1 },
|
||||
_mcl_saturation = 2.4,
|
||||
stack_max = 64,
|
||||
})
|
||||
|
|
|
@ -149,7 +149,7 @@ minetest.register_craftitem("mcl_mobitems:milk_bucket", {
|
|||
return minetest.do_item_eat(0, "bucket:bucket_empty", itemstack, player, pointed_thing)
|
||||
end,
|
||||
stack_max = 1,
|
||||
groups = { food = 3 },
|
||||
groups = { food = 3, can_eat_when_full = 1 },
|
||||
})
|
||||
|
||||
minetest.register_craftitem("mcl_mobitems:spider_eye", {
|
||||
|
|
|
@ -99,7 +99,7 @@ minetest.register_craftitem("mcl_potions:potion_water", {
|
|||
stack_max = 1,
|
||||
inventory_image = potion_image("#0000FF"),
|
||||
wield_image = potion_image("#0000FF"),
|
||||
groups = {brewitem=1, food=3},
|
||||
groups = {brewitem=1, food=3, can_eat_when_full=1},
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
|
@ -140,7 +140,7 @@ minetest.register_craftitem("mcl_potions:potion_awkward", {
|
|||
stack_max = 1,
|
||||
inventory_image = potion_image("#0000FF"),
|
||||
wield_image = potion_image("#0000FF"),
|
||||
groups = {brewitem=1, food=3},
|
||||
groups = {brewitem=1, food=3, can_eat_when_full=1},
|
||||
on_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
|
||||
on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
|
||||
})
|
||||
|
@ -151,7 +151,7 @@ minetest.register_craftitem("mcl_potions:potion_mundane", {
|
|||
stack_max = 1,
|
||||
inventory_image = potion_image("#0000FF"),
|
||||
wield_image = potion_image("#0000FF"),
|
||||
groups = {brewitem=1, food=3},
|
||||
groups = {brewitem=1, food=3, can_eat_when_full=1},
|
||||
on_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
|
||||
on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
|
||||
})
|
||||
|
@ -162,7 +162,7 @@ minetest.register_craftitem("mcl_potions:potion_thick", {
|
|||
stack_max = 1,
|
||||
inventory_image = potion_image("#0000FF"),
|
||||
wield_image = potion_image("#0000FF"),
|
||||
groups = {brewitem=1, food=3},
|
||||
groups = {brewitem=1, food=3, can_eat_when_full=1},
|
||||
on_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
|
||||
on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
|
||||
})
|
||||
|
|
|
@ -24,6 +24,9 @@ core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, point
|
|||
-- FIXME: In singleplayer, there's a cheat to circumvent this, simply by pausing the game between eats.
|
||||
-- This is because os.time() obviously does not care about the pause. A fix needs a different timer mechanism.
|
||||
if no_eat_delay or (mcl_hunger.last_eat[name] < 0) or (os.difftime(os.time(), mcl_hunger.last_eat[name]) >= 2) then
|
||||
local can_eat_when_full = minetest.get_item_group(itemstack:get_name(), "can_eat_when_full") == 1
|
||||
-- Don't allow eating when player has full hunger bar (some exceptional items apply)
|
||||
if can_eat_when_full or (mcl_hunger.get_hunger(user) < 20) then
|
||||
itemstack = mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||
for _, callback in pairs(core.registered_on_item_eats) do
|
||||
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack)
|
||||
|
@ -33,6 +36,7 @@ core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, point
|
|||
end
|
||||
mcl_hunger.last_eat[name] = os.time()
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue