1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved How to get the type of an entity?

Discussion in 'Development' started by EndermannbugZJFC, Jun 6, 2020.

  1. EndermannbugZJFC

    EndermannbugZJFC Slime

    Messages:
    84
    GitHub:
    endermanbugzjfc
    Can anyone tell me how to get the type of an entity please? (Entity class)
     
  2. fevio

    fevio Spider Jockey

    Messages:
    33
    From an event?
     
  3. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Entity->getId(). If I'm not wrong, the identifier will return one of these ids.
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    /** @var Entity $entity */
    if($entity instanceof EntityTypeYouWant) {

    }
     
  5. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    // Returns Identifier, used to reference entities through server <-> client communication.
    /** @var Entity $entity */
    $entity->getId();

    // Gets the class name, with namespace
    get_class($entity);

    // However if you want just class name, without namespace, use the function below
    get_class_name($entity);

    function 
    get_class_name($classname)
    {
        if (
    $pos strrpos($classname'\\')) return substr($classname$pos 1);
        return 
    $pos;
    }

    // Entity Network ID - the identifier for entity type. Refer to list that @Diduhless gave
    $entity::NETWORK_ID
    It is a id to refer entity in the world, but network id is to refer entity type.
     
    Diduhless likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.