PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22
24 public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_PACKET;
25
26 public const FLAG_NONE = 0b0000;
27 public const FLAG_NEIGHBORS = 0b0001;
28 public const FLAG_NETWORK = 0b0010;
29 public const FLAG_NOGRAPHIC = 0b0100;
30 public const FLAG_PRIORITY = 0b1000;
31
32 public const DATA_LAYER_NORMAL = 0;
33 public const DATA_LAYER_LIQUID = 1;
34
35 public BlockPosition $blockPosition;
36 public int $blockRuntimeId;
42 public int $flags = self::FLAG_NETWORK;
43 public int $dataLayerId = self::DATA_LAYER_NORMAL;
44
48 public static function create(BlockPosition $blockPosition, int $blockRuntimeId, int $flags, int $dataLayerId) : self{
49 $result = new self;
50 $result->blockPosition = $blockPosition;
51 $result->blockRuntimeId = $blockRuntimeId;
52 $result->flags = $flags;
53 $result->dataLayerId = $dataLayerId;
54 return $result;
55 }
56
57 protected function decodePayload(ByteBufferReader $in) : void{
58 $this->blockPosition = CommonTypes::getBlockPosition($in);
59 $this->blockRuntimeId = VarInt::readUnsignedInt($in);
60 $this->flags = VarInt::readUnsignedInt($in);
61 $this->dataLayerId = VarInt::readUnsignedInt($in);
62 }
63
64 protected function encodePayload(ByteBufferWriter $out) : void{
65 CommonTypes::putBlockPosition($out, $this->blockPosition);
66 VarInt::writeUnsignedInt($out, $this->blockRuntimeId);
67 VarInt::writeUnsignedInt($out, $this->flags);
68 VarInt::writeUnsignedInt($out, $this->dataLayerId);
69 }
70
71 public function handle(PacketHandlerInterface $handler) : bool{
72 return $handler->handleUpdateBlock($this);
73 }
74}
static create(BlockPosition $blockPosition, int $blockRuntimeId, int $flags, int $dataLayerId)