Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Detecting Entity around an entity?

Comments in 'Plugin Development' started by JonsMC, Aug 27, 2016.

  1. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    hey, i want to detect any entity with the same network id as my main entity in 5 blocks radius, what method and event should i use?
  2. Yeelze
    Offline

    Yeelze New Member

    Joined:
    Apr 2, 2016
    Posts:
    31
    Minecraft User:
    Yeelze
    Hmm you can use @CraftYourBukkit method.
    Muqsit and HotFireyDeath like this.
  3. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Different network id means different mob type, for example
    • Falling Block: 21
    • Creeper: 50
    • Slime: 55
    • Cow: 92
    Try this
    PHP:
    $same = [];
    foreach(
    $player->getViewers() as $entity) {
       if(
    $entity->distance($player) <= 5) {
           if(
    $entity::NETWORK_ID === $player::NETWORK_ID$same[] = $entity;
       }
    }
    Or use 'instanceof'

    Muqsit and Yeelze like this.
  4. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Seems like no one know what i mean :/, i was meaning that i want to check Entity around an Entity if they have the same network id and Both entity aren't instaceof Player
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Still hard to understand, can you please explain your situation there can be one more way to accomplish what you want.
  6. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    So, i have a creeper and it's network_id is 50, then, i spawn another Creeper in the radius of 5 blocks around the first creeper, how can i detect if the seccond creeper is in the radius of 5 blocks around the first creeper?
  7. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    PHP:
    if ($entity1->distance($entity2) <= 5){
     if (
    $entity1::NETWORK_ID === $entity2::NETWORK_ID){
      if (!(
    $entity1 instanceof Player) && !($entity2 instanceof Player)){
       
    //All conditions are met?
      
    }
     }
    }
    where $entity1 is your first entity and $entity2 is your second entity.
  8. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Welp, need help getting entity1 and entity2 in EntityMoveEvent :/ seems like it is possible but i just dont know how
  9. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    EntityMoveEvent only has one entity, so I assume you know your second entity object already.
    Just set $entity1 to the entity in EntityMoveEvent.
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Task? Level::getEntities(), foreach ?
  11. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    :/
  12. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    i just discovered this:
    PHP:
    $event->getEntity()->getLevel()->getNearbyEntities()
  13. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    EntityMoveEvent is deprecated. Use a Task instead.
    Primus likes this.
  14. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Why use task?
  15. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Can i either using getNearbyEntities?
  16. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    My ideas :p
    PHP:
    public function onEnMove(EntityMoveEvent $ev) {
          
    $en $ev->getEntity();
         if(
    $en->getLevel()->getNearbyEntities($en->getBoundingBox()->grow(555), $en)::NETWORK_ID === $en::NETWORK_ID) {
          
    //do something 
           
    }
    }
    although i could wrong :p
  17. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
  18. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    I don't see how a task can detect entity :/, can you help?
  19. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    You're all forgot "floor"
  20. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Explain? ...

Share This Page

Advertisement