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

setBlock Air help

Comments in 'Plugin Development' started by MinePocket Servers, Oct 31, 2015.

  1. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    Current snippet is
    Code:
    $air = new Block(0);
    $level->setBlock(new Vector3($row["x"], $row["y"], $row["z"]), $air);
    $sender->sendMessage(TextFormat::GREEN ."[MPDebug] Placed Trigger! ");
    $this->blc++;
    
    I know this section of code is being run however it is not setting the block to air. The block I want to set to air was a block previously placed by a player. I know this works because the following works.
    Code:
    $level->setBlock(new Vector3($row["x"], $row["y"], $row["z"]), new Block($row["blockId"],0));
    $this->blc++;
    
    Does setblock to air not work if a previous block exists? If this is not possible then is there anything that will set a block at $x $y and $z with $blockid and optionally with meta?
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    $level->setBlock(new Vector3($x$y$z), Block::get(Block::AIR));
    PEMapModder likes this.
  3. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    Allright will try it out, Nice that you can use block names...
  4. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Also I assume you're using the BlockPlaceEvent, in that case you don't need the x, y and z coordinates since the block being placed is already a coordinate itself. This can also be used:
    PHP:
    $level->setBlock(new Vector3($event->getBlock), Block::get(Block::AIR));
  5. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    The logging is using block place event, this segment is pulled from a sql db.
  6. MinePocket Servers
    Offline

    MinePocket Servers Active Member

    Joined:
    Mar 6, 2014
    Posts:
    69
    Minecraft User:
    MinePocket
    Got
    Code:
    Fatal error: Call to a member function setBlock() on null in /home/pocketmine/plugins/MProtect/src/Autonomousperson/MProtect/Main.php on line 121
    
    is Block::get(Block::AIR)
    just
    Block(idhere)?
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $level is null.

Share This Page

Advertisement