execute if entity @e[scores={ricochet=1..}] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run tag @s add bounce

execute if entity @e[tag=ricochet_1] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] at @s run execute as @e[type=#cartographer_core:hostile,distance=0.1..7,tag=!bounce,limit=1,sort=nearest] at @s run function cartographer_custom_enchantments:loop/enchant_effects/ricochet_bounce_1
execute if entity @e[tag=ricochet_1] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run tag @s remove ricochet_1

execute if entity @e[tag=ricochet_2] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] at @s run execute as @e[type=#cartographer_core:hostile,distance=0.1..7,tag=!bounce,limit=1,sort=nearest] at @s run function cartographer_custom_enchantments:loop/enchant_effects/ricochet_bounce_2
execute if entity @e[tag=ricochet_2] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run tag @s remove ricochet_2

execute if entity @e[tag=ricochet_3] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] at @s run execute as @e[type=#cartographer_core:hostile,distance=0.1..7,tag=!bounce,limit=1,sort=nearest] at @s run function cartographer_custom_enchantments:loop/enchant_effects/ricochet_bounce_3
execute if entity @e[tag=ricochet_3] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run tag @s remove ricochet_3

execute if entity @e[scores={ricochet=1..}] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] at @s run tp @s ~ ~ ~ facing entity @e[type=#cartographer_core:hostile,distance=0.1..7,tag=!bounce,limit=1,sort=nearest] feet
execute if entity @e[scores={ricochet=1..}] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] at @s run execute if entity @e[type=#cartographer_core:hostile,distance=0.1..7,tag=!bounce,limit=1,sort=nearest] run scoreboard players set @s helper_raycast 7
execute if entity @e[scores={ricochet=1..}] run execute if entity @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] run execute as @e[type=#cartographer_core:hostile,limit=1,distance=..5,nbt=!{HurtTime:0s}] at @s positioned ~ ~1 ~ run execute if entity @e[type=#cartographer_core:hostile,distance=0.1..7,tag=!bounce,limit=1,sort=nearest] run function cartographer_custom_enchantments:loop/enchant_effects/ricochet_raycast