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

Return block ID by name

Discussion in 'Development' started by XdmingXD, Apr 8, 2017.

  1. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    PHP:
    if($event->getBlock()->getID() == Item::SIGN_POST || $event->getBlock()->getID() == Block::SIGN_POST || $event->getBlock()->getID() == Block::WALL_SIGN){
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
    if(
    $sign instanceof Sign){
    //blah..
    }
    }
    Can I do this?
    and is Item::SIGN_POST a must?
     
    Last edited: Apr 8, 2017
  2. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    Nope. Checking Item::SIGN_POST will make it wrong. Item::SIGN_POST may be a registered ID in Block Class, causing your IF statement dont work the way you wanted;)
     
    HimbeersaftLP, XdmingXD and MagicLJ like this.
  3. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    PHP:
    $block $event->getBlock()
    if(
    in_array($block->getId(), [Block::SIGN_POSTBlock::WALL_SIGN])){
    $sign $event->getPlayer()->getLevel()->getTile($block);
    if(
    $sign instanceof Sign){
    //blah..
    }
    }
    Actually, you can do this too
     
  4. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    This is an array?
     
  5. NIIP99

    NIIP99 Silverfish

    Messages:
    22
    GitHub:
    niip99
    IDs is not an array, but the way @SuperMaXAleX used is to declare 2 IDs (SIGN_POST and WALL_SIGN) together as an array. However, his way is not recommended.

    Yep. But, using IF statement directly is better than using in_array() in this case.
     
    Jack Noordhuis likes this.
  6. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    I'm using it every times x) This is working fine for me
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Meanwhile @dktapps wanted to override block IDs in ItemIds.php. What disaster would happen?
     
  8. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
  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.