execute store result score @s ShrinePlayerCurrentXP run xp query @s levels

execute unless items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"]}]] run scoreboard players set @s ShrineXPRequired 4
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:1}]] run scoreboard players set @s ShrineXPRequired 8
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:2}]] run scoreboard players set @s ShrineXPRequired 12
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:3}]] run scoreboard players set @s ShrineXPRequired 16
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:4}]] run scoreboard players set @s ShrineXPRequired 20

execute unless items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"]}]] if score @s ShrinePlayerCurrentXP < @s ShrineXPRequired run tag @s add shrine_fail_no_xp_0
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:1}]] if score @s ShrinePlayerCurrentXP < @s ShrineXPRequired run tag @s add shrine_fail_no_xp_1
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:2}]] if score @s ShrinePlayerCurrentXP < @s ShrineXPRequired run tag @s add shrine_fail_no_xp_2
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:3}]] if score @s ShrinePlayerCurrentXP < @s ShrineXPRequired run tag @s add shrine_fail_no_xp_3
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:4}]] if score @s ShrinePlayerCurrentXP < @s ShrineXPRequired run tag @s add shrine_fail_no_xp_4
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:5}]] run tag @s add shrine_max_level

execute unless items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"]}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run tag @s add shrine_accept
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:1}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run tag @s add shrine_accept
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:2}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run tag @s add shrine_accept
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:3}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run tag @s add shrine_accept
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:4}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run tag @s add shrine_accept

execute unless items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"]}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run xp add @s -4 levels
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:1}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run xp add @s -8 levels
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:2}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run xp add @s -12 levels
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:3}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run xp add @s -16 levels
execute if items entity @s weapon.mainhand *[minecraft:enchantments~[{enchantments:["kiwi:growth"],levels:4}]] if score @s ShrinePlayerCurrentXP >= @s ShrineXPRequired run xp add @s -20 levels

execute unless entity @s[tag=shrine_fail_no_xp_0] unless entity @s[tag=shrine_fail_no_xp_1] unless entity @s[tag=shrine_fail_no_xp_2] unless entity @s[tag=shrine_fail_no_xp_3] unless entity @s[tag=shrine_fail_no_xp_4] unless entity @s[tag=shrine_max_level] if entity @s[tag=shrine_accept] run item modify entity @s weapon.mainhand kiwi:growth_upgrade