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

setBlock dont work

Comments in 'Plugin Development' started by Player7221, Mar 4, 2016.

  1. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Hello!
    I have problem, because setBlock dont work why?
    Code:
                    $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->getX(), $e->getBlock()->getY(), $e->getBlock()->getZ()), Block::get(1, 0));
    0 errors, but dont work, why?
  2. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    What event?
  3. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    BlockBreakEvent
  4. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
  5. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
    will you set if player break block spawn block back?
  6. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You forgot the third argument in Block::get().
    Player7221 likes this.
  7. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
  8. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->getX(), $e->getBlock()->getY(), $e->getBlock()->getZ()), Block::get(Block::STONE));
    Player7221 likes this.
  9. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Now 0 errors, but setBlock dont work..

    My Event:
    Code:
     public function onBlockBreakEvent(BlockBreakEvent $e)
        {
            if($e->getBlock()->getId() === 1)
            {
                $blockUnder = $e->getBlock()->getLevel()->getBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y - 1, $e->getBlock()->z));
    
                if($blockUnder->getId() === 121)
                {
                    $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y, $e->getBlock()->z), Block::get(Block::STONE));
                    $e->getPlayer()->sendMessage("Na dole jest kamien!");            
                }            
            }
        }
    }
    
  10. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Please, help me.
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Does it send the message?
    Player7221 likes this.
  12. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    Yes, just setBlock dont work :(.

    All Class:
    Code:
    <?php
    
    namespace StoneGenerator;
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\block\BlockBreakEvent;
    use pocketmine\event\Listener;
    use pocketmine\math\Vector3;
    use pocketmine\block\Block;
    use pocketmine\level\Level;
    
    class Main extends PluginBase implements Listener
    {
        public function onEnable()
        {
            $this->saveDefaultConfig();
            $this->getServer()->getPluginManager()->registerEvents($this, $this);
        }
    
        public function onDisable()
        {
    
        }
      
        public function onBlockBreakEvent(BlockBreakEvent $e)
        {
            if($e->getBlock()->getId() === 1)
            {
                $blockUnder = $e->getBlock()->getLevel()->getBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y - 1, $e->getBlock()->z));
    
                if($blockUnder->getId() === 121)
                {
                    $e->getBlock()->getLevel()->setBlock(new Vector3($e->getBlock()->x, $e->getBlock()->y, $e->getBlock()->z), Block::get(Block::STONE));
                    $e->getPlayer()->sendMessage("Na dole jest kamien!");           
                }           
            }
        }
    }
    
    Last edited: Mar 4, 2016
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Cancel the event. PocketMine will change the block to air AFTER the event is called. So even if the plugin changed the block to stone, PocketMine will still change it to air afterwards. To prevent this behaviour, simply cancel the event.
    CraftYourBukkit and applqpak like this.
  14. Player7221
    Offline

    Player7221 New Member

    Joined:
    Feb 15, 2016
    Posts:
    33
    I must use $e->setCancelled();? If yes it stop event and 0 drop cobblestone etc... And if I want add task later?
  15. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Eh what?
    Drop it yourself then
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, you can schedule a delayed task. But that's not the best solution. In this case, you can just foreach the result of getDrops and drop the items one by one.

Share This Page

Advertisement