1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How do you do that after destroying Stone with a golden pick, you cancel the task of renewing?

Discussion in 'Development' started by Krystian Sqiun, Jun 9, 2018.

  1. Krystian Sqiun

    Krystian Sqiun Creeper

    Messages:
    4
    How do you do that after destroying Stone with a golden pick, you cancel the task of renewing?

    public function onBreak(BlockBreakEvent $event){
    $blok = $event->getBlock();
    $gracz = $event->getPlayer();
    $y = $blok->getFloorY();
    $x = $blok->getFloorX();
    $z = $blok->getFloorZ();
    if($blok->getId() == 1){
    $task = new Task($this, $event->getBlock()->getFloorX(), $event->getBlock()->getFloorY(), $event->getBlock()->getFloorZ());
    $this->getServer()->getScheduler()->scheduleDelayedTask($task, 30);
    }
    }
    }

    Task.php
    <?php

    namespace StoneFarm;

    use pocketmine\block\Block;
    use pocketmine\block\Air;
    use pocketmine\block\Stone;
    use pocketmine\math\Vector3;
    use pocketmine\scheduler\PluginTask;

    class Task extends PluginTask{

    private $z;
    private $y;
    private $x;
    private $gracz;

    public function __construct($gracz, $x, $y, $z){
    parent::__construct($gracz);
    $this->x = $x;
    $this->y = $y;
    $this->z = $z;
    $this->gracz = $gracz;
    }



    public function onRun($currentTick){
    $level = $this->gracz->getServer()->getLevelByName("world");
    if($level->getBlock(new Vector3($this->x, $this->y, $this->z))->getId() == 0) {
    $level->setBlock(new Vector3($this->x, $this->y, $this->z), new Stone());
    }
    }
    }
     
  2. Epic

    Epic Creeper

    Messages:
    4
    please make your code clear next time by making it inside [PHP*] [/PHP*] (the * isn't included)
     
    xXNiceAssassinlo YT likes this.
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    or do it for them, it's frankly quite easy
    PHP:
    <?php
    public function onBreak(BlockBreakEvent $event){
    $blok $event->getBlock();
    $gracz $event->getPlayer();
    $y $blok->getFloorY();
    $x $blok->getFloorX();
    $z $blok->getFloorZ();
    if(
    $blok->getId() == 1){
    $task = new Task($this$event->getBlock()->getFloorX(), $event->getBlock()->getFloorY(), $event->getBlock()->getFloorZ());
    $this->getServer()->getScheduler()->scheduleDelayedTask($task30);
    }
    }
    }

    //Task.php
    <?php

    namespace StoneFarm;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\block\Air;
    use 
    pocketmine\block\Stone;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\scheduler\PluginTask;

    class 
    Task extends PluginTask{

    private 
    $z;
    private 
    $y;
    private 
    $x;
    private 
    $gracz;

    public function 
    __construct($gracz$x$y$z){
    parent::__construct($gracz);
    $this->$x;
    $this->$y;
    $this->$z;
    $this->gracz $gracz;
    }



    public function 
    onRun($currentTick){
    $level $this->gracz->getServer()->getLevelByName("world");
    if(
    $level->getBlock(new Vector3($this->x$this->y$this->z))->getId() == 0) {
    $level->setBlock(new Vector3($this->x$this->y$this->z), new Stone());
    }
    }
    }
    there done!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.