#Start
/scoreboard teams join pc_play @a[x=1013,y=102,z=1000,r=2]
#Teleport players to areas
/tp @r[x=1013,y=102,z=1000,r=2] 990 101 1000 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 990 101 1030 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 990 101 1060 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 990 101 970 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 990 101 940 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 1040 101 1000 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 1040 101 1030 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 1040 101 1060 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 1040 101 970 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 1040 101 940 90 -18
/tp @r[x=1013,y=102,z=1000,r=2] 1090 101 1000 90 -18
#Select pumpkins for the round
/scoreboard players tag @r[type=minecraft:armor_stand,name=pc_Marker,tag=!pc_Done] add pc_Selected

/execute @e[type=minecraft:armor_stand,tag=pc_Selected] ~ ~ ~ /clone ~ ~ ~ ~9 ~9 ~9 980 80 1000
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] add pc_Done
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] remove pc_Selected
/scoreboard players tag @r[type=minecraft:armor_stand,name=pc_Marker,tag=!pc_Done] add pc_Selected
/execute @e[type=minecraft:armor_stand,tag=pc_Selected] ~ ~ ~ /clone ~ ~ ~ ~9 ~9 ~9 990 80 1000
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] add pc_Done
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] remove pc_Selected
/scoreboard players tag @r[type=minecraft:armor_stand,name=pc_Marker,tag=!pc_Done] add pc_Selected
/execute @e[type=minecraft:armor_stand,tag=pc_Selected] ~ ~ ~ /clone ~ ~ ~ ~9 ~9 ~9 1000 80 1000
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] add pc_Done
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] remove pc_Selected
/scoreboard players tag @r[type=minecraft:armor_stand,name=pc_Marker,tag=!pc_Done] add pc_Selected
/execute @e[type=minecraft:armor_stand,tag=pc_Selected] ~ ~ ~ /clone ~ ~ ~ ~9 ~9 ~9 1010 80 1000

/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] add pc_Done
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] remove pc_Selected
/scoreboard players tag @r[type=minecraft:armor_stand,name=pc_Marker,tag=!pc_Done] add pc_Selected
/execute @e[type=minecraft:armor_stand,tag=pc_Selected] ~ ~ ~ /clone ~ ~ ~ ~9 ~9 ~9 1020 80 1000
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] add pc_Done
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Selected] remove pc_Selected
#Clear tags
/scoreboard players tag @e[type=minecraft:armor_stand,tag=pc_Done] remove pc_Done
/scoreboard players reset * pc_progress
#Fill the bases
/fill 980 100 1064 988 100 1056 double_stone_slab2 8 replace air
/fill 980 100 1034 988 100 1026 double_stone_slab2 8 replace air
/fill 980 100 1004 988 100 996 double_stone_slab2 8 replace air
/fill 980 100 974 988 100 966 double_stone_slab2 8 replace air
/fill 980 100 944 988 100 936 double_stone_slab2 8 replace air

/fill 1030 100 1064 1038 100 1056 double_stone_slab2 8 replace air
/fill 1030 100 1034 1038 100 1026 double_stone_slab2 8 replace air
/fill 1030 100 1004 1038 100 996 double_stone_slab2 8 replace air
/fill 1030 100 974 1038 100 966 double_stone_slab2 8 replace air
/fill 1030 100 944 1038 100 936 double_stone_slab2 8 replace air
/fill 1080 100 1004 1088 100 996 double_stone_slab2 8 replace air
#Pickaxe
/give @a[team=pc_play] minecraft:diamond_pickaxe 1 0 {ench:[{id:32,lvl:4}],CanDestroy:["minecraft:double_stone_slab2","minecraft:red_sandstone"],HideFlags:31,Unbreakable:1,display:{Name:"Pumpkin Carver",Lore:["Use this to carve the pumpkin"]}}
#Load in first pumpkin to carve
/clone 980 81 1000 980 89 1008 975 102 1056
/clone 980 81 1000 980 89 1008 975 102 1026
/clone 980 81 1000 980 89 1008 975 102 996
/clone 980 81 1000 980 89 1008 975 102 966
/clone 980 81 1000 980 89 1008 975 102 936
/clone 980 81 1000 980 89 1008 1025 102 1056

/clone 980 81 1000 980 89 1008 1025 102 1026
/clone 980 81 1000 980 89 1008 1025 102 996
/clone 980 81 1000 980 89 1008 1025 102 966
/clone 980 81 1000 980 89 1008 1025 102 936
/clone 980 81 1000 980 89 1008 1075 102 996

#Setup
/scoreboard players set @e[type=minecraft:armor_stand,tag=GEN] pc_timer2 4800
/xp -10000l @a[team=pc_play]
/xp 240l @a[team=pc_play]
/blockdata 4 1 -48 {auto:1} #Timer clock
/scoreboard players set @a[team=pc_play] pc_points 0
/scoreboard objectives setdisplay sidebar pc_progress
/scoreboard players set @a pc_progress 0
/give @a[team=pc_play] minecraft:red_sandstone 5 0 {ench:[],CanPlaceOn:["minecraft:stained_hardened_clay","minecraft:double_stone_slab2"],HideFlags:31,Unbreakable:1,display:{Name:"Pumpkin Filler",Lore:["Use this to fill in a block"," you removed by mistake."," ","You only have a limited amount!"]}}
advancement grant @a only pumpkinparty:pc/minigame_play




#R: Timer clock
/scoreboard players remove @e[type=minecraft:armor_stand,tag=GEN,score_pc_timer2_min=0] pc_timer2 1
/scoreboard players operation @e[type=minecraft:armor_stand,tag=GEN] pc_timer = @e[type=minecraft:armor_stand,tag=GEN] pc_timer2
/scoreboard players operation @e[type=minecraft:armor_stand,tag=GEN] pc_timer %= #20 pc_timer
/execute @e[type=minecraft:armor_stand,tag=GEN,score_pc_timer=1,score_pc_timer_min=1] ~ ~ ~ /xp -1l @a
/execute @e[type=minecraft:armor_stand,tag=GEN,score_pc_timer2=-1] ~ ~ ~ /blockdata 4 1 -48 {auto:0}
/scoreboard players reset @e[type=minecraft:armor_stand,tag=GEN,score_pc_timer2=-1] pc_timer2
/execute @e[type=minecraft:armor_stand,tag=GEN,score_pc_timer2=0] ~ ~ ~ /blockdata 6 1 -48 {auto:1} #Game Over (lose)
/replaceitem entity @a[team=pc_play] slot.hotbar.0 minecraft:diamond_pickaxe 1 0 {ench:[{id:32,lvl:4}],CanDestroy:["minecraft:double_stone_slab2","minecraft:red_sandstone"],HideFlags:31,Unbreakable:1,display:{Name:"Pumpkin Carver",Lore:["Use this to carve the pumpkin"]}}
execute @a[score_pc_progress_min=0] ~ ~ ~ /fill ~-20 100 ~-20 ~20 100 ~20 double_stone_slab2 8 replace red_sandstone
execute @a[score_pc_progress_min=0] ~ ~ ~ /fill ~-20 101 ~-20 ~20 100 ~20 air 0 replace red_sandstone
/execute @e[type=minecraft:armor_stand,tag=GEN,score_pc_timer2=0] ~ ~ ~ /blockdata 4 1 -48 {auto:0}


#Game over (loss)
/tellraw @a ["",{"text":"Time is up!","color":"red"}]
/scoreboard teams leave @a[team=pc_play]

#Game over (win)
/tellraw @a ["",{"text":"Everyone finished carving.","color":"green"}]
/scoreboard players reset @e[type=minecraft:armor_stand,tag=GEN] pc_timer2
/xp -1000l @a

#reset
/clear @a minecraft:diamond_pickaxe
/scoreboard objectives setdisplay sidebar points
/execute @a ~ ~ ~ /scoreboard players operation @a[c=1] points += @a[c=1] pc_points
/scoreboard players reset @a pc_progress
/blockdata 14 1 -48 {auto:1} #win advancement
/tp @a 397 69 500 90 -10
/blockdata -24 1 -48 {auto:1} #pp:all_games/end_game



#win advancement
scoreboard players set @e[type=minecraft:armor_stand,tag=GEN] pc_points 0
execute @a ~ ~ ~ scoreboard players operation @e[type=minecraft:armor_stand,tag=GEN] pc_points > @s pc_points
/execute @a ~ ~ ~ scoreboard players operation @s pc_points -= @e[type=minecraft:armor_stand,tag=GEN] pc_points
advancement grant @a[score_pc_points_min=0,score_pc_points=0] only pumpkinparty:pc/minigame_win
/scoreboard players reset @a pc_points



#R: Countdown
scoreboard players add @e[tag=GEN,type=minecraft:armor_stand] GameTimer 1
testfor @e[tag=GEN,type=minecraft:armor_stand,score_GameTimer_min=40]
    /blockdata ~ ~ ~-2 {auto:0b} 
    scoreboard players reset @e[tag=GEN,type=minecraft:armor_stand,score_GameTimer_min=40] GameTimer
    /blockdata 0 1 -48 {auto:1} #Start



#player finishes
/execute @a[team=pc_play] ~ ~ ~ /scoreboard players add @p[team=pc_play,score_pc_progress_min=5] pc_points 1
/tellraw @a ["",{"selector":"@p[team=pc_play,score_pc_progress_min=5]"},{"text":" finished all 5 pumpkins and gains ","color":"green"},{"score":{"name":"@p[team=pc_play,score_pc_progress_min=5]","objective":"pc_points"},"color":"none"},{"text":" candies","color":"green"}]
/scoreboard teams leave @a[team=pc_play,score_pc_progress_min=5]
/testfor @a[team=pc_play]
    gamemode @a[score_pc_progress_min=5] 3
/testforblock ~ ~ ~-2 minecraft:chain_command_block -1 {SuccessCount:0}
    /blockdata 8 1 -48 {auto:1} #game over (win)



#Advancement checks
/testforblocks 980 100 1004 988 100 996 953 93 1008 
    advancement grant @p only pumpkinparty:pc/notch
/testforblocks 980 100 1004 988 100 996 949 89 980
    advancement grant @p only pumpkinparty:pc/sssss



#1st carve
/execute @p[team=pc_play,score_pc_progress=0,score_pc_progress_min=0,x=985,y=101,z=1000,r=20] ~ ~ ~ /testforblocks 980 100 1004 988 100 996 981 80 1000
    scoreboard players tag @p add pc_Improve
    /clone 990 81 1000 990 89 1008 975 102 996
    /tellraw @p ["",{"text":"Carve successful. Loading next pumpkin...","color":"green"}]


#Last carve
/execute @p[team=pc_play,score_pc_progress=4,score_pc_progress_min=4,x=985,y=101,z=1000,r=20] ~ ~ ~ /testforblocks 980 100 1004 988 100 996 1021 80 1000
    /scoreboard players tag @p add pc_Improve
    /tellraw @p ["",{"text":"Carve successful. All pumpkins carved.","color":"green"}]
    /blockdata 12 1 -48 {auto:1} #player finishes
    /playsound minecraft:entity.player.levelup voice @p

#Fail carve 
/tellraw @p ["",{"text":"Carve unsuccesful. Resetting pumpkin...","color":"red"}]
advancement grant @p only pumpkinparty:pc/big_mistakes



#Reset carve
/scoreboard players add @p[tag=pc_Improve] pc_progress 1
/scoreboard players tag @p[tag=pc_Improve] remove pc_Improve
/fill 980 100 1004 988 100 996 double_stone_slab2 8 replace air
/blockdata ~-6 ~1 ~2 {auto:1}

