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

Drop item

Comments in 'Plugin Development' started by BSHRMG, May 4, 2016.

  1. BSHRMG
    Offline

    BSHRMG New Member

    Joined:
    Mar 15, 2016
    Posts:
    21
    Hello I want to know how to set when a player break a block it drops a random item like lucky block?:)
  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    function onBreak(BlockBreakEvent $ev){
        switch(
    $ev->getBlock()->getId()){
            case 
    1//If break Block ID 1
                
    $ev->setDrops(/* Drop Block or Item Here */);
            break;
        }
    }
    Example,
    PHP:
    function onBreak(BlockBreakEvent $ev){
        switch(
    $ev->getBlock()->getId()){
            case 
    1:
                
    $ev->setDrops(array(Block::get(mt_rand(1,20),0,1))); //Drop 1 Block which id is 1 to 20 (random)
            
    break;
        }
    }
    Last edited: May 4, 2016
    BSHRMG likes this.
  3. BSHRMG
    Offline

    BSHRMG New Member

    Joined:
    Mar 15, 2016
    Posts:
    21
    Thank you :D

Share This Page

Advertisement