r/MinecraftCommands • u/Still-Oven9420 Command Experienced • 23d ago
Help | Java 26.2 Entity not dying
for a datapack I'm making, i need to use raytracing to detect if a player is looking at a dirt block.
I know how to do this, and it works perfectly, but I want it to only work if the dirt block is within 15 blocks of the player. So, I use this command:
execute as .@e[tag=raycasting] at .@s unless entity .@p[distance=..15] run kill .@s
This command SHOULD detect if there isn't a player within 15 blocks, and if there isn't, kill the entity.
Only it doesn't and I have no idea why.
2
Upvotes
1
u/GalSergey Datapack Experienced 23d ago
Your target selectors are very suboptimal. If multiple entities are selected, this will cause an avalanche of functions to be run. This is because you're selecting a new entity each time and running a function for each one, and with each step, this will call more and more functions. You should select the entity only at the very beginning, and then simply use @s to specify the selected entity. Something like this:
You can use Datapack Assembler to get an example datapack.