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

Solved getDrops() method

Comments in 'Plugin Development' started by Creeperface, Aug 2, 2015.

Thread Status:
Not open for further replies.
  1. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    If I want how to get it to work? I think it's you that wants to know how to get it to work.
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    sorry there should be "know" instead of "want" xD
  3. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Do you want the code or no?
    HotFireyDeath likes this.
  4. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    :p
    PHP:
    foreach($block->getDrops() as $item){
        
    $player->getInventory()->addItem($item);
    }
    For more help in the future remember to like and follow! ;)
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    But it still wont work
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Wrong place, maybe? It's your problem. Tell me what code you used.
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    It say argument 1 passes to getDrops() must be instance of Item none given
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Code?
  10. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I didnt test your code but im sure it wont work
  11. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Yes it will. And I'm sure your code won't work without what I gave you. :p
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Hmm i use $event->getDrops() and wait for PEMapModder response
  13. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    @Gamecrafter you're wrong... and @Creeperface you too xD

    Looking at the event code, you will notice that there's a specific "getDrops()" method, which returns an item array with all the items that will be dropped, so use something like this:

    PHP:
    public function onBlockBreak(BlockBreakEvent $event){
      
    $event->getPlayer->getInventory()->addItem($event->getDrops());
    }
    And if you want to cancel the already added drops from going into the ground too, add this line after the player-related one:

    PHP:
    $event->setDrops([]);
    Last edited: Aug 2, 2015
    Creeperface likes this.
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    So how should i use $block->getDrops()?
  15. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Ok i know i said it before you but what is $block->getDrops() ?
  17. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    That is just a function for consulting what type of items does a block CAN drop, and you need to specify the Item used to break that block, so it return the correct items ;) no needed in your case :p
  18. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
  19. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Technically I'm not wrong, just gave him the solution to something else. But there is a Block::getDrops(). He didn't exactly say it was for an event, so I just assumed it was for a block.
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @Gamecrafter @iksaku please read the docs. It clearly specifies that the Block::getDrops function requires an Item parameter.

    I believe that (by guessing and vague memory) $item is about what item to break the block with. For example if you pass a pickaxe to a stone getDrops, it will return a cobblestone, but if it is something else, it will return nothing.
    Creeperface likes this.
Thread Status:
Not open for further replies.

Share This Page

Advertisement