mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
PacketSerializer: Improved performance of item serialize/deserialize
This commit is contained in:
parent
b7a6c9dc17
commit
5e8078f3dd
@ -68,6 +68,13 @@ use function substr;
|
||||
|
||||
class PacketSerializer extends BinaryStream{
|
||||
|
||||
private int $shieldItemRuntimeId;
|
||||
|
||||
public function __construct(string $buffer = "", int $offset = 0){
|
||||
parent::__construct($buffer, $offset);
|
||||
$this->shieldItemRuntimeId = ItemTypeDictionary::getInstance()->toRuntimeId("minecraft:shield");
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BinaryDataException
|
||||
*/
|
||||
@ -244,7 +251,7 @@ class PacketSerializer extends BinaryStream{
|
||||
}
|
||||
|
||||
$shieldBlockingTick = null;
|
||||
if($id === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
|
||||
if($id === $this->shieldItemRuntimeId){
|
||||
$shieldBlockingTick = $this->getVarLong();
|
||||
}
|
||||
|
||||
@ -281,7 +288,7 @@ class PacketSerializer extends BinaryStream{
|
||||
}
|
||||
|
||||
$blockingTick = $item->getShieldBlockingTick();
|
||||
if($item->getId() === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){
|
||||
if($item->getId() === $this->shieldItemRuntimeId){
|
||||
$this->putVarLong($blockingTick ?? 0);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user