PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
UpdateBlockPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
19
21 public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_PACKET;
22
23 public const FLAG_NONE = 0b0000;
24 public const FLAG_NEIGHBORS = 0b0001;
25 public const FLAG_NETWORK = 0b0010;
26 public const FLAG_NOGRAPHIC = 0b0100;
27 public const FLAG_PRIORITY = 0b1000;
28
29 public const DATA_LAYER_NORMAL = 0;
30 public const DATA_LAYER_LIQUID = 1;
31
32 public BlockPosition $blockPosition;
33 public int $blockRuntimeId;
39 public int $flags = self::FLAG_NETWORK;
40 public int $dataLayerId = self::DATA_LAYER_NORMAL;
41
45 public static function create(BlockPosition $blockPosition, int $blockRuntimeId, int $flags, int $dataLayerId) : self{
46 $result = new self;
47 $result->blockPosition = $blockPosition;
48 $result->blockRuntimeId = $blockRuntimeId;
49 $result->flags = $flags;
50 $result->dataLayerId = $dataLayerId;
51 return $result;
52 }
53
54 protected function decodePayload(PacketSerializer $in) : void{
55 $this->blockPosition = $in->getBlockPosition();
56 $this->blockRuntimeId = $in->getUnsignedVarInt();
57 $this->flags = $in->getUnsignedVarInt();
58 $this->dataLayerId = $in->getUnsignedVarInt();
59 }
60
61 protected function encodePayload(PacketSerializer $out) : void{
62 $out->putBlockPosition($this->blockPosition);
63 $out->putUnsignedVarInt($this->blockRuntimeId);
64 $out->putUnsignedVarInt($this->flags);
65 $out->putUnsignedVarInt($this->dataLayerId);
66 }
67
68 public function handle(PacketHandlerInterface $handler) : bool{
69 return $handler->handleUpdateBlock($this);
70 }
71}
static create(BlockPosition $blockPosition, int $blockRuntimeId, int $flags, int $dataLayerId)