PocketMine-MP 5.40.1 git-25718e8ccd903d1408fb25666ef84028379bbea6
Loading...
Searching...
No Matches
ClientboundTextureShiftPacket.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\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\VarInt;
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::CLIENTBOUND_TEXTURE_SHIFT_PACKET;
27
29 private int $actionId;
30 private string $collectionName;
31 private string $fromStep;
32 private string $toStep;
37 private array $allSteps;
38 private int $currentLengthTicks;
39 private int $totalLengthTicks;
40 private bool $enabled;
41
47 public static function create(
48 int $actionId,
49 string $collectionName,
50 string $fromStep,
51 string $toStep,
52 array $allSteps,
53 int $currentLengthTicks,
54 int $totalLengthTicks,
55 bool $enabled,
56 ) : self{
57 $result = new self;
58 $result->actionId = $actionId;
59 $result->collectionName = $collectionName;
60 $result->fromStep = $fromStep;
61 $result->toStep = $toStep;
62 $result->allSteps = $allSteps;
63 $result->currentLengthTicks = $currentLengthTicks;
64 $result->totalLengthTicks = $totalLengthTicks;
65 $result->enabled = $enabled;
66 return $result;
67 }
68
72 public function getActionId() : int{ return $this->actionId; }
73
74 public function getCollectionName() : string{ return $this->collectionName; }
75
76 public function getFromStep() : string{ return $this->fromStep; }
77
78 public function getToStep() : string{ return $this->toStep; }
79
84 public function getAllSteps() : array{ return $this->allSteps; }
85
86 public function getCurrentLengthTicks() : int{ return $this->currentLengthTicks; }
87
88 public function getTotalLengthTicks() : int{ return $this->totalLengthTicks; }
89
90 public function isEnabled() : bool{ return $this->enabled; }
91
92 protected function decodePayload(ByteBufferReader $in) : void{
93 $this->actionId = Byte::readUnsigned($in);
94 $this->collectionName = CommonTypes::getString($in);
95 $this->fromStep = CommonTypes::getString($in);
96 $this->toStep = CommonTypes::getString($in);
97
98 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
99 $this->allSteps[] = CommonTypes::getString($in);
100 }
101
102 $this->currentLengthTicks = VarInt::readUnsignedLong($in);
103 $this->totalLengthTicks = VarInt::readUnsignedLong($in);
104 $this->enabled = CommonTypes::getBool($in);
105 }
106
107 protected function encodePayload(ByteBufferWriter $out) : void{
108 Byte::writeUnsigned($out, $this->actionId);
109 CommonTypes::putString($out, $this->collectionName);
110 CommonTypes::putString($out, $this->fromStep);
111 CommonTypes::putString($out, $this->toStep);
112
113 VarInt::writeUnsignedInt($out, count($this->allSteps));
114 foreach($this->allSteps as $step){
115 CommonTypes::putString($out, $step);
116 }
117
118 VarInt::writeUnsignedLong($out, $this->currentLengthTicks);
119 VarInt::writeUnsignedLong($out, $this->totalLengthTicks);
120 CommonTypes::putBool($out, $this->enabled);
121 }
122
123 public function handle(PacketHandlerInterface $handler) : bool{
124 return $handler->handleClientboundTextureShift($this);
125 }
126}
static create(int $actionId, string $collectionName, string $fromStep, string $toStep, array $allSteps, int $currentLengthTicks, int $totalLengthTicks, bool $enabled,)