tag @s add BookInHand

#execute as @a[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run execute at @s positioned ~ 255 ~ run setblock ~ ~ ~ minecraft:brown_shulker_box
execute as @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run execute at @s positioned ~ 255 ~ run setblock ~ ~ ~ minecraft:chest destroy
execute as @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run execute at @s positioned ~ 255 ~ run data modify block ~ ~ ~ Items append from entity @s SelectedItem
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=CobbleSpell] run data modify block ~ 255 ~ Items[0].tag.pages[4] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[4]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=GlassGen] run data modify block ~ 255 ~ Items[0].tag.pages[5] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[5]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=HasteSpell] run data modify block ~ 255 ~ Items[0].tag.pages[6] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[6]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=SlowFallSpell] run data modify block ~ 255 ~ Items[0].tag.pages[7] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[7]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=ResistSpell] run data modify block ~ 255 ~ Items[0].tag.pages[8] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[8]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=EscapeSpell] run data modify block ~ 255 ~ Items[0].tag.pages[9] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[9]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=LocateSpell] run data modify block ~ 255 ~ Items[0].tag.pages[10] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[10]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=HorseSpell] run data modify block ~ 255 ~ Items[0].tag.pages[11] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[11]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=WeatherSpell] run data modify block ~ 255 ~ Items[0].tag.pages[12] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[12]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=InvisSpell] run data modify block ~ 255 ~ Items[0].tag.pages[13] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[13]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=PortalSpell] run data modify block ~ 255 ~ Items[0].tag.pages[14] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[14]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=AnimalSpell] run data modify block ~ 255 ~ Items[0].tag.pages[15] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[15]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=ExpSpell] run data modify block ~ 255 ~ Items[0].tag.pages[16] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[16]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=BasicRevSpell] run data modify block ~ 255 ~ Items[0].tag.pages[31] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[31]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=ResurrectSpell] run data modify block ~ 255 ~ Items[0].tag.pages[32] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[32]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=ImbueSpell] run data modify block ~ 255 ~ Items[0].tag.pages[42] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[42]
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate,tag=RageSpell] run data modify block ~ 255 ~ Items[0].tag.pages[43] set from entity @e[name=BookCopy,limit=1,type=minecraft:armor_stand] HandItems[0].tag.pages[43]


tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=CobbleSpell,tag=BookInHand] remove CobbleSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=GlassGen,tag=BookInHand] remove GlassGen
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=HasteSpell,tag=BookInHand] remove HasteSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=HasteUpgrade,tag=BookInHand] remove HasteUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=SlowFallSpell,tag=BookInHand] remove SlowFallSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=SlowfallUpgrade,tag=BookInHand] remove SlowfallUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=ResistSpell,tag=BookInHand] remove ResistSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=ResistUpgrade,tag=BookInHand] remove ResistUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=EscapeSpell,tag=BookInHand] remove EscapeSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=EscapeUpgrade,tag=BookInHand] remove EscapeUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=LocateSpell,tag=BookInHand] remove LocateSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=LocatorUpgrade,tag=BookInHand] remove LocatorUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=HorseSpell,tag=BookInHand] remove HorseSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=HorseUpgrade,tag=BookInHand] remove HorseUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=WeatherSpell,tag=BookInHand] remove WeatherSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=InvisSpell,tag=BookInHand] remove InvisSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=InvisUpgrade,tag=BookInHand] remove InvisUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=PortalSpell,tag=BookInHand] remove PortalSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=AnimalSpell,tag=BookInHand] remove AnimalSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=FarmUpgrade,tag=BookInHand] remove FarmUpgrade
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=ExpSpell,tag=BookInHand] remove ExpSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BasicRevSpell,tag=BookInHand] remove BasicRevSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BasicRevSpell,tag=BookInHand] remove ResurrectSpell

tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=ImbueSpell,tag=BookInHand] remove ImbueSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=RageSpell,tag=BookInHand] remove RageSpell
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookInHand] add SpellUpdateRemove
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookInHand] remove SpellUpdate
tag @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookInHand,tag=BookUpdate] add BookUpdate2

#execute at @a[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run loot replace entity @p weapon.mainhand mine ~ 255 ~ air{drop_contents:true}
execute as @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},nbt=!{SelectedItem:{tag:{kyunewbook:1b,display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run function zzzzdonotuse:spell/updateold

execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run item replace entity @s weapon.mainhand from block ~ 255 ~ container.0
execute at @s[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run fill ~ 255 ~ ~ 255 ~ air

#execute as @s[tag=BookUpdate] run execute at @s positioned ~ 255 ~ run tp @e[distance=..8,sort=nearest,limit=1,nbt=!{Item:{id:"minecraft:chest"}}] @s
#execute as @s[tag=BookUpdate] run execute at @s positioned ~ 255 ~ run kill @e[distance=..8,sort=nearest,limit=1,nbt={Item:{id:"minecraft:chest"}}]
#execute at @a[nbt={SelectedItem:{tag:{display:{Lore:["\"A book of spells\""]}}}},tag=BookUpdate] run setblock ~ 255 ~ air
tag @s[tag=BookUpdate2] remove BookUpdate
tag @s[tag=BookUpdate2] remove BookUpdate2
tag @s remove BookInHand