#One-Entity Selective getEntitiesWithin

18 messages · Page 1 of 1 (latest)

shrewd rampart
#

Hello there 🗿
I was doing some research in the server until i stumbled with the getEntitiesWithin. I takes every entity inside the area and i realized that you can apply filters such as ".filter(ent => ent.isPlayer())". But i was wondering, is it possible to just get one entity out of the many of the same type in the area?

timid jettyBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

swift mist
#

[0]

#

gets the first entity

#

(after the closing ))

shrewd rampart
#

(Im most probably incorrect, sorry im a newbie in here) So .filter(ent => ent.isPlayer())[0]?

#

let entities = level.getEntitiesWithin(AABB.of(player.x - area, player.y - 1.5, player.z - area, player.x + area, player.y + 1.5, player.z + area)).filter(ent => ent.isPlayer())

#

I got this example from a previous post

#

So how would the filter part be?

pliant sphinx
#

entities[0]

shrewd rampart
#

let entities[0] = level.getEntitiesWithin(AABB.of(player.x - area, player.y - 1.5, player.z - area, player.x + area, player.y + 1.5, player.z + area)).filter(ent => ent.isPlayer())

#

And it basically picks the first entity that appears when checking the area, right?

swift mist
#

let entity = level.getEntitiesWithin(blah blah).filter(ent => ent.isPlayer)[0]

#

or save the list to a variable then use what lexxie said
dont combine them

swift mist
shrewd rampart
#

I will close the ticket later when i test it. Im not at my pc at the moment

#

Anyways, thanks for the help!