execute unless entity @e[type=pig,distance=..2] run scoreboard players set @p pigfly_riding 0
execute unless entity @e[type=pig,distance=..2] run scoreboard players set @p pigfly_current 0
execute unless entity @e[type=pig,distance=..2] run scoreboard players set @p pigfly_goal 0
execute unless entity @e[type=pig,distance=..2] run scoreboard players set @p pigfly_input 5
advancement revoke @p only niknok:technical/when_pigs_fly_ad1




execute if score @p pigfly_riding matches 0 run execute if entity @e[type=pig, distance=..0.5, limit=1] run scoreboard players set @p pigfly_riding 1
execute if score @p pigfly_riding matches 1 run execute store result score @p pigfly_current run data get entity @p Pos[1]
execute if score @p pigfly_riding matches 2 run execute store result score @p pigfly_current run data get entity @p Pos[1]

execute if score @p pigfly_riding matches 1 run scoreboard players operation @p pigfly_goal = @p pigfly_current
execute if score @p pigfly_riding matches 1 run scoreboard players operation @p pigfly_goal -= @p pigfly_input
execute if score @p pigfly_riding matches 1 run execute if block ~ ~-1 ~ minecraft:air run execute if block ~ ~-2 ~ minecraft:air run execute if block ~ ~-3 ~ minecraft:air run execute if block ~ ~-4 ~ minecraft:air run execute if block ~ ~-5 ~ minecraft:air run scoreboard players set @p pigfly_riding 2



execute if score @p pigfly_riding matches 2 run execute if score @p pigfly_current <= @p pigfly_goal run advancement grant @p only niknok:minecraft/when_pigs_fly
execute if score @p pigfly_riding matches 2 run execute unless block ~ ~-1 ~ minecraft:air run scoreboard players set @p pigfly_riding 1