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

Entities

Discussion in 'Development' started by Teamblocket, Apr 23, 2017.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    how can I get a cow entity?
    public function onCow(EntityDeathEvent $event){
    if($event->getEntity() === ???){
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    How are you spawning the cow?
     
  3. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    You can try:
    PHP:
    //use pocketmine\entity\Cow;
    public function getCow(EntityDeathEvent $e){
    $entity $e->getEntity();
    if(
    $entity instanceof Cow){
    //Something here
    }
    }
     
    Primus likes this.
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    There is no Cow class in PMMP, that's why this question is odd.
     
    Sandertv and BEcraft like this.
  5. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Interesting xD
     
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    i don't want to spawn the cow i just want to check if they kill a cow
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    func getNetworkId(Entity $entity): int {
        return 
    get_class($entity)::NETWORK_ID;
    }
    Then you can check if it equals to Cow's network id
    PHP:
    getNetworkId($entity) === Cow::NETWORK_ID
    # Or, as I previously heard that Cow class does not exist
    getNwtworkId($entity) === 11 // According to http://minecraft.gamepedia.com/Pocket_Edition_data_values
     
    NickTehUnicorn, Zayd, BEcraft and 3 others like this.
  8. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    ok! thanks
     
  9. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    $entity::NETWORK_ID achieves the same result, so why waste that tiny amount of CPU time?
     
  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.