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

Solved UpdateBlockPacket -> blockRuntimeId to blockId

Discussion in 'Development' started by Subbitx, Aug 10, 2020.

  1. Subbitx

    Subbitx Silverfish

    Messages:
    18
    I started developing after a long time now and some Code is not working for me. I am sending clientside blocks to players but now I cant convert blockRuntimeIds to normal blockIds, so the server crashes.

    Crash Log:
    My IDE tells me:
    And that is my code:
    Code:
    public function placeBlock(Player $target, $x, $y, $z, $blockRuntimeid) {
            $pk = new UpdateBlockPacket();
            $pk->x = $x;
            $pk->y = $y;
            $pk->z = $z;
            $pk->dataLayerId = 0;
            $pk->blockRuntimeId = types\RuntimeBlockMapping::toStaticRuntimeId($blockRuntimeid, 0);
            $pk->flags = 0b0000;
            $target->dataPacket($pk);
        }
    I searched the whole internet for the issue but nobody had the problem yet!?
    Thank you for your help <3
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You can use
    PHP:
    /**
     * @var \pocketmine\Player $target
     * @var \pocketmine\block\Block $block
     */
    Level->sendBlocks([$target], [$block]);
    api function instead
     
    Primus and Subbitx like this.
  3. Subbitx

    Subbitx Silverfish

    Messages:
    18
    Oh much easier. Thanks.
     
    Primus likes this.
  4. Subbitx

    Subbitx Silverfish

    Messages:
    18
    So final code:
    Code:
    public function placeBlock(Player $target, $x, $y, $z, $blockRuntimeid) {
            $block = Block::get($blockRuntimeid);
            $block->position(Position::fromObject(new Vector3($x, $y, $z)));
            $block->level = $target->level;
            $target->level->sendBlocks([$target],[$block]);
        }
     
    Primus likes this.
  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.