#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Collect pumpkin
scoreboard players add @e[tag=pumpkin] time 0
execute unless score $game_type main matches 1 at @a[scores={getpumpkin=1..}] as @e[tag=pumpkin,distance=..6,nbt={HurtTime:10s},scores={time=0}] run function f:game/pumpkin/get
execute as @e[tag=pumpkin,scores={time=1..}] at @s run function f:game/pumpkin/animation
scoreboard players set @a getpumpkin 0

#Pumpkin
execute as @a[team=spec] at @s if entity @e[tag=pumpkin,distance=..0.1] run spectate
execute as @a[team=spec] at @s if entity @e[tag=pumpkin,distance=..0.1] run tp @s ~ ~0.6 ~

execute as @e[tag=pumpkin] at @s unless block ~ ~1 ~ air run particle minecraft:flame ~ ~1.8 ~ 0.1 0.1 0.1 0.01 1
execute as @e[tag=pumpkin_dropped] at @s run function f:game/pumpkin/dropped

effect give @e[tag=pumpkin] minecraft:invisibility 1000000 100 true
effect give @e[tag=pumpkin] minecraft:instant_damage 1000000 100 true

#Pumpkins count
scoreboard players set $core p_left 0
execute store result score $core p_left if entity @e[tag=pumpkin,scores={time=..0}]
execute unless score $core p_left = $core p_left_prev run function f:game/pumpkin/counter
scoreboard players operation $core p_left_prev = $core p_left