#find players near mob inside creaturespawnevent listener

1 messages · Page 1 of 1 (latest)

honest vessel
#

Hello, Id like to figure out How I can find players that are near a mob to add them as a target when a mob spawns, to do this I need to get a player inside creature spawn event. How could I do this?

normal torrent
#

getNearbyEntities

honest vessel
#

or get the player from it?

honest vessel
#

how could I use a predicate in this situation?

#

Collection entitiesnearpig = zombifiedpiglin.getNearbyEntities(1000, 1000, 1000); code for getting nearby entities

normal torrent
#

Read the docs

honest vessel
#

how would I get the player object for the predicate?

normal torrent
#

You get the entity object

#

And check if it is a player

honest vessel
#

after checking if it is a player how do I get the player object from the collection?

normal torrent
#

Loop over each element and it should be a player