PocketMine-MP 5.15.1 git-fb9a74e8799c71ed8292cfa53abe7a4c9204629d
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
18use function count;
19
20final class PropertySyncData{
27 public function __construct(
28 private array $intProperties,
29 private array $floatProperties,
30 ){}
31
36 public function getIntProperties() : array{
37 return $this->intProperties;
38 }
39
44 public function getFloatProperties() : array{
45 return $this->floatProperties;
46 }
47
48 public static function read(PacketSerializer $in) : self{
49 $intProperties = [];
50 $floatProperties = [];
51
52 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
53 $intProperties[$in->getUnsignedVarInt()] = $in->getVarInt();
54 }
55 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
56 $floatProperties[$in->getUnsignedVarInt()] = $in->getLFloat();
57 }
58
59 return new self($intProperties, $floatProperties);
60 }
61
62 public function write(PacketSerializer $out) : void{
63 $out->putUnsignedVarInt(count($this->intProperties));
64 foreach($this->intProperties as $key => $value){
65 $out->putUnsignedVarInt($key);
66 $out->putVarInt($value);
67 }
68 $out->putUnsignedVarInt(count($this->floatProperties));
69 foreach($this->floatProperties as $key => $value){
70 $out->putUnsignedVarInt($key);
71 $out->putLFloat($value);
72 }
73 }
74}
__construct(private array $intProperties, private array $floatProperties,)