# @s = happy ghast
execute if entity @s[tag=Happy_Ghast.Tamed] run return 0

execute at @s as @e[type=minecraft:item,distance=..4,limit=1,sort=nearest] if items entity @s contents minecraft:snow_block if data entity @s Thrower run data modify entity @n[type=minecraft:happy_ghast,distance=..0.01,limit=1,sort=nearest] data.Owner set from entity @s Thrower
execute at @s as @e[type=minecraft:item,distance=..4,limit=1,sort=nearest] if items entity @s contents minecraft:snow_block unless data entity @s Thrower if data entity @s Owner run data modify entity @n[type=minecraft:happy_ghast,distance=..0.01,limit=1,sort=nearest] data.Owner set from entity @s Owner

execute unless data entity @s data.Owner run return 0

execute store result score @s better_happy_ghast.happy_ghast.age run data get entity @s Age

tag @s add Happy_Ghast.Tamed

execute unless entity @s[tag=Happy_Ghast.BetterStats] run function better_happy_ghast:tick/happy_ghast/apply_tamed_attributes

execute at @s as @e[type=minecraft:item,distance=..4,limit=1,sort=nearest] if items entity @s contents minecraft:snow_block run kill @s

execute if score @s better_happy_ghast.happy_ghast.age matches 0.. run particle minecraft:heart ~ ~ ~ 2 2 2 0 40 force
execute unless score @s better_happy_ghast.happy_ghast.age matches 0.. run particle minecraft:heart ~ ~ ~ 0.75 0.75 0.75 0 10 force

function better_happy_ghast:tick/happy_ghast/tame/give_advancement_to_player with entity @s data
