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

#sh
effect give @e[type=minecraft:shulker] minecraft:invisibility 1000000 100 true

#position
execute as @e[tag=minigun_barrel] run data merge entity @s {Pose:{Head:[0.01f,0.0f,0.01f]}}
execute as @e[tag=minigun_barrel] store result entity @s Pose.Head[0] float 1 run scoreboard players get @s time

#minigun base
execute as @e[tag=minigun_base] at @s run function f:game/store/minigun/base

#store rotation
execute as @e[tag=minigun_tower] run data merge entity @s {Pose:{Head:[0.01f,0.0f,0.0f]}}
execute as @e[tag=minigun_tower] store result entity @s Pose.Head[0] float 1 run data get entity @s Rotation[1]
execute as @e[tag=minigun_barrel] store result entity @s Pose.Head[2] float -1 run data get entity @s Rotation[1]

#hitbox
execute at @a as @e[tag=candy_bullet,distance=..3] store result score @s hitbox_x run data get entity @s Pos[0] 100
execute at @a as @e[tag=candy_bullet,distance=..3] store result score @s hitbox_y run data get entity @s Pos[1] 100
execute at @a as @e[tag=candy_bullet,distance=..3] store result score @s hitbox_z run data get entity @s Pos[2] 100

#hitbox get player
execute as @a store result score @s hitbox_x run data get entity @s Pos[0] 100
execute as @a store result score @s hitbox_y run data get entity @s Pos[1] 100
execute as @a store result score @s hitbox_z run data get entity @s Pos[2] 100
execute as @a store result score @s hitbox_z2 run data get entity @s Pos[0] 100
execute as @a store result score @s hitbox_y2 run data get entity @s Pos[1] 100
execute as @a store result score @s hitbox_z2 run data get entity @s Pos[2] 100

#set player hitbox position
scoreboard players remove @a hitbox_x 40
scoreboard players remove @a hitbox_z 40
scoreboard players add @a hitbox_x2 40
scoreboard players add @a hitbox_y2 170
scoreboard players add @a hitbox_z2 40

#kill
execute as @e[tag=candy_bullet] at @s if score @s hitbox_x >= @p[distance=..3] hitbox_x if score @s hitbox_y >= @p[distance=..3] hitbox_y if score @s hitbox_z >= @p[distance=..3] hitbox_z if score @s hitbox_x <= @p[distance=..3] hitbox_x2 if score @s hitbox_y <= @p[distance=..3] hitbox_y2 if score @s hitbox_z <= @p[distance=..3] hitbox_z2 at @p run function f:game/store/minigun/hit

#process
execute as @e[tag=candy_bullet] at @s run tp @s ^ ^ ^1
execute as @e[tag=candy_bullet] at @s unless entity @p[distance=..50] run kill @s
execute as @e[tag=candy_bullet] at @s unless block ~ ~ ~ air run kill @s
