1
0
Fork 0

Prevent eating most things at full hunger bar

This commit is contained in:
Wuzzy 2017-05-23 02:04:27 +02:00
parent eab0205c2f
commit c2c9a2f4a4
6 changed files with 19 additions and 14 deletions

View File

@ -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) * `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 * `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. * `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 #### Footnotes

View File

@ -152,6 +152,6 @@ minetest.register_craftitem("mcl_core:apple_gold", {
-- TODO: Reduce to 4 when it's ready -- TODO: Reduce to 4 when it's ready
on_place = minetest.item_eat(8), on_place = minetest.item_eat(8),
on_secondary_use = 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, _mcl_saturation = 9.6,
}) })

View File

@ -256,7 +256,7 @@ minetest.register_craftitem("mcl_end:chorus_fruit", {
-- TODO: Teleport player -- TODO: Teleport player
on_place = minetest.item_eat(4), on_place = minetest.item_eat(4),
on_secondary_use = 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, _mcl_saturation = 2.4,
stack_max = 64, stack_max = 64,
}) })

View File

@ -149,7 +149,7 @@ minetest.register_craftitem("mcl_mobitems:milk_bucket", {
return minetest.do_item_eat(0, "bucket:bucket_empty", itemstack, player, pointed_thing) return minetest.do_item_eat(0, "bucket:bucket_empty", itemstack, player, pointed_thing)
end, end,
stack_max = 1, stack_max = 1,
groups = { food = 3 }, groups = { food = 3, can_eat_when_full = 1 },
}) })
minetest.register_craftitem("mcl_mobitems:spider_eye", { minetest.register_craftitem("mcl_mobitems:spider_eye", {

View File

@ -99,7 +99,7 @@ minetest.register_craftitem("mcl_potions:potion_water", {
stack_max = 1, stack_max = 1,
inventory_image = potion_image("#0000FF"), inventory_image = potion_image("#0000FF"),
wield_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) on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under) local node = minetest.get_node(pointed_thing.under)
@ -140,7 +140,7 @@ minetest.register_craftitem("mcl_potions:potion_awkward", {
stack_max = 1, stack_max = 1,
inventory_image = potion_image("#0000FF"), inventory_image = potion_image("#0000FF"),
wield_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_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
on_secondary_use = 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, stack_max = 1,
inventory_image = potion_image("#0000FF"), inventory_image = potion_image("#0000FF"),
wield_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_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
on_secondary_use = 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, stack_max = 1,
inventory_image = potion_image("#0000FF"), inventory_image = potion_image("#0000FF"),
wield_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_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"), on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
}) })

View File

@ -23,15 +23,19 @@ core.do_item_eat = function(hp_change, replace_with_item, itemstack, user, point
-- of the second the player made the first eat. -- of the second the player made the first eat.
-- FIXME: In singleplayer, there's a cheat to circumvent this, simply by pausing the game between eats. -- 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. -- 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 if no_eat_delay or (mcl_hunger.last_eat[name] < 0) or (os.difftime(os.time(), mcl_hunger.last_eat[name]) >= 2) then
itemstack = mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing) local can_eat_when_full = minetest.get_item_group(itemstack:get_name(), "can_eat_when_full") == 1
for _, callback in pairs(core.registered_on_item_eats) do -- Don't allow eating when player has full hunger bar (some exceptional items apply)
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack) if can_eat_when_full or (mcl_hunger.get_hunger(user) < 20) then
if result then itemstack = mcl_hunger.eat(hp_change, replace_with_item, itemstack, user, pointed_thing)
return result for _, callback in pairs(core.registered_on_item_eats) do
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing, old_itemstack)
if result then
return result
end
end end
mcl_hunger.last_eat[name] = os.time()
end end
mcl_hunger.last_eat[name] = os.time()
end end
return itemstack return itemstack