Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Ability to cancel entities looking at other entities

Open Sup33r opened this issue 6 months ago • 4 comments

Is your feature request related to a problem?

When creating systems such as vanish or minigames where you want to hide spectators from other players, you are as it is right now faced with the issue that entities that look at players still will look at players that are vanished or spectating. Right now there are only methods to make entities look at other entities, not an event or such that lets you cancel the act.

Describe the solution you'd like.

Essentially I want a way to toggle or cancel what entities look at what players (or other entities). This could for example be done through an event:

It would be a "EntityLookAtEntityEvent" or something along those lines, that lets you access the entity that tries to look, and the entity that it tries to look at, and then have it be cancellable.

Describe alternatives you've considered.

I've considered putting the players in spectator-mode, causing the entities to not look at players, but it would be very neat if something like this could be implemented.

Other

No response

Sup33r avatar Jun 04 '25 13:06 Sup33r

https://jd.papermc.io/paper/1.21.5/org/bukkit/event/entity/EntityTargetEvent.html

Clexus avatar Jun 07 '25 10:06 Clexus

https://jd.papermc.io/paper/1.21.5/org/bukkit/event/entity/EntityTargetEvent.html

That event doesn't have any control over the look functionality of mobs, as far as i know.

But it would definitely be a plausible approach to incorporate the look into that event, so it can be cancelled etc.

Sup33r avatar Jun 07 '25 10:06 Sup33r

https://jd.papermc.io/paper/1.21.5/org/bukkit/event/entity/EntityTargetEvent.html

That event doesn't have any control over the look functionality of mobs, as far as i know.

But it would definitely be a plausible approach to incorporate the look into that event, so it can be cancelled etc.

If you don't want the players to be followed by the entity, just cancel the EntityTargetEvent, and check so target it's the right player.

If a player were to enter vanish when they already have an entity following them, could you just go through nearby entities, and set target to null, if the entity has the player as target.

wilmer100101 avatar Jun 17 '25 11:06 wilmer100101

I think I misunderstood your question, I first interpreted it as you only wanted to remove the "following" entities.

I assume you are talking about the "LookAtPlayerGoal", I think the only way currently is to get the nms entity and remove the goal by the Mob#removeAllGoals method, where you can check if the goal is instanceof LookAtPlayerGoal.

So yeah, something like a EntityLookAtEntityEvent or more universal for all goals would be nice.

wilmer100101 avatar Jun 17 '25 14:06 wilmer100101