1717use pmmp \encoding \ByteBufferReader ;
1818use pmmp \encoding \ByteBufferWriter ;
1919use pmmp \encoding \LE ;
20+ use pocketmine \network \mcpe \protocol \ProtocolInfo ;
2021use pocketmine \network \mcpe \protocol \serializer \CommonTypes ;
2122
2223/**
@@ -57,16 +58,18 @@ public function getLocalTransitionTicks() : int{ return $this->localTransitionTi
5758
5859 public function isNoiseTransition () : bool { return $ this ->noiseTransition ; }
5960
60- public static function read (ByteBufferReader $ in ) : self {
61+ public static function read (ByteBufferReader $ in, int $ protocolId ) : self {
6162 $ name = CommonTypes::getString ($ in );
6263 $ fromAttribute = CommonTypes::readOptional ($ in , AttributeValue::read (...));
6364 $ attribute = AttributeValue::read ($ in );
6465 $ toAttribute = CommonTypes::readOptional ($ in , AttributeValue::read (...));
6566 $ currentTransitionTicks = LE ::readUnsignedInt ($ in );
6667 $ totalTransitionTicks = LE ::readUnsignedInt ($ in );
6768 $ easeType = CommonTypes::getString ($ in );
68- $ localTransitionTicks = LE ::readUnsignedInt ($ in );
69- $ noiseTransition = CommonTypes::getBool ($ in );
69+ if ($ protocolId >= ProtocolInfo::PROTOCOL_1_26_30 ){
70+ $ localTransitionTicks = LE ::readUnsignedInt ($ in );
71+ $ noiseTransition = CommonTypes::getBool ($ in );
72+ }
7073
7174 return new self (
7275 $ name ,
@@ -76,20 +79,22 @@ public static function read(ByteBufferReader $in) : self{
7679 $ currentTransitionTicks ,
7780 $ totalTransitionTicks ,
7881 $ easeType ,
79- $ localTransitionTicks ,
80- $ noiseTransition
82+ $ localTransitionTicks ?? 0 ,
83+ $ noiseTransition ?? false
8184 );
8285 }
8386
84- public function write (ByteBufferWriter $ out ) : void {
87+ public function write (ByteBufferWriter $ out, int $ protocolId ) : void {
8588 CommonTypes::putString ($ out , $ this ->name );
8689 CommonTypes::writeOptional ($ out , $ this ->fromAttribute , fn (ByteBufferWriter $ out , AttributeValue $ value ) => $ value ->write ($ out ));
8790 $ this ->attribute ->write ($ out );
8891 CommonTypes::writeOptional ($ out , $ this ->toAttribute , fn (ByteBufferWriter $ out , AttributeValue $ value ) => $ value ->write ($ out ));
8992 LE ::writeUnsignedInt ($ out , $ this ->currentTransitionTicks );
9093 LE ::writeUnsignedInt ($ out , $ this ->totalTransitionTicks );
9194 CommonTypes::putString ($ out , $ this ->easeType );
92- LE ::writeUnsignedInt ($ out , $ this ->localTransitionTicks );
93- CommonTypes::putBool ($ out , $ this ->noiseTransition );
95+ if ($ protocolId >= ProtocolInfo::PROTOCOL_1_26_30 ){
96+ LE ::writeUnsignedInt ($ out , $ this ->localTransitionTicks );
97+ CommonTypes::putBool ($ out , $ this ->noiseTransition );
98+ }
9499 }
95100}
0 commit comments