#time -1

execute at @s[scores={time=2399}] run function animated_java:upgrade/summon
execute at @s[scores={tech=0}] run tp @e[tag=aj.upgrade.root,sort=nearest,limit=1] ~ ~ ~ ~ 0
execute at @s[scores={tech=1}] run tp @e[tag=aj.upgrade_furnace.root,sort=nearest,limit=1] ~ ~ ~ ~ 0
execute at @s[scores={tech=2}] run tp @e[tag=aj.upgrade_note.root,sort=nearest,limit=1] ~ ~ ~ ~ 0
execute at @s[scores={tech=3}] run tp @e[tag=aj.upgrade_cutter.root,sort=nearest,limit=1] ~ ~ ~ ~ 0
execute at @s[scores={tech=4}] run tp @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] ~ ~ ~ ~ 0
execute at @s[scores={time=2399}] run function ben:idle
execute at @s if block ~ ~ ~ air unless block ~ ~1 ~ air unless block ~ ~-1 ~ air run tp @e[tag=aj.upgrade_blob.root,sort=nearest,limit=1] ~ ~ ~ ~ 0

#vida
#20 ❤️

#efectos
#resistencia
effect give @s resistance 1 0 true
effect give @s[nbt=!{ActiveEffects:[{Id:10}]}] regeneration 1 2 true

effect give @s[scores={tech=4}] strength 1 2 true
effect give @s[scores={tech=4}] resistance 1 1 true


execute as @s[scores={tech=4}] run function ben:fly

scoreboard players add @s[tag=fly] timer3 1

execute at @s[scores={timer3=1},tag=fly] run execute as @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] run function animated_java:upgrade_golem/animations/run/stop
execute at @s[scores={timer3=1},tag=fly] run execute as @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] run function animated_java:upgrade_golem/animations/idle/play

scoreboard players reset @s[tag=fly] walk
scoreboard players reset @s[tag=fly] walk_water
scoreboard players reset @s[tag=fly] walk_on_water
scoreboard players reset @s[tag=fly] sneak
scoreboard players reset @s[tag=fly] swim

execute at @s[scores={timer3=1..},tag=!fly] run execute as @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] run function animated_java:upgrade_golem/animations/idle/stop

scoreboard players set @s[scores={timer3=1..},tag=!fly] walk 3
scoreboard players set @s[scores={timer3=1..},tag=!fly] walk_water 3
scoreboard players set @s[scores={timer3=1..},tag=!fly] walk_on_water 3
scoreboard players set @s[scores={timer3=1..},tag=!fly] sneak 3
scoreboard players set @s[scores={timer3=1..},tag=!fly] swim 3

scoreboard players reset @s[tag=!fly] timer3


execute at @s[tag=fly] rotated ~ 0 run particle minecraft:flame ^0.3 ^-0.2 ^ 0 0.1 0 0 100
execute at @s[tag=fly] rotated ~ 0 run particle minecraft:campfire_cosy_smoke ^0.3 ^-0.2 ^ 0 0 0 0 1

execute at @s[tag=fly] rotated ~ 0 run particle minecraft:flame ^-0.3 ^-0.2 ^ 0 0.1 0 0 100
execute at @s[tag=fly] rotated ~ 0 run particle minecraft:campfire_cosy_smoke ^-0.3 ^-0.2 ^ 0 0 0 0 1


#habilidades pasivas
#maleable:puede pasar huecos de 1 bloque y vallas
execute at @s[scores={tech=0}] if block ~ ~ ~1 air unless block ~ ~1 ~1 air run tp ~ ~ ~0.001
execute at @s[scores={tech=0}] if block ~ ~ ~-1 air unless block ~ ~1 ~-1 air run tp ~ ~ ~-0.001
execute at @s[scores={tech=0}] if block ~1 ~ ~ air unless block ~1 ~1 ~ air run tp ~0.001 ~ ~
execute at @s[scores={tech=0}] if block ~-1 ~ ~ air unless block ~-1 ~1 ~ air run tp ~-0.001 ~ ~
execute at @s[scores={tech=0}] if block ~ ~ ~ air unless block ~ ~1 ~ air unless block ~ ~-1 ~ air run attribute @s minecraft:generic.movement_speed base set 0.3
execute at @s[scores={tech=0}] if block ~ ~1 ~ air if block ~ ~ ~ air run attribute @s minecraft:generic.movement_speed base set 0.1

execute at @s[scores={tech=0},y_rotation=-45..45] if block ~ ~ ~0.1 #minecraft:fences run tp ~ ~ ~0.001
execute at @s[scores={tech=0},y_rotation=45..135] if block ~-0.1 ~ ~ #minecraft:fences run tp ~-0.001 ~ ~
execute at @s[scores={tech=0},y_rotation=135..-135] if block ~ ~ ~-0.1 #minecraft:fences run tp ~ ~ ~-0.001
execute at @s[scores={tech=0},y_rotation=-135..-45] if block ~0.1 ~ ~ #minecraft:fences run tp ~0.001 ~ ~

execute at @s[scores={tech=0},y_rotation=-45..45] if block ~ ~ ~0.01 iron_bars run tp ~ ~ ~0.001
execute at @s[scores={tech=0},y_rotation=45..135] if block ~-0.01 ~ ~ iron_bars run tp ~-0.001 ~ ~
execute at @s[scores={tech=0},y_rotation=135..-135] if block ~ ~ ~-0.01 iron_bars run tp ~ ~ ~-0.001
execute at @s[scores={tech=0},y_rotation=-135..-45] if block ~0.01 ~ ~ iron_bars run tp ~0.001 ~ ~

#execute at @s[scores={tech=0},y_rotation=-45..45] run tp ~ ~ ~0.1
#execute at @s[scores={tech=0},y_rotation=45..135] run tp ~-0.1 ~ ~
#execute at @s[scores={tech=0},y_rotation=135..-135] run tp ~ ~ ~-0.1
#execute at @s[scores={tech=0},y_rotation=-135..-45] run tp ~0.1 ~ ~


#blob
execute at @s[scores={tech=0}] if block ~ ~ ~ air unless block ~ ~1 ~ air unless block ~ ~-1 ~ air as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function ben:upgrade/blob
execute at @s[scores={tech=0}] if block ~ ~1 ~ air if block ~ ~ ~ air as @e[tag=aj.upgrade_blob.root,sort=nearest,limit=1] run function ben:upgrade/normal


#habilidades activas
#posesión tecnológica: puede fusionarse con mecanismos de redstone y controlarlos
#rayo láser: puede disparar un rayo láser desde su ojo
execute as @s[scores={click=1..},nbt={SelectedItemSlot:0}] unless entity @s[scores={timer=1..}] run function ben:upgrade/laser

#Blast Furnace
#
#lanzallamas: dispara un chorro de fuego que daña y quema a los mobs
execute at @s[scores={click=1..,tech=0},nbt={SelectedItemSlot:1}] if block ~ ~-1 ~ minecraft:blast_furnace unless entity @e[type=iron_golem,distance=..2] as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function ben:upgrade/furnace
execute at @s[scores={click=1..,tech=1},nbt={SelectedItemSlot:1}] as @e[tag=aj.upgrade_furnace.root,sort=nearest,limit=1] run function ben:upgrade/normal

execute as @s[scores={click=1..,tech=1},nbt={SelectedItemSlot:2}] unless entity @s[scores={timer2=1..}] run function ben:upgrade/flame

#Noteblock
#
#aullido sónico: emite un aullido sónico que daña y empuja enemigos y refleja projectiles
execute at @s[scores={click=1..,tech=0},nbt={SelectedItemSlot:1}] if block ~ ~-1 ~ minecraft:note_block unless entity @e[type=iron_golem,distance=..2] as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function ben:upgrade/note
execute at @s[scores={click=1..,tech=2},nbt={SelectedItemSlot:1}] as @e[tag=aj.upgrade_note.root,sort=nearest,limit=1] run function ben:upgrade/normal

execute as @s[scores={click=1..,tech=2},nbt={SelectedItemSlot:2}] unless entity @s[scores={timer2=1..}] run function ben:upgrade/sonic


#Corta Piedra
#
#sierra láser: ataque que hace el mismo daño que una espada de diamante
execute at @s[scores={click=1..,tech=0},nbt={SelectedItemSlot:1}] if block ~ ~ ~ minecraft:stonecutter unless entity @e[type=iron_golem,distance=..2] as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function ben:upgrade/cutter
execute at @s[scores={click=1..,tech=3},nbt={SelectedItemSlot:1}] as @e[tag=aj.upgrade_cutter.root,sort=nearest,limit=1] run function ben:upgrade/normal

execute as @s[scores={click=1..,tech=3},nbt={SelectedItemSlot:2}] unless entity @s[scores={timer2=1..}] run function ben:upgrade/cut

#Iron golem
#
#onda expansiva: empuja y daña a todos los mobs a su alrededor, además destruye el terreno
#vuelo: puede volar
execute at @s[scores={click=1..,tech=0},nbt={SelectedItemSlot:1}] if entity @e[type=iron_golem,distance=..2] as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function ben:upgrade/golem
execute at @s[scores={click=1..,tech=4},nbt={SelectedItemSlot:1}] as @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] run function ben:upgrade/normal

execute as @s[scores={click=1..,tech=4},nbt={SelectedItemSlot:2},nbt={OnGround:1b}] unless entity @s[scores={timer2=1..}] run function ben:upgrade/shock

#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#timer Shock Wave

effect give @s[scores={timer2=1,tech=4}] slowness 1 255 true
effect give @s[scores={timer2=1,tech=4}] jump_boost 1 200 true

effect give @s[scores={timer2=1,tech=4}] resistance 1 5 true
scoreboard players add @s[scores={timer2=1..,tech=4}] timer2 1

scoreboard players reset @s[scores={timer2=1..20,tech=4}] walk
scoreboard players reset @s[scores={timer2=1..20,tech=4}] walk_water
scoreboard players reset @s[scores={timer2=1..20,tech=4}] walk_on_water
scoreboard players reset @s[scores={timer2=1..20,tech=4}] sneak
scoreboard players reset @s[scores={timer2=1..20,tech=4}] swim

execute at @s[scores={timer2=13,tech=4}] run summon tnt

execute at @s[scores={timer2=20,tech=4}] run execute as @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] run function animated_java:upgrade_golem/animations/slam/stop
execute at @s[scores={timer2=20,tech=4}] run execute as @e[tag=aj.upgrade_golem.root,sort=nearest,limit=1] run function animated_java:upgrade_golem/animations/idle/play

scoreboard players set @s[scores={timer2=20,tech=4}] walk 3
scoreboard players set @s[scores={timer2=20,tech=4}] walk_water 3
scoreboard players set @s[scores={timer2=20,tech=4}] walk_on_water 3
scoreboard players set @s[scores={timer2=20,tech=4}] sneak 3
scoreboard players set @s[scores={timer2=20,tech=4}] swim 3

scoreboard players reset @s[scores={timer2=60,tech=4}] timer2

#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#timer flame

effect give @s[scores={timer2=1,tech=1}] slowness 1 255 true
effect give @s[scores={timer2=1,tech=1}] jump_boost 1 200 true


scoreboard players add @s[scores={timer2=1..,tech=1}] timer2 1

scoreboard players reset @s[scores={timer2=1..,tech=1}] walk
scoreboard players reset @s[scores={timer2=1..,tech=1}] walk_water
scoreboard players reset @s[scores={timer2=1..,tech=1}] walk_on_water
scoreboard players reset @s[scores={timer2=1..,tech=1}] sneak
scoreboard players reset @s[scores={timer2=1..,tech=1}] swim

execute at @s[scores={timer2=5..17,tech=1}] unless entity @s[scores={watertime=1..}] run function ben:upgrade/flamecast/start_raycast

execute at @s[scores={timer2=17,tech=1}] run execute as @e[tag=aj.upgrade_furnace.root,sort=nearest,limit=1] run function animated_java:upgrade_furnace/animations/blast/stop
execute at @s[scores={timer2=17,tech=1}] run execute as @e[tag=aj.upgrade_furnace.root,sort=nearest,limit=1] run function animated_java:upgrade_furnace/animations/idle/play

scoreboard players set @s[scores={timer2=17,tech=1}] walk 3
scoreboard players set @s[scores={timer2=17,tech=1}] walk_water 3
scoreboard players set @s[scores={timer2=17,tech=1}] walk_on_water 3
scoreboard players set @s[scores={timer2=17,tech=1}] sneak 3
scoreboard players set @s[scores={timer2=17,tech=1}] swim 3

scoreboard players reset @s[scores={timer2=17,tech=1}] timer2



scoreboard players set @s[scores={time=2399}] watertime 0

scoreboard players add @s[tag=water,scores={watertime=..18}] watertime 3
execute as @s[predicate=!ben:clear] run scoreboard players add @s[predicate=is_sky:check_sky,scores={watertime=..18}] watertime 3

scoreboard players remove @s[tag=!water,scores={watertime=1..}] watertime 1



#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#timer sonic

effect give @s[scores={timer2=1,tech=2}] slowness 1 255 true
effect give @s[scores={timer2=1,tech=2}] jump_boost 1 200 true


scoreboard players add @s[scores={timer2=1..,tech=2}] timer2 1

scoreboard players reset @s[scores={timer2=1..,tech=2}] walk
scoreboard players reset @s[scores={timer2=1..,tech=2}] walk_water
scoreboard players reset @s[scores={timer2=1..,tech=2}] walk_on_water
scoreboard players reset @s[scores={timer2=1..,tech=2}] sneak
scoreboard players reset @s[scores={timer2=1..,tech=2}] swim

execute at @s[scores={timer2=5..17,tech=2}] run function ben:upgrade/soniccast/start_raycast

execute at @s[scores={timer2=17,tech=2}] run execute as @e[tag=aj.upgrade_note.root,sort=nearest,limit=1] run function animated_java:upgrade_note/animations/blast/stop
execute at @s[scores={timer2=17,tech=2}] run execute as @e[tag=aj.upgrade_note.root,sort=nearest,limit=1] run function animated_java:upgrade_note/animations/idle/play

scoreboard players set @s[scores={timer2=17,tech=2}] walk 3
scoreboard players set @s[scores={timer2=17,tech=2}] walk_water 3
scoreboard players set @s[scores={timer2=17,tech=2}] walk_on_water 3
scoreboard players set @s[scores={timer2=17,tech=2}] sneak 3
scoreboard players set @s[scores={timer2=17,tech=2}] swim 3


scoreboard players reset @s[scores={timer2=17,tech=2}] timer2




#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#timer cut

effect give @s[scores={timer2=1,tech=3}] slowness 1 255 true
effect give @s[scores={timer2=1,tech=3}] jump_boost 1 200 true


scoreboard players add @s[scores={timer2=1..,tech=3}] timer2 1

scoreboard players reset @s[scores={timer2=1..,tech=3}] walk
scoreboard players reset @s[scores={timer2=1..,tech=3}] walk_water
scoreboard players reset @s[scores={timer2=1..,tech=3}] walk_on_water
scoreboard players reset @s[scores={timer2=1..,tech=3}] sneak
scoreboard players reset @s[scores={timer2=1..,tech=3}] swim

execute at @s[scores={timer2=5..20,tech=3}] run function ben:upgrade/cutcast/start_raycast

execute at @s[scores={timer2=20,tech=3}] run execute as @e[tag=aj.upgrade_cutter.root,sort=nearest,limit=1] run function animated_java:upgrade_cutter/animations/blast/stop
execute at @s[scores={timer2=20,tech=3}] run execute as @e[tag=aj.upgrade_cutter.root,sort=nearest,limit=1] run function animated_java:upgrade_cutter/animations/idle/play

scoreboard players set @s[scores={timer2=20,tech=3}] walk 3
scoreboard players set @s[scores={timer2=20,tech=3}] walk_water 3
scoreboard players set @s[scores={timer2=20,tech=3}] walk_on_water 3
scoreboard players set @s[scores={timer2=20,tech=3}] sneak 3
scoreboard players set @s[scores={timer2=20,tech=3}] swim 3


scoreboard players reset @s[scores={timer2=20,tech=3}] timer2

#--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




execute as @s[nbt={SelectedItemSlot:0}] run title @s actionbar {"text":"Optic Laser","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:1},scores={tech=0}] run title @s actionbar {"text":"Technological Merging","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:1},scores={tech=1..}] run title @s actionbar {"text":"Technological Demerging","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:2},scores={tech=0}] run title @s actionbar {"text":""}
execute as @s[nbt={SelectedItemSlot:2},scores={tech=1}] run title @s actionbar {"text":"Flamethrower","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:2},scores={tech=2}] run title @s actionbar {"text":"Sonic Boom","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:2},scores={tech=3}] run title @s actionbar {"text":"Laser Saw","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:2},scores={tech=4}] run title @s actionbar {"text":"Shock Wave","color":"dark_green","bold":true}
execute as @s[nbt={SelectedItemSlot:3}] run title @s actionbar {"text":""}
execute as @s[nbt={SelectedItemSlot:4}] run title @s actionbar {"text":""}
execute as @s[nbt={SelectedItemSlot:5}] run title @s actionbar {"text":""}
execute as @s[nbt={SelectedItemSlot:6}] run title @s actionbar {"text":""}
execute as @s[nbt={SelectedItemSlot:7}] run title @s actionbar {"text":""}
execute as @s[nbt={SelectedItemSlot:8}] run title @s actionbar {"text":""}

scoreboard players add @s[scores={timer=1..}] timer 1
scoreboard players reset @s[scores={timer=1..}] walk
scoreboard players reset @s[scores={timer=1..}] walk_water
scoreboard players reset @s[scores={timer=1..}] walk_on_water
scoreboard players reset @s[scores={timer=1..}] sneak
scoreboard players reset @s[scores={timer=1..}] swim

effect give @s[scores={timer=..20}] slowness 1 255 true
effect give @s[scores={timer=..20}] jump_boost 1 200 true
execute at @s[scores={timer=8..39,tech=0}] run function ben:upgrade/lasercast/start_raycast
execute at @s[scores={timer=8..39,tech=1}] positioned ~ ~-1 ~ run function ben:upgrade/lasercast/start_raycast
execute at @s[scores={timer=8..39,tech=2}] positioned ~ ~-1 ~ run function ben:upgrade/lasercast/start_raycast
execute at @s[scores={timer=8..39,tech=3}] positioned ~ ~-1 ~ run function ben:upgrade/lasercast/start_raycast
execute at @s[scores={timer=8..39,tech=4}] positioned ~ ~1 ~ run function ben:upgrade/lasercast/start_raycast


execute at @s[scores={timer=40}] run execute as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function animated_java:upgrade/animations/blast/stop
execute at @s[scores={timer=40}] run execute as @e[tag=aj.upgrade.root,sort=nearest,limit=1] run function animated_java:upgrade/animations/idle/play

scoreboard players set @s[scores={timer=40}] walk 3
scoreboard players set @s[scores={timer=40}] walk_water 3
scoreboard players set @s[scores={timer=40}] walk_on_water 3
scoreboard players set @s[scores={timer=40}] sneak 3
scoreboard players set @s[scores={timer=40}] swim 3

scoreboard players reset @s[scores={timer=40}] timer
