Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to get count of an item

Comments in 'Plugin Development' started by minebuilder0110, Jan 13, 2016.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Well, the title says it all. I defined $handItem by something like
    PHP:
    $handItem $sender->getInventory()->getItemInHand()
    //I don't know if this is the right way to define it, but you get the idea.
    . I would like to know how would I get how many items I have in my hand, and the item ID of it.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    https://github.com/PocketMine/Pocke.../pocketmine/inventory/PlayerInventory.php#L83
    The getItemInHand() function returns an instance of pocketmine\item\Item.
    Now look at the Item class declaration.
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L1443
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L1447
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L1419
    It has three public functions that match what you are asking for.
    getId()
    getDamage()
    getCount()

    Next time before asking, try browsing the source code or documentation to find the answer yourself.
  3. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    :)
  4. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Oh right, it reurned item instance... I was going through inventory source code... :oops:
    ?
  5. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    PHP:
    $handItem->getCount();
    Last edited: Jan 14, 2016
  6. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    There is no such function
    KubixQ, basprohop and PEMapModder like this.
  7. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    PHP:
    $handItem->getCount();
    **
  8. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    I meant getCount();
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And I have already mentioned it in my first post.
    XFuryMCPE likes this.
  10. XFuryMCPE
    Offline

    XFuryMCPE Active Member Plugin Developer

    Joined:
    Jun 19, 2015
    Posts:
    137
    Plugins:
    2
    Minecraft User:
    XFuriousMC
    *facepalm*
    KubixQ likes this.

Share This Page

Advertisement