
# -> Reset adv trigger
advancement revoke @s only overly_realistic:items/player_use_scribe_book

# -> If player's scribe skill is not high enough then return and warn the player
#execute unless score @s OverlyRealistic.Player.WisdomStats.Scribing matches 5.. run \
    return run \
        function overly_realistic:players/misc/scribe_book/scribe_skill_warning

# -> Add to use counter
scoreboard players add @s OverlyRealistic.Player.ScribeBookTime 1

# -> Cache player shifting bool
scoreboard players set #or.player_shifting OverlyRealistic.General.ArbitraryData 0
execute if predicate overly_realistic:player/actions/player_is_shifting run \
    scoreboard players set #or.player_shifting OverlyRealistic.General.ArbitraryData 1

# -> If player is shifting then show a notification
execute if score #or.player_shifting OverlyRealistic.General.ArbitraryData matches 1 run \
    function overly_realistic:players/misc/scribe_book/scribe_skill_self_notif

# -> Show particles on selected player
tag @s add OverlyRealistic.Player.CurrentScribePlayer
execute unless score #or.player_shifting OverlyRealistic.General.ArbitraryData matches 1 \
    anchored eyes \
    positioned ^ ^ ^ \
    anchored feet \
    positioned ^ ^ ^1.5 \
    positioned ~-0.5 ~-0.5 ~-0.5 \
    at @p[tag=!OverlyRealistic.Player.CurrentScribePlayer,dx=0,dy=0,dz=0] run \
        particle enchant ~ ~1 ~ 0.3 0.5 0.3 0.1 1 force @s
tag @s remove OverlyRealistic.Player.CurrentScribePlayer

# -> If non-passable time then return
execute unless score @s OverlyRealistic.Player.ScribeBookTime matches 40.. run \
    return fail

# -> Reset time
scoreboard players reset @s OverlyRealistic.Player.ScribeBookTime

# -> Get the selected player
tag @s add OverlyRealistic.Player.CurrentScribePlayer
scoreboard players set #or.is_player_present OverlyRealistic.General.ArbitraryData 0
execute unless score #or.player_shifting OverlyRealistic.General.ArbitraryData matches 1 \
    anchored eyes \
    positioned ^ ^ ^ \
    anchored feet \
    positioned ^ ^ ^1.5 \
    positioned ~-0.5 ~-0.5 ~-0.5 \
    store success score #or.is_player_present OverlyRealistic.General.ArbitraryData \
    as @p[tag=!OverlyRealistic.Player.CurrentScribePlayer,dx=0,dy=0,dz=0] run \
        function overly_realistic:players/misc/scribe_book/get_book_detailings
tag @s remove OverlyRealistic.Player.CurrentScribePlayer

execute if score #or.player_shifting OverlyRealistic.General.ArbitraryData matches 1 run \
    function overly_realistic:players/misc/scribe_book/get_book_detailings

# -> Open GUI
execute if score #or.player_shifting OverlyRealistic.General.ArbitraryData matches 1 run \
    return run \
        function overly_realistic:players/misc/scribe_book/open_book_ui with storage overly_realistic:scribing scribe_book_details
execute if score #or.is_player_present OverlyRealistic.General.ArbitraryData matches 1 run \
    function overly_realistic:players/misc/scribe_book/open_book_ui with storage overly_realistic:scribing scribe_book_details
