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

Why setblock() crashes

Comments in 'Plugin Development' started by ButterCoder, Jun 21, 2015.

  1. ButterCoder
    Offline

    ButterCoder New Member

    Joined:
    Jun 18, 2015
    Posts:
    8
    Minecraft User:
    ButterCoder
    Hi I'm new to plugin development. I want to use this setblock function, but when I tap the stone the game crahes and nothing happens if I remove the "$level->setBlock($pos, $block);" line it won't crash.




    PHP:
    <?php

    namespace ButterPack;


    use 
    pocketmine\Player;
    use 
    pocketmine\Entity;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\block\Cobblestone;
    use 
    pocketmine\network\protocol\UseItemPacket;
    use 
    pocketmine\level\format\mcregion\Chunk;

    class 
    Main extends PluginBase implements Listener{
       


        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
       
       
           public function 
    onPlayerInteract(PlayerInteractEvent $event) {
            if(
    $event->getItem()->getId() === 280){
                if(
    $event->getBlock()->getId() === 1){
                    if(
    $event->getFace() === 1){
                            
    $this->getLogger()->info(" Touched stone" );
                            
    $pos = new Vector3(13176127);
                            
    $block Block::get(40);
                            
    $level "world";
                           
                            
    $level->setBlock($pos$block);
                            
    $this->getLogger()->info($pos);
                           
                           
                           
                           
                           
                           
                        }
                    }
                }
            }
       
       
       
        public function 
    onDisable(){
            
    $this->getLogger()->info("ButterPack disabled");
        }



    }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $level must be an object of Level, not a world name. Use $this->getServer ()->getLevelByName ("world") instead.
    ButterCoder likes this.
  3. ButterCoder
    Offline

    ButterCoder New Member

    Joined:
    Jun 18, 2015
    Posts:
    8
    Minecraft User:
    ButterCoder
    omg Thanks!

Share This Page

Advertisement