PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
PropertySyncData.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\entity;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
21use function count;
22
23final class PropertySyncData{
30 public function __construct(
31 private array $intProperties,
32 private array $floatProperties,
33 ){}
34
39 public function getIntProperties() : array{
40 return $this->intProperties;
41 }
42
47 public function getFloatProperties() : array{
48 return $this->floatProperties;
49 }
50
51 public static function read(ByteBufferReader $in) : self{
52 $intProperties = [];
53 $floatProperties = [];
54
55 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
56 $intProperties[VarInt::readUnsignedInt($in)] = VarInt::readSignedInt($in);
57 }
58 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
59 $floatProperties[VarInt::readUnsignedInt($in)] = LE::readFloat($in);
60 }
61
62 return new self($intProperties, $floatProperties);
63 }
64
65 public function write(ByteBufferWriter $out) : void{
66 VarInt::writeUnsignedInt($out, count($this->intProperties));
67 foreach($this->intProperties as $key => $value){
68 VarInt::writeUnsignedInt($out, $key);
69 VarInt::writeSignedInt($out, $value);
70 }
71 VarInt::writeUnsignedInt($out, count($this->floatProperties));
72 foreach($this->floatProperties as $key => $value){
73 VarInt::writeUnsignedInt($out, $key);
74 LE::writeFloat($out, $value);
75 }
76 }
77}
__construct(private array $intProperties, private array $floatProperties,)