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

Anvil Inventory

Discussion in 'Development' started by abimalek, Nov 11, 2017.

  1. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    I'm working on a pouches plugin and I need to know how to open an anvil inventory to a player on PlayerInteractEvent and add items to it!!
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    PHP:
    /** @var $player pocketmine\Player */
    /** @var $pos pocketmine\level\Position */
    $inv = new pocketmine\inventory\AnvilInventory($pos); //This is basically a normal inv, you can handle it like a player inventory with just 2 slots.
    /** @var $item1 pocketmine\item\Item */
    /** @var $item2 pocketmine\item\Item */
    $inv->addItem($item1$item2); //Add items to the inv, like a player inv.
    $player->addWindow($inv);
     
    Vaxrp likes this.
  3. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Is this method possible with like a ChestInventory?
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Yes, but you need a tile.
     
  5. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    what would the api for that be like the use pocketmine\inventory\AddWindow?
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    What?
     
  7. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    the api for the addwindow
    what would it be
    would it be{ use pocketmine\Player\addWindow;
     
  8. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    :facepalm::facepalm::facepalm::facepalm::facepalm::facepalm::facepalm::facepalm::facepalm::facepalm::facepalm:

    addWindow is a function!!!!!!!!! omg help me pls
     
    jasonwynn10 and NickTehUnicorn like this.
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Are you trying to do this?
    Screenshot_20171112-231341.png
    I don't think you can do that in OOP. I don't know much about function aliases in namespaces.

    Player itself is an instance of \pocketmine\Player. You can call the function from that player instance.
    PHP:
    /** @var Player */
    $player->addWindow(...);
    Look into PocketMine's source code to see how it's being called and handled.
     
    Last edited: Nov 12, 2017
    jasonwynn10 likes this.
  10. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
  11. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    how about just trying that code without importing dogshit?
     
    Teamblocket likes this.
  12. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    pls tell what $pos is
     
  13. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Read the code:
    @var $pos pocketmine\level\Position
    Therefore $pos is a Positon object. (The position of the anvil)
     
  14. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    So it wiuld be $pos = pocketmine/level/Position;
     
  15. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    :facepalm:
    PHP:
    $pos = new Position($x$y$z$level);
     
    Teamblocket and jasonwynn10 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.