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

PlayerInteractEvent not activating

Discussion in 'Development' started by Vaxrp, Nov 3, 2017.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    399 IS A NUMBER, but it is also a Object like Sander said if it is an OBJECT i can use get(399, 0) but if its a block I use

    getId() === 35
     
  2. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    399 is not object , Item.php is object and 399 can be only in it's constructor :facepalm: :facepalm: :facepalm: useless to help here
     
  3. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Just try this code and you will see:
    Again, if it doesn’t work, try adding elses to your ifs to find out your exact problem.

    Item::get() always returns an Item object (object).
    $item->getId() always returns the ID of the item (integer).

    That means $item->getId() === Item::get(1) can NEVER work because getId() returns an integer and Item::get() an Item object.
     
    Last edited: Nov 4, 2017
  4. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Checked and I think I found the problem. I tried using the onheld function with adding an effect at the same time as adding an item. The effect part worked because I got speed 1 when I held the block. Is there a diffrent way of adding the item?
     
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Why are you asking for another way to add items to inventory? Just use Item::get().
     
  6. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    PHP:
    $player->getInventory()->addItem(Item::get(101));
    Is the part that doesnt work because when I used that and made it add effects also it added the effects but didnt give the other item.
     
  7. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    Last edited: Nov 4, 2017
  8. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Are you sure there aren’t any errors in console? Are you sure that item has really been added to inventory?
     
  9. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Compare the IDs, not the objects. Comparing two different objects will make it false as they are, wait for it, different. They may be of the same class, but that doesn't mean they are the same object.

    Just look here for proof.
     
    Last edited: Nov 4, 2017
    jasonwynn10 and WinterBuild7074 like 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.