PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
UpdateSubChunkBlocksPacketEntry.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\types;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22
24 public function __construct(
25 private BlockPosition $blockPosition,
26 private int $blockRuntimeId,
27 private int $flags,
28 //These two fields are useless 99.9% of the time; they are here to allow this packet to provide UpdateBlockSyncedPacket functionality.
29 private int $syncedUpdateActorUniqueId,
30 private int $syncedUpdateType
31 ){}
32
33 public static function simple(BlockPosition $blockPosition, int $blockRuntimeId) : self{
34 return new self($blockPosition, $blockRuntimeId, UpdateBlockPacket::FLAG_NETWORK, 0, 0);
35 }
36
37 public function getBlockPosition() : BlockPosition{ return $this->blockPosition; }
38
39 public function getBlockRuntimeId() : int{ return $this->blockRuntimeId; }
40
41 public function getFlags() : int{ return $this->flags; }
42
43 public function getSyncedUpdateActorUniqueId() : int{ return $this->syncedUpdateActorUniqueId; }
44
45 public function getSyncedUpdateType() : int{ return $this->syncedUpdateType; }
46
47 public static function read(ByteBufferReader $in) : self{
48 $blockPosition = CommonTypes::getBlockPosition($in);
49 $blockRuntimeId = VarInt::readUnsignedInt($in);
50 $updateFlags = VarInt::readUnsignedInt($in);
51 $syncedUpdateActorUniqueId = VarInt::readUnsignedLong($in); //this can't use the standard method because it's unsigned as opposed to the usual signed... !!!!!!
52 $syncedUpdateType = VarInt::readUnsignedInt($in); //this isn't even consistent with UpdateBlockSyncedPacket?!
53
54 return new self($blockPosition, $blockRuntimeId, $updateFlags, $syncedUpdateActorUniqueId, $syncedUpdateType);
55 }
56
57 public function write(ByteBufferWriter $out) : void{
58 CommonTypes::putBlockPosition($out, $this->blockPosition);
59 VarInt::writeUnsignedInt($out, $this->blockRuntimeId);
60 VarInt::writeUnsignedInt($out, $this->flags);
61 VarInt::writeUnsignedLong($out, $this->syncedUpdateActorUniqueId);
62 VarInt::writeUnsignedInt($out, $this->syncedUpdateType);
63 }
64}