Solved Location.getNearbyEntities() method?

Discussion in 'Plugin Development' started by GeorgeeeHD, Aug 8, 2014.

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

    GeorgeeeHD

    Is there a good way to do this? At the moment, I have just spawned in an Item at the Location I want then use Item.getNearbyEntities() then Item.remove();

    This isn't really a problem but I want to do it a better way as I feel this is not the best way and also it's not the best as sometimes you can see the item spawned in for a tiny bit.

    Thanks for any help :)

    (I would loop through all entities in the world then check the distance to the location i want but that could be laggy in a world with a lot of entities right?)
     
  2. Offline

    Garris0n

    Loop through the items in the world and check the distance.

    Make sure you compare with distanceSquared() and your radius squared, as the distance() method uses expensive sqrt() operations.
     
  3. Offline

    GeorgeeeHD

    Garris0n would that be laggy at all even if there were a lot of entities?
     
  4. Offline

    Garris0n

    Perhaps if there were enough it would be noticeable, but there's not exactly an alternative. What do you think the Entity#getNearbyEntities() method does?
     
  5. Offline

    GeorgeeeHD

    Garris0n hmm I'm guessing the same thing as your solution but uses the parameters as the distance.
     
  6. Offline

    NathanWolf

    Garris0n likes this.
  7. Offline

    Garris0n

    In the end, yeah. I tried to trace what the method does once and it's quite a lot of stuff involving hitboxes. I wouldn't be surprised if just looping through was more efficient, actually, although you don't get to use a box.
     
  8. Offline

    GeorgeeeHD

Thread Status:
Not open for further replies.

Share This Page