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

setBlock and getBlock, I need some help

Comments in 'Plugin Development' started by YoDevil, May 12, 2014.

  1. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    Hi, I'm new to Pocketmine plugin development.
    I'm creating a plugin for a minigame, so now i'm testing setBlock and getBlock.
    With my script I want to create a platform with a different color of wool every 5 seconds
    Here's my script:
    PHP:
    <?php

    /*
    __PocketMine Plugin__
    name=Blocks
    version=0.0.1
    author=YoDevil
    class=Blocks
    apiversion=12
    */

    class Blocks implements Plugin{
        private 
    $api;
        public function 
    __construct(ServerAPI $api$server false){
            
    $this->api $api;
        }

        public function 
    init(){
            
    $this->api->schedule(5*20, array($this"timer"), array(), false);
        }

        public function 
    __destruct(){

        }
       
        public function 
    timer(){
            
    $wool_color rand(1,15);
            
    $level $this->api->level->get("blocks");
            for (
    $x 1$x <= 20$x++) 
            {
                for (
    $z 1$z <= 20$z++) 
                {
                    
    $testforBlock $level->getBlock(new Vector3($x,80,$z));
                    if (
    $testforBlock->getID() === BlockAPI::get(00))
                    {
                        
    $wool_block BlockAPI::get(35$wool_color);
                        
    $level->setBlock(new Vector3($x,80,$z), $wool_block);
                    }
                }
            }
        }
    }
    This code doesn't work, and I don't understand why. It looks ok for me, but I'm also new to PHP so maybe i can't really see my mistake.
    I've tested and the blocks at height 80 are air blocks (line 34), so that is not the problem.
    Please help me!
    Thanks in advance :)
  2. codmadnesspro
    Offline

    codmadnesspro Notable Member Plugin Developer

    Joined:
    Sep 11, 2013
    Posts:
    551
    Plugins:
    1
    Minecraft User:
    Codmadnesspro
    New api soon... Pointless you making this ._.
    Spurs_Man321, Darunia18 and iksaku like this.
  3. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Spurs_Man321 likes this.
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    getID will return an integer not a block object.
    LDX likes this.
  5. YoDevil
    Offline

    YoDevil New Member

    Joined:
    May 12, 2014
    Posts:
    10
    Minecraft User:
    YoDevil
    Ok thanks all!

Share This Page

Advertisement