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

Change block every second?

Comments in 'Plugin Development' started by Legoboy0215, May 17, 2015.

  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Is it possible to change the block type at X:125 Y:56 Z:63 every 1 second? Maybe One second ago it was white wool, now it maybe black wool. It may look like it is flashing.
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PHP:
    <?php
    namespace your\own\name\space;
    use 
    pocketmine\plugin\PluginTask;
    class 
    ChangeBlockTask extends PluginTask{
      private 
    $pos;
      private 
    $list;
      private 
    $current 0;
      public function 
    __construct(Main $mainPosition $pos, array $list){
        
    parent::__construct($main);
        
    $this->pos $pos;
        
    $this->list $list;
        if(
    count($list) === 0){
          throw new \
    InvalidArgumentException;
        }
      }
      public function 
    onRun($t){
        
    $this->pos->getLevel()->setBlock($this->pos$this->list[$this->next()]);
      }
      private function 
    next(){
        
    $this->current++;
        if(
    $this->current >= count($this->list)) $this->current 0// loop back to the initial item
        
    return $this->current;
      }
    }
    PHP:
    <?php
    namespace your\own\name\space;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\plugin\PluginBase;
    class 
    Main extends PluginBase{
      public function 
    onEnable(){
        
    $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new ChangeBlockTask($this, new Position(1255663$this->getServer()->getDefaultLevel()), [Block::get(Block::WOOL0), Block::get(Block::WOOL15)]), 2020);
      }
    }
    Last edited: May 17, 2015
    Jon likes this.
  3. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    wouldnt it lag?
    LDX and HotFireyDeath like this.
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    2 different files?
  5. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    I think so.

    Isn't it best to put merge all schedulers?
  6. GamesLoad
    Offline

    GamesLoad Active Member

    Joined:
    Jun 28, 2014
    Posts:
    106
    Minecraft User:
    GamesLoad
    ClassNotFoundException: "Class pocketmine\task\PluginTask not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use the edited content.
    yep
    why?
  8. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    change pocketmine\task\PluginTask to pocketmine\scheduler\PluginTask
  9. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    So, like this?
    blockchanger\src\legoboy\blockchanger\main.php
    and
    blockchanger\src\legoboy\blockchanger\task.php
  10. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    for example, if you setBlock per tick, the Server lags IF you do that more than 100+. well im just assuming in my experience with WEA.
  11. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    No!
    only the imports/use. please compare analytically.
  12. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    its still wrong xD it must be scheduler not plugin :p
  13. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    So what should I name it?
  14. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    He just asked to change one block.
    Same as the class name of that file.
    ChangeBlockTask.php
    Main.php

    Of course, change the namespace first.
  15. GamesLoad
    Offline

    GamesLoad Active Member

    Joined:
    Jun 28, 2014
    Posts:
    106
    Minecraft User:
    GamesLoad
    PHP:
    <?php
    namespace robozeri\ChangeBlock;
    use 
    pocketmine\scheduler\PluginTask;
    class 
    ChangeBlockTask extends PluginTask{
      private 
    $pos;
      private 
    $list;
      private 
    $current 0;
      public function 
    __construct(Main $mainPosition $pos, array $list){
        
    parent::__construct($main);
        
    $this->pos $pos;
        
    $this->list $list;
        if(
    count($list) === 0){
          throw new \
    InvalidArgumentException;
        }
      }
      public function 
    onRun($t){
        
    $this->pos->getLevel()->setBlock($this->pos$this->list[$this->next()]);
      }
      private function 
    next(){
        
    $this->current++;
        if(
    $this->current >= count($this->list)) $this->current 0//
        
    return $this->current;
      }
    }
    PHP:
    <?php
    namespace robozeri\ChangeBlock;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\plugin\PluginBase;
    use 
    robozeri\ChangeBlock\ChangeBlockTask;
    class 
    Main extends PluginBase{
      public function 
    onEnable(){
        
    $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new ChangeBlockTask($this, new Position(1294141$this->getServer()->getDefaultLevel()), [Block::get(Block::WOOL0), Block::get(Block::WOOL15)]));
      }
    }

    Sorry because I know from error it does not work?
    Last edited by a moderator: May 17, 2015
  16. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Thanks! Everyone!
    A little question...
    Will it being multiple blocks hard?
  17. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Use my edited content. I changed the Main class a bit, and also the first few lines of the ChangePluginTask class.
  18. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

    Joined:
    Nov 7, 2013
    Posts:
    1,167
    Plugins:
    4
    Minecraft User:
    iJoshuaHD
    Simple solution: Please, LEARN BASICS of PHP.
    Samueljh1, LDX, iksaku and 6 others like this.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PSR-4 isn't basics of PHP.
    Falk likes this.
  20. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Code:
    [CRITICAL] ClassNotFoundException: "Class legoboy\blockchanger\main not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 111
    
    What?!

Share This Page

Advertisement