Solved Nearby Entities in all directions

Discussion in 'Plugin Development' started by GCD55, Jan 14, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    GCD55

    So I've played with NearByEntities a bit and have a question:

    Maybe its me but it seems like when used the radius checked is flat.
    I spent several hours messing around until I got what I wanted which works fine for me and avoided using nearByEntities at all. However, I would like to get clarity on how this function works.

    Specifically: is there a way to specify an area of
    10 blocks around the X & Z coords
    and then
    4 levels high from the floor Ycoord to the roof Ycoord???

    What would it look like coded?
     
  2. Offline

    Zombie_Striker

    @GCD55
    Are you looking for a radius or a box when getting the entities?

    If you need a box, use getNearbyEntnties. If you need to do a radius check, you will need to compare the distances between entities (which you can do by using Location#distance(Location2) )

    Either way, to answer your question, yes. Use getNeatbyEntities(10,4,10) to get all the entities within 10 blocks from the sides of the entities, and 4 blocks above and below the entity.
     
  3. Offline

    Adamki11s

    @GCD55
    https://hub.spigotmc.org/javadocs/bukkit/

    Code:
    Entity e;
    
    List<Entity> near = e.getNearbyEntities(5.0, 2.0, 5.0);
    That would get you all nearby entities within 5 X/Z blocks and 2 Y blocks, not sure if you wanted that or double, in which case just double all the parameters. As the previous poster mentioned this checks in a bounding box, however I'd imagine that that's fine for you unless you have some specific requirement to gather entities in a spherical radius.
     
    GCD55 likes this.
  4. Offline

    GCD55

    @Zombie_Striker

    Use getNeatbyEntities(10,4,10) to get all the entities within 10 blocks from the sides of the entities, and 4 blocks above and below the entity.

    Was the answer I was looking for, Thanks!
     
Thread Status:
Not open for further replies.

Share This Page