PacketSerializer: Improved performance of item serialize/deserialize

This commit is contained in:
Dylan K. Taylor 2021-03-31 21:39:55 +01:00
parent b7a6c9dc17
commit 5e8078f3dd
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -68,6 +68,13 @@ use function substr;
class PacketSerializer extends BinaryStream{ 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 * @throws BinaryDataException
*/ */
@ -244,7 +251,7 @@ class PacketSerializer extends BinaryStream{
} }
$shieldBlockingTick = null; $shieldBlockingTick = null;
if($id === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){ if($id === $this->shieldItemRuntimeId){
$shieldBlockingTick = $this->getVarLong(); $shieldBlockingTick = $this->getVarLong();
} }
@ -281,7 +288,7 @@ class PacketSerializer extends BinaryStream{
} }
$blockingTick = $item->getShieldBlockingTick(); $blockingTick = $item->getShieldBlockingTick();
if($item->getId() === ItemTypeDictionary::getInstance()->fromStringId("minecraft:shield")){ if($item->getId() === $this->shieldItemRuntimeId){
$this->putVarLong($blockingTick ?? 0); $this->putVarLong($blockingTick ?? 0);
} }
} }