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

[NEW API] AddItem function.

Comments in 'Plugin Development' started by Killman2, Jun 28, 2014.

  1. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Hi! I have a question. In the old API we did $issuer->addItem(); how do we do this in the new one?
  2. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    you mean adding an item to there inventory ?
  3. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Yeah
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    435
    Plugins:
    4
    Minecraft User:
    Lambo
    Yes.

    Edit: I thought you were asking if we had it.
    Anyway, here is how to do it:
    PHP:
    $player->getInventory()->addItem(Item::get(id),damage,count);
    $player->getInventory()->sendContents($player);
  5. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    just use "give" . $sender . "57 64"
  6. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
  7. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Thanks :)
  8. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Thanks
  9. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    435
    Plugins:
    4
    Minecraft User:
    Lambo
    Or use the actual function ;)
  10. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    is there a difference between my function and your's ?
  11. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    And another thing, how do you get the ID of a block or a an item?
    like
    PHP:
    $event->getBlock()->getID()
    ?
  12. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    435
    Plugins:
    4
    Minecraft User:
    Lambo
    No, but it can get quite annoying if you have console debugging on and it keeps showing "console ran: blabla".
    And I think it should be
    PHP:
    "give ".$player->getName()." id count"
  13. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    435
    Plugins:
    4
    Minecraft User:
    Lambo
    Yep.
    I mean, that's right :p
  14. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Ok,
    thanks
  15. Dutok
    Offline

    Dutok Notable Member Plugin Developer

    Joined:
    Jun 20, 2014
    Posts:
    372
    Plugins:
    3
    Minecraft User:
    Dutok
    Yes, that will return the ID of the item or block.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Mislocated parentheses ;)

    Also, note that you can pass infinite number of items:
    PHP:
    $player->getInventory()->addItem(Item::get($id /* damage default to 0 and count default to 1, can be omitted */ ), Item::get($id2), Item::get($id3));
  17. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Can you still use $data["target"] with 1.4 API?
  18. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    its getPlayer()
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes if you have $data defined of course. But you don't have anything that defines $data, do you?
  20. swagboy47
    Offline

    swagboy47 Active Member

    Joined:
    Jun 10, 2014
    Posts:
    445
    Minecraft User:
    swagking
    ops :p

Share This Page

Advertisement