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

Need help with code for my plugin.

Comments in 'Plugin Development' started by IcePL, Mar 6, 2016.

  1. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Hi i write plugin to drop items from stone and I have a problem because I not get drop:(
    This is the code:
    PHP:
    <?php

    namespace DawixQMC\drop;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase implements Listener{
      
        public function 
    onEnable(){
          
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
          
    $this->getServer()->getLogger()->info(TextFormat::GREEN."[PocketDrop] Activated!");
        }
      
        public function 
    blockBreak(BlockBreakEvent $event){
                      
                        
    $block $event->getBlock();
                        
    $player $event->getPlayer();
                        
    $id $block->getId();
                      
                        if(
    $id === Block::STONE){
                            switch(
    mt_rand(1200)){
                          
                    case 
    1:
                            
    $player->getLevel()->setBlock($block, new Block(Block::AIR));
                            
    $player->getLevel()->dropItem($block, new Item(26401));
                            
    $player->sendMessage("PocketMC Diamond!");
                            break;
                            }
                            }
        }
    }
    Any player edit this code for me or check what is wrong?
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    do you know how it works? it randomly happens.
  3. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Yes I know that random but dug a lot of cobble and nothing could
  4. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    first, Level::dropItem($i) requires an item object...
    Nawaf_Craft1b likes this.
  5. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    I do not know English well
    You can explain to me what I have to add improved?

Share This Page

Advertisement