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

Ore gen

Discussion in 'Development' started by BattleAlan, Mar 25, 2019.

  1. BattleAlan

    BattleAlan Spider

    Messages:
    13
    Why it dont work?
    Code:
    <?php
    declare(strict_types=1);
    
    namespace Alan;
    use pocketmine\scheduler\PluginTask;
    use pocketmine\Server;
    use pocketmine\block\Block;
    use pocketmine\event\Listener;
    use pocketmine\math\Vector3;
    use pocketmine\item\Item;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\Level;
    use pocketmine\plugin\PluginBase;
    use Alan\Task\DiamondGenTask;
    
    class Main extends PluginBase {
        public function onEnable() {
            $this->scheduler();
        }
        public function scheduler() {
                $this->getScheduler()->scheduleRepeatingTask(new DiamondGenTask($this), 5 * 20);
        }
    }
    Here the effect task.
    Code:
    <?php
    
    namespace Alan\Tasks;
    
    use Alan\Main;
    use pocketmine\scheduler\PluginTask;
    use pocketmine\Server;
    use pocketmine\block\Block;
    use pocketmine\math\Vector3;
    use pocketmine\Level;
    use pocketmine\scheduler\Task;
    use pocketmine\event\Listener;
    use pocketmine\item\Item;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\block\Block;
    
    class DiamondGenTask extends Task
    {
        /** @var Main */
        private $plugin;
    
        /**
         * CactusTask constructor.
         * @param Main $plugin
         */
        public function __construct(Main $plugin)
        {
            $this->plugin = $plugin;
        }
    
        /**
         * @param $currentTick
         */
        public function onRun(int $currentTick)
        {
        $level = $this->getOwner()->getServer()->getLevelByName('Alazar');
            if($level instanceof Level) {
                $gen = new \pocketmime\block\White_glazed_terracotta();
                $tile = $level->getTile(new Vector3($gen->getX() , $gen->getY()+1, $gen->getZ()));
                if($tile instanceof Chest){
                    $chest = $tile->getInventory();
                    $chest->addItem(Item::get(264, 0, 1));
                }
            }
        }
    }
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    there are a few reasons, level may be null, $gen is not defined, coordinates may be wrong, tile is not a chest
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Explain what "not work" means. What debugging attempts have you tried?
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    There are other errors such as wrong use statement for Level and missing use statement for Chest in DiamondGenTask
    You instantiated a new Block instance which have no coordinates defined in it and tried to get coordinates from it
     
  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.