1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Change block only for one player

Discussion in 'Development' started by udwarf, Jun 8, 2017.

  1. udwarf

    udwarf Silverfish

    Messages:
    21
    Hello, developers!
    In one of my minigames I'm trying to make so changing of one block was visible by only one player.
    This block should not be changed in the world, but one player will see it like it was changed.
    May be I do it in wrong way, because I didn't succeed.
    I'm trying to create UpdateBlockPacket and send it to the particular player.
    PHP:
    $pk = new UpdateBlockPacket();
    $pk->$pos->getX();
    $pk->$pos->getY();
    $pk->$pos->getZ();
    $pk->blockId Block::GOLD_BLOCK;
    $pk->blockData 0;
    $pk->flags UpdateBlockPacket::FLAG_NONE// not sure what is here
    $player->dataPacket($pk);
    But player doesn't see any changes
    How to implement it correctly?

    Thanks in advance!
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Avoid sending packets directly. Use the Level::sendBlocks() method instead.
     
    jasonwynn10, Muqsit and udwarf like this.
  3. udwarf

    udwarf Silverfish

    Messages:
    21
    Great!
    $lv->sendBlocks([$player],[$block]); works as I wanted!
    Thank you
     
    jasonwynn10 likes this.
  4. udwarf

    udwarf Silverfish

    Messages:
    21
    Is it possible to update tiles in the same way?
    I didn't found Level::sendTiles method..
     
    SOFe likes this.
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Um, for that, you will need to send BlockEntityPacket directly to the player. Read my answer to a similar question.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.