Skip to content

Commit

Permalink
Use first-class callables wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Feb 16, 2024
1 parent 2d2dd91 commit 14a06a0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/CameraInstructionPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public function getFade() : ?CameraFadeInstruction{ return $this->fade; }

protected function decodePayload(PacketSerializer $in) : void{
$this->set = $in->readOptional(fn() => CameraSetInstruction::read($in));
$this->clear = $in->readOptional(fn() => $in->getBool());
$this->clear = $in->readOptional($in->getBool(...));
$this->fade = $in->readOptional(fn() => CameraFadeInstruction::read($in));
}

protected function encodePayload(PacketSerializer $out) : void{
$out->writeOptional($this->set, fn(CameraSetInstruction $v) => $v->write($out));
$out->writeOptional($this->clear, fn(bool $v) => $out->putBool($v));
$out->writeOptional($this->clear, $out->putBool(...));
$out->writeOptional($this->fade, fn(CameraFadeInstruction $v) => $v->write($out));
}

Expand Down
4 changes: 2 additions & 2 deletions src/EducationSettingsPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->postProcessFilter = $in->getString();
$this->screenshotBorderResourcePath = $in->getString();
$this->agentCapabilities = $in->readOptional(fn() => EducationSettingsAgentCapabilities::read($in));
$this->codeBuilderOverrideUri = $in->readOptional(fn() => $in->getString());
$this->codeBuilderOverrideUri = $in->readOptional($in->getString(...));
$this->hasQuiz = $in->getBool();
$this->linkSettings = $in->readOptional(fn() => EducationSettingsExternalLinkSettings::read($in));
}
Expand All @@ -112,7 +112,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->postProcessFilter);
$out->putString($this->screenshotBorderResourcePath);
$out->writeOptional($this->agentCapabilities, fn(EducationSettingsAgentCapabilities $v) => $v->write($out));
$out->writeOptional($this->codeBuilderOverrideUri, fn(string $v) => $out->putString($v));
$out->writeOptional($this->codeBuilderOverrideUri, $out->putString(...));
$out->putBool($this->hasQuiz);
$out->writeOptional($this->linkSettings, fn(EducationSettingsExternalLinkSettings $v) => $v->write($out));
}
Expand Down
8 changes: 4 additions & 4 deletions src/ModalFormResponsePacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ public static function cancel(int $formId, int $cancelReason) : self{

protected function decodePayload(PacketSerializer $in) : void{
$this->formId = $in->getUnsignedVarInt();
$this->formData = $in->readOptional(\Closure::fromCallable([$in, 'getString']));
$this->cancelReason = $in->readOptional(\Closure::fromCallable([$in, 'getByte']));
$this->formData = $in->readOptional($in->getString(...));
$this->cancelReason = $in->readOptional($in->getByte(...));
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt($this->formId);

$out->writeOptional($this->formData, \Closure::fromCallable([$out, 'putString']));
$out->writeOptional($this->cancelReason, \Closure::fromCallable([$out, 'putByte']));
$out->writeOptional($this->formData, $out->putString(...));
$out->writeOptional($this->cancelReason, $out->putByte(...));
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
4 changes: 2 additions & 2 deletions src/types/EducationSettingsAgentCapabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function __construct(
public function getCanModifyBlocks() : ?bool{ return $this->canModifyBlocks; }

public static function read(PacketSerializer $in) : self{
$canModifyBlocks = $in->readOptional(\Closure::fromCallable([$in, 'getBool']));
$canModifyBlocks = $in->readOptional($in->getBool(...));
return new self($canModifyBlocks);
}

public function write(PacketSerializer $out) : void{
$out->writeOptional($this->canModifyBlocks, \Closure::fromCallable([$out, 'putBool']));
$out->writeOptional($this->canModifyBlocks, $out->putBool(...));
}
}
4 changes: 2 additions & 2 deletions src/types/LevelSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function internalRead(PacketSerializer $in) : void{
$this->limitedWorldLength = $in->getLInt();
$this->isNewNether = $in->getBool();
$this->eduSharedUriResource = EducationUriResource::read($in);
$this->experimentalGameplayOverride = $in->readOptional(\Closure::fromCallable([$in, 'getBool']));
$this->experimentalGameplayOverride = $in->readOptional($in->getBool(...));
$this->chatRestrictionLevel = $in->getByte();
$this->disablePlayerInteractions = $in->getBool();
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public function write(PacketSerializer $out) : void{
$out->putLInt($this->limitedWorldLength);
$out->putBool($this->isNewNether);
($this->eduSharedUriResource ?? new EducationUriResource("", ""))->write($out);
$out->writeOptional($this->experimentalGameplayOverride, \Closure::fromCallable([$out, 'putBool']));
$out->writeOptional($this->experimentalGameplayOverride, $out->putBool(...));
$out->putByte($this->chatRestrictionLevel);
$out->putBool($this->disablePlayerInteractions);
}
Expand Down
28 changes: 14 additions & 14 deletions src/types/camera/CameraPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public function getPlayerEffects() : ?bool{ return $this->playerEffects; }
public static function read(PacketSerializer $in) : self{
$name = $in->getString();
$parent = $in->getString();
$xPosition = $in->readOptional(fn() => $in->getLFloat());
$yPosition = $in->readOptional(fn() => $in->getLFloat());
$zPosition = $in->readOptional(fn() => $in->getLFloat());
$pitch = $in->readOptional(fn() => $in->getLFloat());
$yaw = $in->readOptional(fn() => $in->getLFloat());
$audioListenerType = $in->readOptional(fn() => $in->getByte());
$playerEffects = $in->readOptional(fn() => $in->getBool());
$xPosition = $in->readOptional($in->getLFloat(...));
$yPosition = $in->readOptional($in->getLFloat(...));
$zPosition = $in->readOptional($in->getLFloat(...));
$pitch = $in->readOptional($in->getLFloat(...));
$yaw = $in->readOptional($in->getLFloat(...));
$audioListenerType = $in->readOptional($in->getByte(...));
$playerEffects = $in->readOptional($in->getBool(...));

return new self(
$name,
Expand All @@ -77,12 +77,12 @@ public static function read(PacketSerializer $in) : self{
public function write(PacketSerializer $out) : void{
$out->putString($this->name);
$out->putString($this->parent);
$out->writeOptional($this->xPosition, fn(float $v) => $out->putLFloat($v));
$out->writeOptional($this->yPosition, fn(float $v) => $out->putLFloat($v));
$out->writeOptional($this->zPosition, fn(float $v) => $out->putLFloat($v));
$out->writeOptional($this->pitch, fn(float $v) => $out->putLFloat($v));
$out->writeOptional($this->yaw, fn(float $v) => $out->putLFloat($v));
$out->writeOptional($this->audioListenerType, fn(int $v) => $out->putByte($v));
$out->writeOptional($this->playerEffects, fn(bool $v) => $out->putBool($v));
$out->writeOptional($this->xPosition, $out->putLFloat(...));
$out->writeOptional($this->yPosition, $out->putLFloat(...));
$out->writeOptional($this->zPosition, $out->putLFloat(...));
$out->writeOptional($this->pitch, $out->putLFloat(...));
$out->writeOptional($this->yaw, $out->putLFloat(...));
$out->writeOptional($this->audioListenerType, $out->putByte(...));
$out->writeOptional($this->playerEffects, $out->putBool(...));
}
}
12 changes: 6 additions & 6 deletions src/types/camera/CameraSetInstruction.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function getDefault() : ?bool{ return $this->default; }
public static function read(PacketSerializer $in) : self{
$preset = $in->getLInt();
$ease = $in->readOptional(fn() => CameraSetInstructionEase::read($in));
$cameraPosition = $in->readOptional(fn() => $in->getVector3());
$cameraPosition = $in->readOptional($in->getVector3(...));
$rotation = $in->readOptional(fn() => CameraSetInstructionRotation::read($in));
$facingPosition = $in->readOptional(fn() => $in->getVector3());
$default = $in->readOptional(fn() => $in->getBool());
$facingPosition = $in->readOptional($in->getVector3(...));
$default = $in->readOptional($in->getBool(...));

return new self(
$preset,
Expand All @@ -61,9 +61,9 @@ public static function read(PacketSerializer $in) : self{
public function write(PacketSerializer $out) : void{
$out->putLInt($this->preset);
$out->writeOptional($this->ease, fn(CameraSetInstructionEase $v) => $v->write($out));
$out->writeOptional($this->cameraPosition, fn(Vector3 $v) => $out->putVector3($v));
$out->writeOptional($this->cameraPosition, $out->putVector3(...));
$out->writeOptional($this->rotation, fn(CameraSetInstructionRotation $v) => $v->write($out));
$out->writeOptional($this->facingPosition, fn(Vector3 $v) => $out->putVector3($v));
$out->writeOptional($this->default, fn(bool $v) => $out->putBool($v));
$out->writeOptional($this->facingPosition, $out->putVector3(...));
$out->writeOptional($this->default, $out->putBool(...));
}
}

0 comments on commit 14a06a0

Please sign in to comment.