Skip to content

Commit eb1357e

Browse files
committed
Update ext-encoding, tidy some nonsensical sign/unsign calls
1 parent 809d613 commit eb1357e

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
php-version: ${{ matrix.php }}
2020
ini-values: xdebug.max_nesting_level=3000
21-
extensions: encoding-pmmp/ext-encoding@0.5.1
21+
extensions: encoding-pmmp/ext-encoding@1.0.0
2222

2323
- name: Load Composer package cache
2424
uses: actions/cache@v4

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "library",
55
"require": {
66
"php": "^8.1",
7-
"ext-encoding": "~0.5.0",
7+
"ext-encoding": "~1.0.0",
88
"ext-json": "*",
99
"pocketmine/binaryutils": "^0.2.0",
1010
"pocketmine/color": "^0.2.0 || ^0.3.0",

src/PacketPool.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace pocketmine\network\mcpe\protocol;
1616

17-
use pocketmine\utils\Binary;
17+
use pmmp\encoding\VarInt;
1818
use pocketmine\utils\BinaryDataException;
1919

2020
class PacketPool{
@@ -254,7 +254,6 @@ public function getPacketById(int $pid) : ?Packet{
254254
* @throws BinaryDataException
255255
*/
256256
public function getPacket(string $buffer) : ?Packet{
257-
$offset = 0;
258-
return $this->getPacketById(Binary::readUnsignedVarInt($buffer, $offset) & DataPacket::PID_MASK);
257+
return $this->getPacketById(VarInt::unpackUnsignedInt($buffer) & DataPacket::PID_MASK);
259258
}
260259
}

src/types/SubChunkPacketHeightMapInfo.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use pmmp\encoding\Byte;
1818
use pmmp\encoding\ByteBufferReader;
1919
use pmmp\encoding\ByteBufferWriter;
20-
use pocketmine\utils\Binary;
2120
use function array_fill;
2221
use function count;
2322

@@ -43,14 +42,14 @@ public function getHeight(int $x, int $z) : int{
4342
public static function read(ByteBufferReader $in) : self{
4443
$heights = [];
4544
for($i = 0; $i < 256; ++$i){
46-
$heights[] = Binary::signByte(Byte::readUnsigned($in));
45+
$heights[] = Byte::readSigned($in);
4746
}
4847
return new self($heights);
4948
}
5049

5150
public function write(ByteBufferWriter $out) : void{
5251
for($i = 0; $i < 256; ++$i){
53-
Byte::writeUnsigned($out, Binary::unsignByte($this->heights[$i]));
52+
Byte::writeSigned($out, $this->heights[$i]);
5453
}
5554
}
5655

src/types/SubChunkPositionOffset.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use pmmp\encoding\Byte;
1818
use pmmp\encoding\ByteBufferReader;
1919
use pmmp\encoding\ByteBufferWriter;
20-
use pocketmine\utils\Binary;
2120
use pocketmine\utils\Limits;
2221

2322
final class SubChunkPositionOffset{
@@ -45,16 +44,16 @@ public function getYOffset() : int{ return $this->yOffset; }
4544
public function getZOffset() : int{ return $this->zOffset; }
4645

4746
public static function read(ByteBufferReader $in) : self{
48-
$xOffset = Binary::signByte(Byte::readUnsigned($in));
49-
$yOffset = Binary::signByte(Byte::readUnsigned($in));
50-
$zOffset = Binary::signByte(Byte::readUnsigned($in));
47+
$xOffset = Byte::readSigned($in);
48+
$yOffset = Byte::readSigned($in);
49+
$zOffset = Byte::readSigned($in);
5150

5251
return new self($xOffset, $yOffset, $zOffset);
5352
}
5453

5554
public function write(ByteBufferWriter $out) : void{
56-
Byte::writeUnsigned($out, $this->xOffset);
57-
Byte::writeUnsigned($out, $this->yOffset);
58-
Byte::writeUnsigned($out, $this->zOffset);
55+
Byte::writeSigned($out, $this->xOffset);
56+
Byte::writeSigned($out, $this->yOffset);
57+
Byte::writeSigned($out, $this->zOffset);
5958
}
6059
}

src/types/entity/ByteMetadataProperty.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use pmmp\encoding\ByteBufferReader;
1919
use pmmp\encoding\ByteBufferWriter;
2020
use pocketmine\network\mcpe\protocol\types\GetTypeIdFromConstTrait;
21-
use pocketmine\utils\Binary;
2221

2322
final class ByteMetadataProperty implements MetadataProperty{
2423
use GetTypeIdFromConstTrait;
@@ -35,10 +34,10 @@ protected function max() : int{
3534
}
3635

3736
public static function read(ByteBufferReader $in) : self{
38-
return new self(Binary::signByte(Byte::readUnsigned($in)));
37+
return new self(Byte::readSigned($in));
3938
}
4039

4140
public function write(ByteBufferWriter $out) : void{
42-
Byte::writeUnsigned($out, $this->value);
41+
Byte::writeSigned($out, $this->value);
4342
}
4443
}

0 commit comments

Comments
 (0)