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. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    hi i want to get drops of some block but which item should i put in $block->getDrops(Item $item); it should return me an array of Item objects to be dropped right?
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You don't need to put anything in getDrops(). It just returns an array of items.
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    *it should return array of items
  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
    What are you trying to say? I don't understand you.
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    look at documentation
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I don't get what you're trying to say. If you want someone to help you, try to be a bit more descriptive and specific about what you want to accomplish.
  8. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

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

    Gamecrafter

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

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    and whick item should i put into getDrops() ? :D
  11. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You don't NEED to. It returns an array of all the items that are dropped.
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i need it ;)
    PHP:
    public function getDrops(Item $item){
    if(!isset(
    self::$list[$this->getId()])){ //Unknown blocks
    return [];
    }else{
    return [
    [
    $this->getId(), $this->getDamage(), 1],
    ];
    }
    }
  13. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Just say what you need it for... If you don't no one will help you.
  14. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i tried it without Item parameter
    Code:
    [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\block\BlockBreakEvent' to 'Annihilation v1': Argument 1 passed to pocketmine\block\Wood::getDrops() must be an instance of pocketmine\item\Item, none given, called in C:\Users\Honza\Documents\PocketMine-MP\plugins\Annihilation\src\Annihilation\Arena\Arena.php on line 248 and defined on Annihilation\Arena\Arena
    
  15. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Full code, please?
  16. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    PHP:
    public function onBlockBreak(BlockBreakEvent $e){
        
    $e->getPlayer()->getInventory()->addItem($e->getBlock()->getDrops());
    }
  17. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Wrong, you can't add a whole array of items into the player's inventory at once. It has to be like this:
    iksaku likes this.
  18. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    but it said another error message
  19. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You want the code?
  20. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    yes if you want how to get it to work
Thread Status:
Not open for further replies.

Share This Page

Advertisement