1

Detecting Entities and Ending Function Recursion

TofuChild27 5/26/21 2:48 pm
104
6/27/2021 8:28 am
Hello All!
I have been having trouble making the recursive function raycast I have been creating stop once it hits an entity with any sort of precision. I have been able to make it stop once it hits the ground by simply including if block ~ ~ ~ minecraft:air in the execute line calling the recursion, but I have not been able to find a good way to stop the recursion when it hits an entity because of how independent the recursion command is from any other commands I run. If any of you have a suggestion, that would be very appreciated.
Thank you for your time,
TofuChild27
Posted by
TofuChild27
Level 1 : New Miner
0

  Have something to say?

JoinSign in

1

Bertiecrafter
06/27/2021 8:28 am
Level 72 : Legendary System
history
You should be doing it exactly the same:
"if entity @e[........,distance=..0.2]"

I used 0.2 as distance here, but it should be the same distance as the steps you take for sufficient coverage.

A couple gotcha's:
- Make sure you execute the next step at the new location of the marker. E.g.: "execute at @s if entity ....... run function ...."
- An entity is only detected if it's feet are within the circle around the center of the marker. Use particles at ~ ~ ~ to figure out where those points are. For example, you should make the raycast start about ~1.7 blocks up on the y axis to align with the player camera and then check for the entity like ~-1 blocks lower on the y axis to detect mobs better.

E.g. at first:
/execute positioned ~ ~1.7~ run function namespace:summon_ray
and then inside a step function:
/tp @s ^ ^ ^0.2
/execute at @s positioned ~ ~-1 ~ if entity .... positioned ~ ~1 ~ run function namespace:ray_step
1

Welcome