# Check who has a book
tag @a remove cubc_mo_en_has_book
function cubc/mo_en/book/has_book

# Claim a book
tag @e[type=cubc_mo_en:book] remove cubc_mo_en_claimed
execute as @a[tag=cubc_mo_en_has_book] at @s anchored eyes positioned ^^^0.5 if entity @e[r=5, c=1, type=cubc_mo_en:book, tag=!cubc_mo_en_claimed] run function cubc/mo_en/book/claim
execute as @a[tag=cubc_mo_en_has_book] at @s anchored eyes positioned ^^^0.5 unless entity @e[r=5, c=1, type=cubc_mo_en:book, tag=cubc_mo_en_claimed] run function cubc/mo_en/book/summon

# Delete useless books
event entity @e[type=cubc_mo_en:book, tag=!cubc_mo_en_claimed] cubc_mo_en:despawn

# Go next page
title @a[tag=cubc_mo_en_has_book] actionbar Interact: §3Previous§f | Attack: §6Next§f

# Item cooldown
scoreboard objectives add cubc_mo_en_book_cd dummy
scoreboard players add @a cubc_mo_en_book_cd 0
scoreboard players add @a[scores={cubc_mo_en_book_cd=1..}] cubc_mo_en_book_cd -1