# Allow to eat
execute store result score hp food_craving run data get entity @s Health
execute store result score max_hp food_craving run attribute @s generic.max_health get

execute if score hp food_craving = max_hp food_craving run effect give @s[scores={food_craving=140..},nbt={foodLevel:20}] hunger 1 255 true
execute if score hp food_craving < max_hp food_craving run effect clear @s[scores={food_craving=140..}] hunger
effect clear @s[scores={food_craving=140..},nbt=!{foodLevel:20}] hunger

# Food craving
tellraw @s[scores={food_craving=20}] ["",{"text":"[!] ","color":"dark_red","bold":true},{"translate":"endless_food_crate.msg","color":"gray"}]
effect give @s[scores={food_craving=0}] hunger 6 255
execute if entity @s[scores={food_craving=-60}] run function items:passive/endless_food_crate/next_craving

scoreboard players remove @s food_craving 1
