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

Solved How to use setDrops()

Comments in 'Plugin Development' started by Rspuds, Aug 12, 2015.

  1. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    I'm making a lucky blocks plugin and I'm trying to use the setDrops function to change the drops of the block to be the reward they get. So I need to know the proper way to use the setDrops function. This includes how to add multiple item drops and the amount of each drop. I'm guessing this would be the best way to do what I'm trying to achieve but if there is a better why i'm willing to give it a try. One more thing, I don't want to have the items go straight into the players inventory if possible. I want them to fall as an entity have make the player pick them up.

    Thanks for any help!
  2. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    on BlockBreakEvent
    Code:
    if($event->getBlock()->getId ==/*block id*/){
    $event->setDrops(/*items(s)*/);
    }
    
  3. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    I have tried the time id's as well as item::stone for example like you showed and neither of these worked...
  4. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    use block id
  5. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    ok he's my basic code I used to test setDrops()

    PHP:
            public function onBlockBreak(BlockBreakEvent $event){
            
    $player $event->getPlayer();
            
    $block $event->getBlock();
            
    $blockID $block->getId();
            if(
    $blockID === 1){
                
    $drops = array(1);
                
    $event->setDrops($drops);
                }
            }
        
    I tryed putting 1 where the variable $drops is but it said needs to be an array so i did this. When I do it this way it doesn't have any drops so i'm guessing it isn't item ID
  6. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    PHP:
    public function drops(BlockBreakEvent $event){
    if(
    $event->getBlock()->getID() === 56){
    $drops = array(Item::get(Item::DIAMOND_CHESTPLATE,0,1));
    $event->getDrops($event->setDrops($drops));
    }
    taken from my servercore
    jojoe77777 and Rspuds like this.
  7. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    It works! Thanks for the help!
    TryoneLegendZzz likes this.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    99% of the time, PocketMine uses Item objects as parameters instead of item IDs.

Share This Page

Advertisement