Raycasting 1.6.4 [Bedrock Edition] [Most efficient] [Very accurate] Looping:
# Summons raycast entity when an entity holds the correct item, dirt named 'raycast pp 69 420'
execute if entity @e run execute as @e run execute at @e run execute if entity @s[distance=..1] run execute if entity @s[nbt={SelectedItem:{id:"minecraft:dirt",count:42b,tag:{display:{Name:'{"text":"raycast pp 69 420"}'}}} run summon armor_stand ~ ~ ~ {CustomName:'{"text":"Raycast"}',Invisible:1b,NoGravity:1b}
Raycast:
# Detects if there's a block here and kills itself if there's not
execute if entity @e run execute as @e run execute at @e run execute if entity @s[distance=..1] run execute if entity @s[type=armor_stand] run execute if entity @s[name=Raycast] run execute if block ~ ~ ~ minecraft:air run kill @s
# Detects if itself exists and if it doesn't exist summon a new armor_satnd
execute if entity @e run execute unless entity @s run execute positioned ^ ^ ^0.1 run summon armor_stand ~ ~ ~ {CustomName:'{"text":"Raycast"}',Invisible:1b,NoGravity:1b}
# Detects if itself exists and if it does it does something
execute if entity @e run execute if entity @s run function namespace:hit
Hit:
# Put what you want it to do when raycast hits something in here
# Cleans up
execute if entity @e run execute at @e run execute as @e run execute if entity @s[type=armor_stand] run execute if entity @s[name=Raycast] run kill @s
📝Special Note: ||Incase you're fricking retarded slow, this will work but it is really bad please do not. Also this is intentionally incorrectly labled. This is Java commands for 1.13+||
🔗Link: https://gist.github.com/SheepCommander/54e8bf5c5fc44743efaf3b3fa8296c6a
BTW this paste is best viewed on discord. (Go to Raw then copy and paste into discord for better viewing.