PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ChangeMobPropertyPacket.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\LE;
20use pmmp\encoding\VarInt;
22
28 public const NETWORK_ID = ProtocolInfo::CHANGE_MOB_PROPERTY_PACKET;
29
30 private int $actorUniqueId;
31 private string $propertyName;
32 private bool $boolValue;
33 private string $stringValue;
34 private int $intValue;
35 private float $floatValue;
36
40 private static function create(int $actorUniqueId, string $propertyName, bool $boolValue, string $stringValue, int $intValue, float $floatValue) : self{
41 $result = new self;
42 $result->actorUniqueId = $actorUniqueId;
43 $result->propertyName = $propertyName;
44 $result->boolValue = $boolValue;
45 $result->stringValue = $stringValue;
46 $result->intValue = $intValue;
47 $result->floatValue = $floatValue;
48 return $result;
49 }
50
51 public static function boolValue(int $actorUniqueId, string $propertyName, bool $value) : self{
52 return self::create($actorUniqueId, $propertyName, $value, "", 0, 0);
53 }
54
55 public static function stringValue(int $actorUniqueId, string $propertyName, string $value) : self{
56 return self::create($actorUniqueId, $propertyName, false, $value, 0, 0);
57 }
58
59 public static function intValue(int $actorUniqueId, string $propertyName, int $value) : self{
60 return self::create($actorUniqueId, $propertyName, false, "", $value, 0);
61 }
62
63 public static function floatValue(int $actorUniqueId, string $propertyName, float $value) : self{
64 return self::create($actorUniqueId, $propertyName, false, "", 0, $value);
65 }
66
67 public function getActorUniqueId() : int{ return $this->actorUniqueId; }
68
69 public function getPropertyName() : string{ return $this->propertyName; }
70
71 public function isBoolValue() : bool{ return $this->boolValue; }
72
73 public function getStringValue() : string{ return $this->stringValue; }
74
75 public function getIntValue() : int{ return $this->intValue; }
76
77 public function getFloatValue() : float{ return $this->floatValue; }
78
79 protected function decodePayload(ByteBufferReader $in) : void{
80 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
81 $this->propertyName = CommonTypes::getString($in);
82 $this->boolValue = CommonTypes::getBool($in);
83 $this->stringValue = CommonTypes::getString($in);
84 $this->intValue = VarInt::readSignedInt($in);
85 $this->floatValue = LE::readFloat($in);
86 }
87
88 protected function encodePayload(ByteBufferWriter $out) : void{
89 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
90 CommonTypes::putString($out, $this->propertyName);
91 CommonTypes::putBool($out, $this->boolValue);
92 CommonTypes::putString($out, $this->stringValue);
93 VarInt::writeSignedInt($out, $this->intValue);
94 LE::writeFloat($out, $this->floatValue);
95 }
96
97 public function handle(PacketHandlerInterface $handler) : bool{
98 return $handler->handleChangeMobProperty($this);
99 }
100}