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

[Solved] How to get the item meta here

Discussion in 'Development' started by BEcraft, Jan 15, 2017.

  1. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Hi I would like to know how to get the meta when player hold a item for example 351:2 here:
    PHP:
    if($player->getItemInHand()->getId() == "351"){
                            
    $level->addParticle(new FlameParticle(new Vector3($posX$posY+1$posZ)));
                            
    $level->addParticle(new HappyVillagerParticle(new Vector3($posX+0.5$posY+1$posZ)));
                            
    $level->addParticle(new HappyVillagerParticle(new Vector3($posX$posY+1$posZ+0.5)));
                    }
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
    $item->getDamage()
    Where $item is an Item object.
     
  3. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    I meant here xD
    PHP:
    public function AddParticle(){
                foreach(
    $this->getServer()->getOnlinePlayers() as $player){
                    
    $posX $player->x;
                    
    $posY $player->y;
                    
    $posZ $player->z;
                    
    $level $player->getLevel();
                    
    //$lapis = Item::get(351, 4, 1);
                    
    if($player->getItemInHand()->getId() == "351"){
                            
    $level->addParticle(new FlameParticle(new Vector3($posX$posY+1$posZ)));
                            
    $level->addParticle(new HappyVillagerParticle(new Vector3($posX+0.5$posY+1$posZ)));
                            
    $level->addParticle(new HappyVillagerParticle(new Vector3($posX$posY+1$posZ+0.5)));
                    }
                    }
                }
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    PHP:
     $handItem $player->getItemInHand();
    if(
    $handItem->getId() === 351 && $handItem->getDamage() === 2) {
     
    BEcraft likes this.
  5. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Thanks @Sandertv :D
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    No problem, glad I could help.
     
    BEcraft 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.