PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
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
18
24 public const NETWORK_ID = ProtocolInfo::CHANGE_MOB_PROPERTY_PACKET;
25
26 private int $actorUniqueId;
27 private string $propertyName;
28 private bool $boolValue;
29 private string $stringValue;
30 private int $intValue;
31 private float $floatValue;
32
36 private static function create(int $actorUniqueId, string $propertyName, bool $boolValue, string $stringValue, int $intValue, float $floatValue) : self{
37 $result = new self;
38 $result->actorUniqueId = $actorUniqueId;
39 $result->propertyName = $propertyName;
40 $result->boolValue = $boolValue;
41 $result->stringValue = $stringValue;
42 $result->intValue = $intValue;
43 $result->floatValue = $floatValue;
44 return $result;
45 }
46
47 public static function boolValue(int $actorUniqueId, string $propertyName, bool $value) : self{
48 return self::create($actorUniqueId, $propertyName, $value, "", 0, 0);
49 }
50
51 public static function stringValue(int $actorUniqueId, string $propertyName, string $value) : self{
52 return self::create($actorUniqueId, $propertyName, false, $value, 0, 0);
53 }
54
55 public static function intValue(int $actorUniqueId, string $propertyName, int $value) : self{
56 return self::create($actorUniqueId, $propertyName, false, "", $value, 0);
57 }
58
59 public static function floatValue(int $actorUniqueId, string $propertyName, float $value) : self{
60 return self::create($actorUniqueId, $propertyName, false, "", 0, $value);
61 }
62
63 public function getActorUniqueId() : int{ return $this->actorUniqueId; }
64
65 public function getPropertyName() : string{ return $this->propertyName; }
66
67 public function isBoolValue() : bool{ return $this->boolValue; }
68
69 public function getStringValue() : string{ return $this->stringValue; }
70
71 public function getIntValue() : int{ return $this->intValue; }
72
73 public function getFloatValue() : float{ return $this->floatValue; }
74
75 protected function decodePayload(PacketSerializer $in) : void{
76 $this->actorUniqueId = $in->getActorUniqueId();
77 $this->propertyName = $in->getString();
78 $this->boolValue = $in->getBool();
79 $this->stringValue = $in->getString();
80 $this->intValue = $in->getVarInt();
81 $this->floatValue = $in->getLFloat();
82 }
83
84 protected function encodePayload(PacketSerializer $out) : void{
85 $out->putActorUniqueId($this->actorUniqueId);
86 $out->putString($this->propertyName);
87 $out->putBool($this->boolValue);
88 $out->putString($this->stringValue);
89 $out->putVarInt($this->intValue);
90 $out->putLFloat($this->floatValue);
91 }
92
93 public function handle(PacketHandlerInterface $handler) : bool{
94 return $handler->handleChangeMobProperty($this);
95 }
96}