Started by
MischiefCat591
on
Topic category: Help with MCreator software
Is there a way i could give the player a potion effect when they're looking at a certain entity?
Edited by MischiefCat591 on Sun, 06/30/2024 - 01:59
Topic category: Help with MCreator software
Is there a way i could give the player a potion effect when they're looking at a certain entity?
I've done something similar for one of my mods, but where the player gives specific entities an effect by looking at them instead.
I Googled how to give a mob an effect by looking at them and used this for reference: https://www.reddit.com/r/MinecraftCommands/comments/146x8wx/how_do_i_give_an_effect_to_the_entity_the_player/
Here's a command for what you're trying to do, though: /execute as @a at @a facing entity @e[type=minecraft:villager] feet positioned ^ ^ ^1 rotated as @a[limit=1] positioned ^ ^ ^-1 if entity @a[distance=..0.075] if entity @e[type=villager,distance=..10] run effect give @s minecraft:glowing 1 0 false
The distance value in "if entity @a[distance=..0.075]" refers to how closely the player must be looking at the mob in order for the effect to trigger. The smaller the value, the smaller the area.
The distance value in "if entity @e[type=villager,distance=..10]" limits how far away the command is able to take effect. Here, it only works within 10 blocks of the entity. If the player looks at a villager from further than 10 blocks away, then nothing will happen.
Just create an onTick procedure for the entity you want and have that command be executed in whatever circumstances you'd like.