tag @a add hitable
tag @e[type=minecraft:pillager] add hitable
tag @e[type=minecraft:vindicator] add hitable
execute as @e[type=!minecraft:player] run scoreboard players set @s invulnerable 0
execute as @a unless score @s invulnerable matches 0 unless score @s invulnerable matches 1 run scoreboard players set @s invulnerable 0

scoreboard players remove @a[scores={invulnerable=1}] invulnerable 1
scoreboard players set @e[type=!minecraft:player] invulnerable 0
execute as @a unless score @s shiftcheck matches 1.. run scoreboard players set @s shiftreload 0
scoreboard players set @a shiftcheck 0

function ws:item/gun/glock/reset
function ws:item/gun/spas12/reset
function ws:item/gun/mp5/reset
function ws:item/gun/scoutrifle/reset

execute as @a[tag=glockReloading] run function ws:item/gun/glock/reload
execute as @a[scores={carrotshoot=1..,glockCD=..0,magGlock=1..},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"glock"}}}}] at @s positioned ^ ^ ^ run function ray_demo:ray/cast
scoreboard players remove @a[scores={glockCD=1..}] glockCD 1
execute as @a[scores={glockCD=1..}] run function ws:item/gun/glock/shoot
execute as @a[scores={glockCD=0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"glock"}}}}] run item modify entity @s weapon.mainhand ray_demo:glock/def
execute as @a[scores={carrotshoot=1..,magGlock=..0,glockCD=..0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"glock"}}}}] at @s positioned ^ ^ ^ run playsound minecraft:weapon.noammo player @a ~ ~ ~
execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"glock"}}}}] run function ws:item/gun/glock/ammo

execute as @a[tag=spas12Reloading] run function ws:item/gun/spas12/reload
execute as @a[scores={carrotshoot=1..,spas12CD=..0,magSPAS=1..},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"spas12"}}}}] at @s positioned ^ ^ ^ run function ray_demo:ray/castshotgun
scoreboard players remove @a[scores={spas12CD=1..}] spas12CD 1
execute as @a[scores={spas12CD=1..}] run function ws:item/gun/spas12/shoot
execute as @a[scores={spas12CD=0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"spas12"}}}}] run item modify entity @s weapon.mainhand ray_demo:spas12/def
execute as @a[scores={carrotshoot=1..,magSPAS=..0,spas12CD=..0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"spas12"}}}}] at @s positioned ^ ^ ^ run playsound minecraft:weapon.noammo player @a ~ ~ ~
execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"spas12"}}}}] run function ws:item/gun/spas12/ammo

execute as @a[tag=mp5Reloading] run function ws:item/gun/mp5/reload
execute as @a[scores={carrotshoot=1..,mp5CD=..0,magMP5=1..},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"mp5"}}}}] at @s positioned ^ ^ ^ run function ray_demo:ray/cast
scoreboard players remove @a[scores={mp5CD=1..}] mp5CD 1
execute as @a[scores={mp5CD=1..}] run function ws:item/gun/mp5/shoot
execute as @a[scores={mp5CD=0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"mp5"}}}}] run item modify entity @s weapon.mainhand ray_demo:mp5/def
execute as @a[scores={carrotshoot=1..,magMP5=..0,mp5CD=..0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"mp5"}}}}] at @s positioned ^ ^ ^ run playsound minecraft:weapon.noammo player @a ~ ~ ~
execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"mp5"}}}}] run function ws:item/gun/mp5/ammo

execute as @a[scores={carrotshoot=1..,duskCD=..0,18mm=1..},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"duskshotgun"}}}}] at @s positioned ^ ^ ^ run function ray_demo:ray/castduskshotgun
scoreboard players remove @a[scores={duskCD=1..}] duskCD 1
execute as @a[scores={duskCD=1..}] run function ws:item/gun/duskshotgun/shoot
execute as @a[scores={duskCD=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"duskshotgun"}}}}] run item modify entity @s weapon.mainhand ray_demo:duskshotgun/def
execute as @a[scores={carrotshoot=1..,18mm=..0,duskCD=..0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"duskshotgun"}}}}] at @s positioned ^ ^ ^ run playsound minecraft:weapon.noammo player @a ~ ~ ~
execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"duskshotgun"}}}}] run function ws:item/gun/duskshotgun/ammo

execute as @a[tag=scoutReloading] run function ws:item/gun/scoutrifle/reload
execute as @a[scores={carrotshoot=1..,sniperCD=..0,magScout=1..},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"scoutrifle"}}}}] at @s positioned ^ ^ ^ run function ray_demo:ray/castsniper
scoreboard players remove @a[scores={sniperCD=1..}] sniperCD 1
execute as @a[scores={sniperCD=1..}] run function ws:item/gun/scoutrifle/shoot
execute as @a[scores={sniperCD=0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"scoutrifle"}}}}] run item modify entity @s weapon.mainhand ray_demo:scout/def
execute as @a[scores={carrotshoot=1..,magScout=..0,sniperCD=..0,shiftreload=0},nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"scoutrifle"}}}}] at @s positioned ^ ^ ^ run playsound minecraft:weapon.noammo player @a ~ ~ ~
execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{weapon:"scoutrifle"}}}}] run function ws:item/gun/scoutrifle/ammo

scoreboard players set @a[scores={carrotshoot=1..}] carrotshoot 0

execute as @a[nbt={Inventory:[{Slot:-106b,components:{"minecraft:custom_data":{nailgun:1}}}]}] run function ws:item/gun/nailgun/offhand

execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{nailgun:1}}}}] run function ws:item/gun/nailgun/selected
scoreboard players set @a[nbt=!{SelectedItem:{components:{"minecraft:custom_data":{nailgun:1}}}}] shot 0
scoreboard players set @a[scores={shot=1..}] nailrecharge -5
scoreboard players add @a[scores={nailrecharge=..7}] nailrecharge 1
scoreboard players add @a[scores={nailrecharge=8,nails=..99}] nails 1
scoreboard players remove @a[scores={shot=1}] nails 1
scoreboard players set @a[scores={nailrecharge=8}] nailrecharge 0
execute as @a[nbt={SelectedItem:{components:{"minecraft:custom_data":{nailgun:1}}}},scores={shot=1..}] at @s as @e[type=minecraft:arrow,sort=nearest,limit=1] run tag @s add nail
execute as @e[tag=nail] run data merge entity @s {damage:0.00001d}

scoreboard players set @a shot 0

scoreboard players add .guns scores 1
execute if score .guns scores matches 100.. as @a run function ws:misc/gun/scoreset