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

Placing A Block

Comments in 'Plugin Development' started by Tethered_, Nov 20, 2014.

  1. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    How can I place a certain block at coordinates x y and z when an event is called?
  2. Dinokiller
    Offline

    Dinokiller Notable Member

    Joined:
    Sep 22, 2013
    Posts:
    376
    Minecraft User:
    Dinokiller_
    In the method which is executed on the event you want to use:
    PHP:
    $position = new Vector3(345623); // Some random location
    $block $level->getBlock($position);
  3. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    Wont that just detect the block at 34, 56, 23 and return what type the block is?
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    You need to specify the Level where you want to work:
    PHP:
    $level $this->getServer()->getLevelByName($levelname);
    You could also get the level by using an entity that it's on it: (Ex. using a player that you already have)
    PHP:
    $level $player->getLevel();
    And then, the rest of the code that @Dinokiller give us:
    1. Define the position:
      PHP:
      $pos = new Vector3($x$y$z);
    2. This may vary depending on what you want to do:
      • To get a block object:
        PHP:
        $level->getBlock($pos);
      • To place a block: (Ex. Using a Bedrock block)
        PHP:
        $block = new Bedrock();
        $level->setBlock($pos$block);
      • To simulate a "Tap" on a block with a certain item: (Ex. using a Flint & Stell Item)
        PHP:
        $item = new FlintandSteel();
        $level->useItemOn($pos$item);
    I hope this will help you ;)
    P.S: @PEMapModder please correct me if I'm wrong :p
    Andrey Nazarchuk and Tethered_ like this.
  5. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    God dang that's helpful. Thanks!!
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Also try Block::get()

Share This Page

Advertisement