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

Solved How to find <ID meta> in event

Discussion in 'Development' started by xDillnn, Mar 24, 2018.

  1. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    Hello. I need help to find how to find the <ID Meta> of a block in a InteractEvent

    Example with Interact:
    PHP:
    public function onInteract(PlayerInteractEvent $e) {
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $item Item::get(001);
            
    $i $e->getItem();
            if(
    $block->getId() === 54){
                if(
    $i->getCustomName() === "§2§lCub §fCrate Key" && $i->getId() === 131) {
                    
    $e->setCancelled();
    Where it says:
    PHP:
    if($block->getId() === 54){
    I was wondering if i could get the <ID & Meta>. Hopefully someone has a solution.
    Please help me.
    Thanks.
     
    Last edited: Mar 24, 2018
  2. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    $block->getDamage()
     
  3. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    Where do I add
    PHP:
    $block->getDamage()
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    it returns the block meta
     
  5. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    I have a feeling it's like this if I'm correct.
    PHP:
    public function onInteract(PlayerInteractEvent $e) {
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $item Item::get(001);
            
    $i $e->getItem();
            if(
    $block->getId() === 54) {
                if(
    $block->getDamage() === 1) {
                    if(
    $i->getCustomName() === "§2§lCub §fCrate Key" && $i->getId() === 131) {
                        
    $e->setCancelled();
     
  6. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Why are you trying to receive the item twice?
     
  7. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    Sorry I'm still a little new to this....
     
  8. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    You can do just like this, very simple:
    PHP:
    public function onInteract(PlayerInteractEvent $e) {
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
        
                    if(
    $block->getCustomName() === "§2§lCub §fCrate Key" && $block->getId() === 131 && $block->getDamage() === 1) {
                   
    //whatever you want do to here
                    
    }
                    }
    I do not know the reason for executing several 'if' clause, you have to explain if the player interaction in PlayerInteractEvent is clicking on the HotBar or clicking on the map block. What do you really want to do?
    If you want to detect a block on the ground or floor (map) you should do the variable $block like this:
    PHP:
    $block->getBlock();
    on the top example that i showed but if you want to detect a block on the hotbar (hand of the player) you should use variable
    PHP:
    $block $player->getInventory()->getItemInHand();
     
    Last edited: Mar 24, 2018
  9. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    you are checking if id of item is 54, that means it can't change to 131
    what exactly you want to do?
     
  10. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    PHP:
    public function onInteract(PlayerInteractEvent $e) {
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
       
                if(
    $block->getId() === 54) {
                 
                   
    $player->sendMessage("Damage from that chest you tapped: ".$block->getDamage());
                 
                }
        }
     
  11. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    I want to get the damage of The chest A.K.A "54" so I don't have to use the same chest for multiple crate keys. I want multiple chest and each key has its designated chest.
     
  12. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    Where do you add that?
     
  13. xDillnn

    xDillnn Spider

    Messages:
    9
    GitHub:
    xdillnn
    Fixed I got it working
     
  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.