Make The Monster Despawn When Looked At

Started by JustMonitor on

Topic category: Help with modding (Java Edition)

Last seen on 17:21, 31. Mar 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Make The Monster Despawn When Looked At

Hello, I want to make my entity spawn lightning and despawn when the player looks at him even if he is 200 blocks away, using procedures, I hope yall can help.

Last seen on 16:24, 16. Apr 2024
Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I can recommend you…
Mon, 04/01/2024 - 14:56

I can recommend you something that i've tried and worked for me, but is a bit poor, you need to insert into entity tick this command that would be executed from the entity (but first you will need to make a synched data for the entity(In my case i will call it "Test")):

execute as @p at @s anchored eyes facing entity @e[type=mod_id:entity_id,limit=1,sort=nearest] eyes anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run data merge entity @e[type=mod_id:entity_id,limit=1,sort=nearest] {DataTest:1b}

(i recommend you to play with the distance)

This would make the Test synched Data of the entity became true, now inside the tick update you must put a procedure that makes this:

if  entity... Test = true{
   (Here you put your execution)
   (here you must set the Test to false to avoid he loop)
}

Hope this helps you, and sorry if bad english ;)