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

Place function

Comments in 'Plugin Development' started by Irish, Jun 4, 2016.

  1. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Recently I've been notified that every block has a place function, but when I try to use the place function, it never places down the block. Could someone give me an example on how I could use it?
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
  3. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    nonono, the place function in each block. It helps with setting tiles easier.
  4. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    I already know setBlock.
  5. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
  6. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Yes but it also creates the tile, every time I try to use it, it doesn't place the block down. Henceforth why I asked about it.
  7. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Can you show how you're trying to use it?
  8. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Code:
    $chest = new Chest();
    $chest->place(Item::get(Item::CHEST), Block::get(Block::Chest), Block::get(Block::AIR), 0, $player->x, $player->y, $player->z, $player);
  9. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    I don't have to put the $player at the end, because even if it's not there it still doesn't work.
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You're making this harder than it has to be. Just use setBlock to place the chest.
    PHP:
    $level->setBlock(new Vector3($player->x$player->y$player->z), Block::get(Block::CHEST01))
  11. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    Well, I was told to use it. That was an example, but every time I place a Skull it is invisible even after creating the tile, so I was told to use place
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You dont have to create anything. Simply use the setBlock function. Can you show the code of how you were trying to use setBlock?
  13. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    You aren't understanding that you can't set a tile without creating it, or it will be invisible.
  14. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You don't have to create a tile. You can indeed use setBlock to place a chest block.
    Last edited: Jun 4, 2016
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    The Chest:place() function indeed places the block.
    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/block/Chest.php#L98

    https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/block/Chest.php#L71 is not equivalent to Level::setBlock(). It does many other things.
    Block::place is called from https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/level/Level.php#L1730 Level::useItemOn(), which is called from the packet handling code for UseItemPacket. Therefore, it simulates a player placing a chest.
  16. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Do you know what a tile is? A tile is a tile entity, not a block. setBlock only places a block, not a tile. To make a chest block visible, apart from setting the chest block, you also have to set the chest tile entity.
    Legoboy0215 likes this.
  17. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Incorrect, a chest block is visible wether you initiate a tile at its location or not. If the chest has no tile linked then any attempts to open the chest are considered normal block placements/interactions.
  18. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    No you don't. You can set a chest block without setting a chest tile.
  19. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Whatever, I'm quite outdated (at least it was true before). Maybe you should look at the posts above again? The main point is, calling setBlock() does not place the tile entity. Whether the chest block is visible without an associated tile is not the aim of our discussion. (What's the meaning of placing a chest block that you can't open, anyway?)
    Gamecrafter likes this.
  20. Irish
    Offline

    Irish Active Member

    Joined:
    Apr 24, 2016
    Posts:
    96
    Minecraft User:
    _Irish_
    I do believe I was giving an example of a chest, but really I'm trying to place down another tile so that it won't be invisible. So even after creating and adding the tile it still is invisible.

Share This Page

Advertisement