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

setBlock help?

Comments in 'Plugin Development' started by Radix, Jul 22, 2015.

  1. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    I saw a post when they were speaking about setBlock and I was wondering if anybody could teach me how to use it? Maybe an example ?
    PHP:
    $level->setBlock(new Vector3($x$y$z), 54);
    // I don't understand this
  2. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    What you don't understand?

    PHP:
    $lv->setBlock(Vector3($x$y$z), Block::get($id$meta));
    $lv is world where you want set Block, example:
    PHP:
    $lv $this->getServer()->getLevelByName("world");
    $x,$y,$z are coordinates of block you want to set. They are numbers/variables.
    $id, $meta are parametres of block you want set. When you write Block::get(35, 1), it will set block with id 35 and meta/damage 1 (= red wool)
  3. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    SoI can do something like ..
    PHP:
    $lv $this->getServer()->getLevelByName("world");
    $lv->setBlock(Vector3(getPlayerX(), getPlayerY(), getPlayerZ()), Block::get(10));
  4. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    I don't know if getPlayerX() can return number. I recommend to use (in events etc...) $ev->getPlayer()->getX()... Anyways, right.
  5. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    What is the correct way to get lets say $issuer cords and set a block , simple code example...
  6. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    There're two possibilities:

    1) $issuer->getPosition();
    (Position is Vector3 with player X,Y,Z)
    2) $issuer->getX(), $issuer->getY(), $issuer->getZ()

    If you want set block at issuers coordinates, use:
    PHP:
    $issuer->getLevel()->setBlock($issuer->getPosition(), Block::get(1,0));
    However, if you don't want set block at player position (e.g. under player), you must write:
    PHP:
    $issuer->getLevel()->setBlock(Vector3($issuer->getX(), $issuer->getY()-1$issuer->getZ()), Block::get(1,0));
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    PHP:
    $lv $this->getServer()->getLevelByName("world");
    $lv->setBlock(Vector3($issuer->getX(), $issuer->getY(), $issuer->getZ()), Block::get(10));
    I am sure you can first do $xyz = newVector3....
    But I am too lazy or I don't think mine is right... lol
  8. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    $issuer->getPosition() === Vector3($x,$y,$z)
  9. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    So it's unnecessary to write setBlock(Vector3(Vector3($x,$y,$z))...
  10. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Your is right, but if player is in world "level", it'll set block at players X,Y,Z, but in different level
  11. Tarik02
    Offline

    Tarik02 New Member

    Joined:
    Jun 24, 2015
    Posts:
    26
    Minecraft User:
    Tarik02
    PHP:
    $lv $this->getServer()->getLevelByName("world");
    $Player $this->getServer->getPlayer("Radix");
    $lv->setBlock($Player,Block::get(1),true,true);
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $issuer itself is a position.
    $Player->getLevel(). Why search for a level again while you already have a level?
    Man, this is not ModPE... -_-#
  13. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Sorry , Use to do ModPE Scripts :p As you can tell <3 Love u sorry ...
    PHP:
    $lv $this->getServer()->getLevelByName("world");
    $pep $issuer->getX(), $issuer->getY(), $issuer->getZ()
    $Player $this->getServer->getPlayer($pep);
    $lv->setBlock($Player,Block::get(1),true,true);
    Now what is this?
    PHP:
    $lv->setBlock($Player,Block::get(1),true,true);
    Like
    PHP:
    $lv->setBlock ($Player,Block::get(1),true,true); // ::get(1) ?
    Minecrafter9203 likes this.
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    ModPE..... lol
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $pep what the...

    Let me translate the line you are asking into JavaScript:
    Code:
    level.setBlock(player, Block.get(1 /* stone ID
    Happy?
    First parameter player is the position object. Second parameter is the block, an object containing the target ID and damage. Third parameter is whether to send the packet immediately in an independent packet. (Client lags if many independent packets are sent) fourth parameter is whether to update nearby blocks.
    Andrey Nazarchuk likes this.
  16. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Ah , fudge it !
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ah, screw it... lol
  18. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Was just gonna set two blocks at player location! , but noooo its all of this extra shiz
  19. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    @PEMapModder @Radix
    How would I get a block at a location?
    Like this or something(Does not work):
    PHP:
    $player->getLevel()->getBlock($pos)->getId();
    Last edited: Aug 9, 2015
  20. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Sorry, $p->getPosition() is position:
    PHP:
    $p->getPosition() = Position($x,$y,$z,$lv);

Share This Page

Advertisement