advancement revoke @s only mot_structures:using_chart
advancement revoke @s only mot_structures:unfolding_chart
schedule clear mot_structures:chart_precaution

#if somehow player changed chart from hand in 1 tick, fails function(failstate1)
execute unless items entity @s weapon.* *[minecraft:custom_model_data={strings:["mot:chart"]}] run return fail

#if player uses chart in a dimension thats doesnt corresponding to chart, fails function(failstate2)
execute if items entity @s weapon.offhand *[minecraft:custom_model_data={strings:["mot:chart"]}] unless items entity @s weapon.mainhand *[minecraft:custom_model_data={strings:["mot:chart"]}] if predicate mot_structures:chart_dimension_check2 run return fail
execute if items entity @s weapon.mainhand *[minecraft:custom_model_data={strings:["mot:chart"]}] if predicate mot_structures:chart_dimension_check run return fail

#if everything is correct, generates chart and plays sounds
execute if items entity @s weapon.offhand *[minecraft:custom_model_data={strings:["mot:chart"]}] unless items entity @s weapon.mainhand *[minecraft:custom_model_data={strings:["mot:chart"]}] run loot replace entity @s weapon.offhand loot mot_structures:charts/unfold_chart2
execute if items entity @s weapon.mainhand *[minecraft:custom_model_data={strings:["mot:chart"]}] run loot replace entity @s weapon.mainhand loot mot_structures:charts/unfold_chart

playsound minecraft:entity.villager.work_librarian player @s