################################################################################################
#
# Laser Game
#
################################################################################################


#------------
give @a[tag=give] minecraft:endermite_spawn_egg{display:{Name:"{\"text\":\"§6§lMirror\"}",Lore:["Rightclick to spawn."]},EntityTag:{id:"minecraft:armor_stand",Invisible:1,Marker:1,Tags:["sp1","sp"]},HideFlags:63}

execute as @e[tag=sp1] at @s run summon armor_stand ~ ~ ~ {NoGravity:1,Tags:["mirror"],Invisible:1,ArmorItems:[{},{},{},{id:"minecraft:diamond_pickaxe",Count:1,tag:{Unbreakable:1,Damage:10}}],DisabledSlots:63}
execute as @e[tag=sp1] at @s run summon armor_stand ~ ~ ~ {NoGravity:1,Tags:["mirror_base"],Invisible:1,ArmorItems:[{},{},{},{id:"minecraft:diamond_pickaxe",Count:1,tag:{Unbreakable:1,Damage:11}}],DisabledSlots:63}
execute as @e[tag=sp1] at @s run setblock ~ ~ ~ white_banner
execute as @e[tag=sp1] at @s run summon villager ~ ~ ~ {NoAI:1,VillagerData:{Offers:{}},PersistenceRequired:1,Health:1000f,Attributes:[{Name:generic.maxHealth,Base:1000}],Silent:1,Tags:["invis","mirror_villager"]}
kill @e[tag=sp1]

scoreboard players add @e[tag=sh] laser_spawn 1
scoreboard players set @e[tag=sh,scores={laser_spawn=30..}] laser_spawn 0
execute as @e[tag=sh,scores={laser_spawn=1}] at @s run summon armor_stand 2 81 686 {NoGravity:1,Tags:["laser"],Rotation:[-90f],Invisible:1,Marker:1}
execute as @e[tag=sh,scores={laser_spawn=1}] at @s run summon armor_stand 54 81 686 {NoGravity:1,Tags:["laser"],Rotation:[90f],Invisible:1,Marker:1}

execute as @e[tag=laser] at @s unless block ~ ~ ~ #jungle_temple:laser run kill @s
execute as @e[tag=laser] at @s run tp @s ^ ^ ^0.5
execute as @e[tag=laser,x=28,y=81,z=675,distance=..0.5] run scoreboard players set @e[tag=sh,scores={gamestate=3}] gamestate 4
execute as @e[tag=laser] at @s run particle dust 1 0.1 0.1 2 ~ ~0.4 ~ 0 0 0 0.01 1 force
execute as @e[tag=laser] at @s run particle end_rod ~ ~0.5 ~ 0 0 0 0.01 1 force
execute as @e[tag=laser] at @s unless block ~ ~ ~ #jungle_temple:laser run kill @s
execute as @e[tag=laser] at @s run tp @s ^ ^ ^0.5
execute as @e[tag=laser] at @s run particle dust 1 0.1 0.1 2 ~ ~0.4 ~ 0 0 0 0.1 1 force
execute as @e[tag=laser] at @s run particle end_rod ~ ~0.5 ~ 0 0 0 0.01 1 force
execute as @e[tag=laser,x=52.5,y=81,z=692,distance=..0.5] run scoreboard players set @e[tag=sh] emerald_active 31
execute as @e[tag=laser,x=28,y=81,z=675,distance=..0.5] run scoreboard players set @e[tag=sh,scores={gamestate=3}] gamestate 4


execute as @e[tag=laser] at @s if block ~ ~-1 ~ white_banner run function jungle_temple:deflect

execute as @e[tag=laser] at @s unless block ~ ~ ~ #jungle_temple:laser run kill @s
execute as @e[tag=laser] at @s run tp @s ^ ^ ^0.5
execute as @e[tag=laser,x=28,y=81,z=675,distance=..0.5] run scoreboard players set @e[tag=sh,scores={gamestate=3}] gamestate 4
execute as @e[tag=laser] at @s run particle dust 1 0.1 0.1 2 ~ ~0.4 ~ 0 0 0 0.01 1 force
execute as @e[tag=laser] at @s run particle end_rod ~ ~0.5 ~ 0 0 0 0.01 1 force
execute as @e[tag=laser] at @s unless block ~ ~ ~ #jungle_temple:laser run kill @s
execute as @e[tag=laser] at @s run tp @s ^ ^ ^0.5
execute as @e[tag=laser] at @s run particle dust 1 0.1 0.1 2 ~ ~0.4 ~ 0 0 0 0.1 1 force
execute as @e[tag=laser] at @s run particle end_rod ~ ~0.5 ~ 0 0 0 0.01 1 force
execute as @e[tag=laser,x=52.5,y=81,z=692,distance=..0.5] run scoreboard players set @e[tag=sh] emerald_active 31
execute as @e[tag=laser,x=28,y=81,z=675,distance=..0.5] run scoreboard players set @e[tag=sh,scores={gamestate=3}] gamestate 4



execute as @e[tag=laser] at @s if block ~ ~-1 ~ white_banner run function jungle_temple:deflect

effect give @e[tag=mirror_villager] instant_health 10 10 true

execute as @e[tag=mirror_villager,nbt={HurtTime:10s}] at @s run tag @e[tag=mirror,limit=1,sort=nearest,distance=..1] add mir_left
execute as @a[scores={talk=1..}] at @s positioned ^ ^ ^1 run execute as @e[tag=mirror_villager,distance=..2] at @s run tag @e[tag=mirror,limit=1,sort=nearest,distance=..1] add mir_right
execute as @e[tag=cage2,scores={cage_timer=0}] at @s run tag @e[tag=mirror,x=13,y=80,z=683,distance=..2] remove mir_left
execute as @e[tag=cage2,scores={cage_timer=0}] at @s run tag @e[tag=mirror,x=13,y=80,z=683,distance=..2] remove mir_right
tag @e[tag=mirror,x=49,y=80,z=680,distance=..2] remove mir_left
tag @e[tag=mirror,x=49,y=80,z=680,distance=..2] remove mir_right
scoreboard players set @a talk 0
scoreboard players add @e[tag=mirror] mirror_rot 0
scoreboard players add @e[tag=mirror,scores={mirror_rot=1..}] mirror_rot 1
scoreboard players set @e[tag=mirror,scores={mirror_rot=11..}] mirror_rot 0
scoreboard players remove @e[tag=mirror,scores={mirror_rot=..-1}] mirror_rot 1
scoreboard players set @e[tag=mirror,scores={mirror_rot=..-11}] mirror_rot 0

execute as @e[tag=mir_left] at @s run function jungle_temple:random_rotate_sound
execute as @e[tag=mir_right] at @s run function jungle_temple:random_rotate_sound

scoreboard players set @e[tag=mirror,tag=mir_right,scores={mirror_rot=0}] mirror_rot 1
scoreboard players set @e[tag=mirror,tag=mir_left,scores={mirror_rot=0}] mirror_rot -1
scoreboard players add @e[tag=mirror] mirror_y 0
execute as @e[tag=mirror,scores={mirror_rot=-2}] at @s run fill ~ ~ ~ ~ ~1 ~ void_air
execute as @e[tag=mirror,scores={mirror_rot=2}] at @s run fill ~ ~ ~ ~ ~1 ~ void_air
execute as @e[tag=mirror,scores={mirror_rot=-10}] at @s run fill ~ ~1 ~ ~ ~1 ~ air
execute as @e[tag=mirror,scores={mirror_rot=10}] at @s run fill ~ ~1 ~ ~ ~1 ~ air
tag @e[tag=mirror,scores={mirror_rot=-10}] add update_banner
tag @e[tag=mirror,scores={mirror_rot=10}] add update_banner

scoreboard players add @e[tag=mirror,scores={mirror_rot=1}] mirror_y 1
scoreboard players remove @e[tag=mirror,scores={mirror_rot=-1}] mirror_y 1
execute as @e[tag=mirror,scores={mirror_rot=1..10}] at @s run tp @s ~ ~ ~ ~-2.25 ~
execute as @e[tag=mirror,scores={mirror_rot=-10..-1}] at @s run tp @s ~ ~ ~ ~2.25 ~
scoreboard players set @e[scores={mirror_y=..-1}] mirror_y 15
scoreboard players set @e[scores={mirror_y=16..}] mirror_y 0

tag @e[tag=mir_right] remove mir_right
tag @e[tag=mir_left] remove mir_left

execute as @e[tag=update_banner,scores={mirror_y=0}] at @s run setblock ~ ~ ~ white_banner[rotation=0]
execute as @e[tag=update_banner,scores={mirror_y=15}] at @s run setblock ~ ~ ~ white_banner[rotation=1]
execute as @e[tag=update_banner,scores={mirror_y=14}] at @s run setblock ~ ~ ~ white_banner[rotation=2]
execute as @e[tag=update_banner,scores={mirror_y=13}] at @s run setblock ~ ~ ~ white_banner[rotation=3]
execute as @e[tag=update_banner,scores={mirror_y=12}] at @s run setblock ~ ~ ~ white_banner[rotation=4]
execute as @e[tag=update_banner,scores={mirror_y=11}] at @s run setblock ~ ~ ~ white_banner[rotation=5]
execute as @e[tag=update_banner,scores={mirror_y=10}] at @s run setblock ~ ~ ~ white_banner[rotation=6]
execute as @e[tag=update_banner,scores={mirror_y=9}] at @s run setblock ~ ~ ~ white_banner[rotation=7]
execute as @e[tag=update_banner,scores={mirror_y=8}] at @s run setblock ~ ~ ~ white_banner[rotation=8]
execute as @e[tag=update_banner,scores={mirror_y=7}] at @s run setblock ~ ~ ~ white_banner[rotation=9]
execute as @e[tag=update_banner,scores={mirror_y=6}] at @s run setblock ~ ~ ~ white_banner[rotation=10]
execute as @e[tag=update_banner,scores={mirror_y=5}] at @s run setblock ~ ~ ~ white_banner[rotation=11]
execute as @e[tag=update_banner,scores={mirror_y=4}] at @s run setblock ~ ~ ~ white_banner[rotation=12]
execute as @e[tag=update_banner,scores={mirror_y=3}] at @s run setblock ~ ~ ~ white_banner[rotation=13]
execute as @e[tag=update_banner,scores={mirror_y=2}] at @s run setblock ~ ~ ~ white_banner[rotation=14]
execute as @e[tag=update_banner,scores={mirror_y=1}] at @s run setblock ~ ~ ~ white_banner[rotation=15]
tag @e[tag=update_banner] remove update_banner

scoreboard players add @e[tag=sh,scores={init_mirror_rot=1..}] init_mirror_rot 1
scoreboard players set @e[tag=sh,scores={init_mirror_rot=120..}] init_mirror_rot 0

execute as @e[tag=sh,scores={init_mirror_rot=1..}] at @s run function jungle_temple:mirror_rotate_init

scoreboard players add @e[tag=cage2] cage_timer 0
scoreboard players add @e[tag=cage2,scores={cage_timer=1..19}] cage_timer 1
scoreboard players add @e[tag=cage2,scores={cage_timer=-20..-1}] cage_timer 1

execute as @e[tag=cage2,scores={cage_timer=1..19}] at @s run tp @s ~ ~-0.12 ~
execute as @e[tag=cage2,scores={cage_timer=-19..-2}] at @s run tp @s ~ ~0.12 ~

execute as @e[tag=cage2,scores={cage_timer=-18}] at @s run fill 13 80 683 13 81 683 void_air
execute as @e[tag=cage2,scores={cage_timer=2}] at @s run setblock 13 81 683 air
execute as @e[tag=cage2,scores={cage_timer=2}] at @s run tag @e[tag=mirror,distance=..3] add update_banner

execute as @e[tag=cage2,scores={cage_timer=-18}] at @s run setblock 54 81 692 red_stained_glass
execute as @e[tag=cage2,scores={cage_timer=2}] at @s run setblock 54 81 692 redstone_block

scoreboard players remove @e[tag=sh] emerald_active 1

execute as @e[tag=sh,scores={emerald_active=..0}] run scoreboard players set @e[tag=cage2,scores={cage_timer=20..}] cage_timer -20
execute as @e[tag=sh,scores={emerald_active=1..}] run scoreboard players set @e[tag=cage2,scores={cage_timer=0}] cage_timer 1

execute as @e[tag=sh,scores={gamestate=4}] at @s run setblock 28 81 675 diamond_block
execute as @e[tag=sh,scores={gamestate=4}] at @s run fill 27 74 701 29 78 701 air
execute as @e[tag=sh,scores={gamestate=4}] at @s run tag @a[tag=trapped] remove trapped
execute as @e[tag=sh,scores={gamestate=4}] at @s run playsound magic master @a 28 81 675 1.0 1.0
execute as @e[tag=sh,scores={gamestate=4}] at @s run
scoreboard players set @e[tag=sh,scores={gamestate=4}] gamestate 5
