Generate traits for runtime enum serialization instead of helper classes

This commit is contained in:
Dylan K. Taylor 2022-07-18 15:13:40 +01:00
parent 172bd9a129
commit 8660dfe576
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
17 changed files with 81 additions and 87 deletions

View File

@ -59,8 +59,8 @@ function buildWriterFunc(string $virtualTypeName, string $nativeTypeName, array
$lines = []; $lines = [];
$functionName = "write$virtualTypeName"; $functionName = "write$virtualTypeName";
$lines[] = "public static function $functionName(RuntimeDataWriter \$w, \\$nativeTypeName \$value) : void{"; $lines[] = "public function $functionName(\\$nativeTypeName \$value) : void{";
$lines[] = "\t\$w->writeInt($bits, match(\$value){"; $lines[] = "\t\$this->writeInt($bits, match(\$value){";
foreach($memberNames as $key => $memberName){ foreach($memberNames as $key => $memberName){
$lines[] = "\t\t$memberName => $key,"; $lines[] = "\t\t$memberName => $key,";
@ -84,8 +84,8 @@ function buildReaderFunc(string $virtualTypeName, string $nativeTypeName, array
$lines = []; $lines = [];
$functionName = "read$virtualTypeName"; $functionName = "read$virtualTypeName";
$lines[] = "public static function $functionName(RuntimeDataReader \$r) : \\$nativeTypeName{"; $lines[] = "public function $functionName() : \\$nativeTypeName{";
$lines[] = "\treturn match(\$r->readInt($bits)){"; $lines[] = "\treturn match(\$this->readInt($bits)){";
foreach($memberNames as $key => $memberName){ foreach($memberNames as $key => $memberName){
$lines[] = "\t\t$key => $memberName,"; $lines[] = "\t\t$key => $memberName,";
@ -165,8 +165,16 @@ $enumsUsed = [
PotionType::getAll() PotionType::getAll()
]; ];
$readerFuncs = []; $readerFuncs = [
$writerFuncs = []; "" => [
"abstract public function readInt(int \$bits) : int;"
]
];
$writerFuncs = [
"" => [
"abstract public function writeInt(int \$bits, int \$value) : void;"
]
];
$functionName = ""; $functionName = "";
foreach($enumsUsed as $enumMembers){ foreach($enumsUsed as $enumMembers){
@ -220,14 +228,14 @@ namespace pocketmine\data\runtime;
HEADER; HEADER;
echo "final class $className{\n\n"; echo "trait $className{\n\n";
echo implode("\n\n", array_map(fn(array $functionLines) => "\t" . implode("\n\t", $functionLines), $functions)); echo implode("\n\n", array_map(fn(array $functionLines) => "\t" . implode("\n\t", $functionLines), $functions));
echo "\n\n}\n"; echo "\n\n}\n";
file_put_contents(dirname(__DIR__) . '/src/data/runtime/' . $className . '.php', ob_get_clean()); file_put_contents(dirname(__DIR__) . '/src/data/runtime/' . $className . '.php', ob_get_clean());
} }
printFunctions($writerFuncs, "RuntimeEnumSerializer"); printFunctions($writerFuncs, "RuntimeEnumSerializerTrait");
printFunctions($readerFuncs, "RuntimeEnumDeserializer"); printFunctions($readerFuncs, "RuntimeEnumDeserializerTrait");
echo "Done. Don't forget to run CS fixup after generating code.\n"; echo "Done. Don't forget to run CS fixup after generating code.\n";

View File

@ -29,8 +29,6 @@ use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\block\utils\SupportType; use pocketmine\block\utils\SupportType;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing; use pocketmine\math\Facing;
@ -52,12 +50,12 @@ final class Bell extends Transparent{
public function getRequiredStateDataBits() : int{ return 4; } public function getRequiredStateDataBits() : int{ return 4; }
protected function decodeState(RuntimeDataReader $r) : void{ protected function decodeState(RuntimeDataReader $r) : void{
$this->attachmentType = RuntimeEnumDeserializer::readBellAttachmentType($r); $this->attachmentType = $r->readBellAttachmentType();
$this->facing = $r->readHorizontalFacing(); $this->facing = $r->readHorizontalFacing();
} }
protected function encodeState(RuntimeDataWriter $w) : void{ protected function encodeState(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeBellAttachmentType($w, $this->attachmentType); $w->writeBellAttachmentType($this->attachmentType);
$w->writeHorizontalFacing($this->facing); $w->writeHorizontalFacing($this->facing);
} }

View File

@ -26,8 +26,6 @@ namespace pocketmine\block;
use pocketmine\block\utils\LeverFacing; use pocketmine\block\utils\LeverFacing;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Axis; use pocketmine\math\Axis;
use pocketmine\math\Facing; use pocketmine\math\Facing;
@ -50,12 +48,12 @@ class Lever extends Flowable{
public function getRequiredStateDataBits() : int{ return 4; } public function getRequiredStateDataBits() : int{ return 4; }
protected function decodeState(RuntimeDataReader $r) : void{ protected function decodeState(RuntimeDataReader $r) : void{
$this->facing = RuntimeEnumDeserializer::readLeverFacing($r); $this->facing = $r->readLeverFacing();
$this->activated = $r->readBool(); $this->activated = $r->readBool();
} }
protected function encodeState(RuntimeDataWriter $w) : void{ protected function encodeState(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeLeverFacing($w, $this->facing); $w->writeLeverFacing($this->facing);
$w->writeBool($this->activated); $w->writeBool($this->activated);
} }

View File

@ -26,8 +26,6 @@ namespace pocketmine\block;
use pocketmine\block\utils\MushroomBlockType; use pocketmine\block\utils\MushroomBlockType;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\item\Item; use pocketmine\item\Item;
use function mt_rand; use function mt_rand;
@ -42,11 +40,11 @@ class RedMushroomBlock extends Opaque{
public function getRequiredStateDataBits() : int{ return 4; } public function getRequiredStateDataBits() : int{ return 4; }
protected function decodeState(RuntimeDataReader $r) : void{ protected function decodeState(RuntimeDataReader $r) : void{
$this->mushroomBlockType = RuntimeEnumDeserializer::readMushroomBlockType($r); $this->mushroomBlockType = $r->readMushroomBlockType();
} }
protected function encodeState(RuntimeDataWriter $w) : void{ protected function encodeState(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeMushroomBlockType($w, $this->mushroomBlockType); $w->writeMushroomBlockType($this->mushroomBlockType);
} }
public function getMushroomBlockType() : MushroomBlockType{ return $this->mushroomBlockType; } public function getMushroomBlockType() : MushroomBlockType{ return $this->mushroomBlockType; }

View File

@ -28,8 +28,6 @@ use pocketmine\block\utils\SkullType;
use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; use pocketmine\data\runtime\InvalidSerializedRuntimeDataException;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing; use pocketmine\math\Facing;
@ -56,11 +54,11 @@ class Skull extends Flowable{
public function getRequiredTypeDataBits() : int{ return 3; } public function getRequiredTypeDataBits() : int{ return 3; }
protected function decodeType(RuntimeDataReader $r) : void{ protected function decodeType(RuntimeDataReader $r) : void{
$this->skullType = RuntimeEnumDeserializer::readSkullType($r); $this->skullType = $r->readSkullType();
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeSkullType($w, $this->skullType); $w->writeSkullType($this->skullType);
} }
public function getRequiredStateDataBits() : int{ return 3; } public function getRequiredStateDataBits() : int{ return 3; }

View File

@ -27,8 +27,6 @@ use pocketmine\block\utils\SlabType;
use pocketmine\block\utils\SupportType; use pocketmine\block\utils\SupportType;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing; use pocketmine\math\Facing;
@ -47,11 +45,11 @@ class Slab extends Transparent{
public function getRequiredStateDataBits() : int{ return 2; } public function getRequiredStateDataBits() : int{ return 2; }
protected function decodeState(RuntimeDataReader $r) : void{ protected function decodeState(RuntimeDataReader $r) : void{
$this->slabType = RuntimeEnumDeserializer::readSlabType($r); $this->slabType = $r->readSlabType();
} }
protected function encodeState(RuntimeDataWriter $w) : void{ protected function encodeState(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeSlabType($w, $this->slabType); $w->writeSlabType($this->slabType);
} }
public function isTransparent() : bool{ public function isTransparent() : bool{

View File

@ -26,8 +26,6 @@ namespace pocketmine\block\utils;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
trait ColoredTrait{ trait ColoredTrait{
/** @var DyeColor */ /** @var DyeColor */
@ -37,12 +35,12 @@ trait ColoredTrait{
/** @see Block::decodeType() */ /** @see Block::decodeType() */
protected function decodeType(RuntimeDataReader $r) : void{ protected function decodeType(RuntimeDataReader $r) : void{
$this->color = RuntimeEnumDeserializer::readDyeColor($r); $this->color = $r->readDyeColor();
} }
/** @see Block::encodeType() */ /** @see Block::encodeType() */
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeDyeColor($w, $this->color); $w->writeDyeColor($this->color);
} }
public function getColor() : DyeColor{ return $this->color; } public function getColor() : DyeColor{ return $this->color; }

View File

@ -25,8 +25,6 @@ namespace pocketmine\block\utils;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\item\Axe; use pocketmine\item\Axe;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\ItemTypeIds; use pocketmine\item\ItemTypeIds;
@ -43,12 +41,12 @@ trait CopperTrait{
public function getRequiredTypeDataBits() : int{ return 3; } public function getRequiredTypeDataBits() : int{ return 3; }
protected function decodeType(RuntimeDataReader $r) : void{ protected function decodeType(RuntimeDataReader $r) : void{
$this->oxidation = RuntimeEnumDeserializer::readCopperOxidation($r); $this->oxidation = $r->readCopperOxidation();
$this->waxed = $r->readBool(); $this->waxed = $r->readBool();
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeCopperOxidation($w, $this->oxidation); $w->writeCopperOxidation($this->oxidation);
$w->writeBool($this->waxed); $w->writeBool($this->waxed);
} }

View File

@ -26,8 +26,6 @@ namespace pocketmine\block\utils;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataReader;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumDeserializer;
use pocketmine\data\runtime\RuntimeEnumSerializer;
trait CoralTypeTrait{ trait CoralTypeTrait{
protected CoralType $coralType; protected CoralType $coralType;
@ -37,13 +35,13 @@ trait CoralTypeTrait{
/** @see Block::decodeType() */ /** @see Block::decodeType() */
protected function decodeType(RuntimeDataReader $r) : void{ protected function decodeType(RuntimeDataReader $r) : void{
$this->coralType = RuntimeEnumDeserializer::readCoralType($r); $this->coralType = $r->readCoralType();
$this->dead = $r->readBool(); $this->dead = $r->readBool();
} }
/** @see Block::encodeType() */ /** @see Block::encodeType() */
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeCoralType($w, $this->coralType); $w->writeCoralType($this->coralType);
$w->writeBool($this->dead); $w->writeBool($this->dead);
} }

View File

@ -29,6 +29,7 @@ use pocketmine\math\Facing;
use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\AssumptionFailedError;
final class RuntimeDataReader{ final class RuntimeDataReader{
use RuntimeEnumDeserializerTrait;
private int $offset = 0; private int $offset = 0;

View File

@ -29,6 +29,7 @@ use pocketmine\math\Facing;
use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\AssumptionFailedError;
final class RuntimeDataWriter{ final class RuntimeDataWriter{
use RuntimeEnumSerializerTrait;
private int $value = 0; private int $value = 0;
private int $offset = 0; private int $offset = 0;

View File

@ -27,10 +27,12 @@ namespace pocketmine\data\runtime;
* This class is auto-generated. Do not edit it manually. * This class is auto-generated. Do not edit it manually.
* @see build/generate-runtime-enum-serializers.php * @see build/generate-runtime-enum-serializers.php
*/ */
final class RuntimeEnumDeserializer{ trait RuntimeEnumDeserializerTrait{
public static function readBellAttachmentType(RuntimeDataReader $r) : \pocketmine\block\utils\BellAttachmentType{ abstract public function readInt(int $bits) : int;
return match($r->readInt(2)){
public function readBellAttachmentType() : \pocketmine\block\utils\BellAttachmentType{
return match($this->readInt(2)){
0 => \pocketmine\block\utils\BellAttachmentType::CEILING(), 0 => \pocketmine\block\utils\BellAttachmentType::CEILING(),
1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(), 1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(),
2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(), 2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(),
@ -39,8 +41,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readCopperOxidation(RuntimeDataReader $r) : \pocketmine\block\utils\CopperOxidation{ public function readCopperOxidation() : \pocketmine\block\utils\CopperOxidation{
return match($r->readInt(2)){ return match($this->readInt(2)){
0 => \pocketmine\block\utils\CopperOxidation::EXPOSED(), 0 => \pocketmine\block\utils\CopperOxidation::EXPOSED(),
1 => \pocketmine\block\utils\CopperOxidation::NONE(), 1 => \pocketmine\block\utils\CopperOxidation::NONE(),
2 => \pocketmine\block\utils\CopperOxidation::OXIDIZED(), 2 => \pocketmine\block\utils\CopperOxidation::OXIDIZED(),
@ -49,8 +51,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readCoralType(RuntimeDataReader $r) : \pocketmine\block\utils\CoralType{ public function readCoralType() : \pocketmine\block\utils\CoralType{
return match($r->readInt(3)){ return match($this->readInt(3)){
0 => \pocketmine\block\utils\CoralType::BRAIN(), 0 => \pocketmine\block\utils\CoralType::BRAIN(),
1 => \pocketmine\block\utils\CoralType::BUBBLE(), 1 => \pocketmine\block\utils\CoralType::BUBBLE(),
2 => \pocketmine\block\utils\CoralType::FIRE(), 2 => \pocketmine\block\utils\CoralType::FIRE(),
@ -60,8 +62,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readDyeColor(RuntimeDataReader $r) : \pocketmine\block\utils\DyeColor{ public function readDyeColor() : \pocketmine\block\utils\DyeColor{
return match($r->readInt(4)){ return match($this->readInt(4)){
0 => \pocketmine\block\utils\DyeColor::BLACK(), 0 => \pocketmine\block\utils\DyeColor::BLACK(),
1 => \pocketmine\block\utils\DyeColor::BLUE(), 1 => \pocketmine\block\utils\DyeColor::BLUE(),
2 => \pocketmine\block\utils\DyeColor::BROWN(), 2 => \pocketmine\block\utils\DyeColor::BROWN(),
@ -82,8 +84,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readLeverFacing(RuntimeDataReader $r) : \pocketmine\block\utils\LeverFacing{ public function readLeverFacing() : \pocketmine\block\utils\LeverFacing{
return match($r->readInt(3)){ return match($this->readInt(3)){
0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(), 0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(),
1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(), 1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(),
2 => \pocketmine\block\utils\LeverFacing::EAST(), 2 => \pocketmine\block\utils\LeverFacing::EAST(),
@ -96,8 +98,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readMushroomBlockType(RuntimeDataReader $r) : \pocketmine\block\utils\MushroomBlockType{ public function readMushroomBlockType() : \pocketmine\block\utils\MushroomBlockType{
return match($r->readInt(4)){ return match($this->readInt(4)){
0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(), 0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(),
1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(), 1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(),
2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(), 2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(),
@ -113,8 +115,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readPotionType(RuntimeDataReader $r) : \pocketmine\item\PotionType{ public function readPotionType() : \pocketmine\item\PotionType{
return match($r->readInt(6)){ return match($this->readInt(6)){
0 => \pocketmine\item\PotionType::AWKWARD(), 0 => \pocketmine\item\PotionType::AWKWARD(),
1 => \pocketmine\item\PotionType::FIRE_RESISTANCE(), 1 => \pocketmine\item\PotionType::FIRE_RESISTANCE(),
2 => \pocketmine\item\PotionType::HARMING(), 2 => \pocketmine\item\PotionType::HARMING(),
@ -161,8 +163,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readSkullType(RuntimeDataReader $r) : \pocketmine\block\utils\SkullType{ public function readSkullType() : \pocketmine\block\utils\SkullType{
return match($r->readInt(3)){ return match($this->readInt(3)){
0 => \pocketmine\block\utils\SkullType::CREEPER(), 0 => \pocketmine\block\utils\SkullType::CREEPER(),
1 => \pocketmine\block\utils\SkullType::DRAGON(), 1 => \pocketmine\block\utils\SkullType::DRAGON(),
2 => \pocketmine\block\utils\SkullType::PLAYER(), 2 => \pocketmine\block\utils\SkullType::PLAYER(),
@ -173,8 +175,8 @@ final class RuntimeEnumDeserializer{
}; };
} }
public static function readSlabType(RuntimeDataReader $r) : \pocketmine\block\utils\SlabType{ public function readSlabType() : \pocketmine\block\utils\SlabType{
return match($r->readInt(2)){ return match($this->readInt(2)){
0 => \pocketmine\block\utils\SlabType::BOTTOM(), 0 => \pocketmine\block\utils\SlabType::BOTTOM(),
1 => \pocketmine\block\utils\SlabType::DOUBLE(), 1 => \pocketmine\block\utils\SlabType::DOUBLE(),
2 => \pocketmine\block\utils\SlabType::TOP(), 2 => \pocketmine\block\utils\SlabType::TOP(),

View File

@ -27,10 +27,12 @@ namespace pocketmine\data\runtime;
* This class is auto-generated. Do not edit it manually. * This class is auto-generated. Do not edit it manually.
* @see build/generate-runtime-enum-serializers.php * @see build/generate-runtime-enum-serializers.php
*/ */
final class RuntimeEnumSerializer{ trait RuntimeEnumSerializerTrait{
public static function writeBellAttachmentType(RuntimeDataWriter $w, \pocketmine\block\utils\BellAttachmentType $value) : void{ abstract public function writeInt(int $bits, int $value) : void;
$w->writeInt(2, match($value){
public function writeBellAttachmentType(\pocketmine\block\utils\BellAttachmentType $value) : void{
$this->writeInt(2, match($value){
\pocketmine\block\utils\BellAttachmentType::CEILING() => 0, \pocketmine\block\utils\BellAttachmentType::CEILING() => 0,
\pocketmine\block\utils\BellAttachmentType::FLOOR() => 1, \pocketmine\block\utils\BellAttachmentType::FLOOR() => 1,
\pocketmine\block\utils\BellAttachmentType::ONE_WALL() => 2, \pocketmine\block\utils\BellAttachmentType::ONE_WALL() => 2,
@ -39,8 +41,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeCopperOxidation(RuntimeDataWriter $w, \pocketmine\block\utils\CopperOxidation $value) : void{ public function writeCopperOxidation(\pocketmine\block\utils\CopperOxidation $value) : void{
$w->writeInt(2, match($value){ $this->writeInt(2, match($value){
\pocketmine\block\utils\CopperOxidation::EXPOSED() => 0, \pocketmine\block\utils\CopperOxidation::EXPOSED() => 0,
\pocketmine\block\utils\CopperOxidation::NONE() => 1, \pocketmine\block\utils\CopperOxidation::NONE() => 1,
\pocketmine\block\utils\CopperOxidation::OXIDIZED() => 2, \pocketmine\block\utils\CopperOxidation::OXIDIZED() => 2,
@ -49,8 +51,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeCoralType(RuntimeDataWriter $w, \pocketmine\block\utils\CoralType $value) : void{ public function writeCoralType(\pocketmine\block\utils\CoralType $value) : void{
$w->writeInt(3, match($value){ $this->writeInt(3, match($value){
\pocketmine\block\utils\CoralType::BRAIN() => 0, \pocketmine\block\utils\CoralType::BRAIN() => 0,
\pocketmine\block\utils\CoralType::BUBBLE() => 1, \pocketmine\block\utils\CoralType::BUBBLE() => 1,
\pocketmine\block\utils\CoralType::FIRE() => 2, \pocketmine\block\utils\CoralType::FIRE() => 2,
@ -60,8 +62,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeDyeColor(RuntimeDataWriter $w, \pocketmine\block\utils\DyeColor $value) : void{ public function writeDyeColor(\pocketmine\block\utils\DyeColor $value) : void{
$w->writeInt(4, match($value){ $this->writeInt(4, match($value){
\pocketmine\block\utils\DyeColor::BLACK() => 0, \pocketmine\block\utils\DyeColor::BLACK() => 0,
\pocketmine\block\utils\DyeColor::BLUE() => 1, \pocketmine\block\utils\DyeColor::BLUE() => 1,
\pocketmine\block\utils\DyeColor::BROWN() => 2, \pocketmine\block\utils\DyeColor::BROWN() => 2,
@ -82,8 +84,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeLeverFacing(RuntimeDataWriter $w, \pocketmine\block\utils\LeverFacing $value) : void{ public function writeLeverFacing(\pocketmine\block\utils\LeverFacing $value) : void{
$w->writeInt(3, match($value){ $this->writeInt(3, match($value){
\pocketmine\block\utils\LeverFacing::DOWN_AXIS_X() => 0, \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X() => 0,
\pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z() => 1, \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z() => 1,
\pocketmine\block\utils\LeverFacing::EAST() => 2, \pocketmine\block\utils\LeverFacing::EAST() => 2,
@ -96,8 +98,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeMushroomBlockType(RuntimeDataWriter $w, \pocketmine\block\utils\MushroomBlockType $value) : void{ public function writeMushroomBlockType(\pocketmine\block\utils\MushroomBlockType $value) : void{
$w->writeInt(4, match($value){ $this->writeInt(4, match($value){
\pocketmine\block\utils\MushroomBlockType::ALL_CAP() => 0, \pocketmine\block\utils\MushroomBlockType::ALL_CAP() => 0,
\pocketmine\block\utils\MushroomBlockType::CAP_EAST() => 1, \pocketmine\block\utils\MushroomBlockType::CAP_EAST() => 1,
\pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE() => 2, \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE() => 2,
@ -113,8 +115,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writePotionType(RuntimeDataWriter $w, \pocketmine\item\PotionType $value) : void{ public function writePotionType(\pocketmine\item\PotionType $value) : void{
$w->writeInt(6, match($value){ $this->writeInt(6, match($value){
\pocketmine\item\PotionType::AWKWARD() => 0, \pocketmine\item\PotionType::AWKWARD() => 0,
\pocketmine\item\PotionType::FIRE_RESISTANCE() => 1, \pocketmine\item\PotionType::FIRE_RESISTANCE() => 1,
\pocketmine\item\PotionType::HARMING() => 2, \pocketmine\item\PotionType::HARMING() => 2,
@ -161,8 +163,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeSkullType(RuntimeDataWriter $w, \pocketmine\block\utils\SkullType $value) : void{ public function writeSkullType(\pocketmine\block\utils\SkullType $value) : void{
$w->writeInt(3, match($value){ $this->writeInt(3, match($value){
\pocketmine\block\utils\SkullType::CREEPER() => 0, \pocketmine\block\utils\SkullType::CREEPER() => 0,
\pocketmine\block\utils\SkullType::DRAGON() => 1, \pocketmine\block\utils\SkullType::DRAGON() => 1,
\pocketmine\block\utils\SkullType::PLAYER() => 2, \pocketmine\block\utils\SkullType::PLAYER() => 2,
@ -173,8 +175,8 @@ final class RuntimeEnumSerializer{
}); });
} }
public static function writeSlabType(RuntimeDataWriter $w, \pocketmine\block\utils\SlabType $value) : void{ public function writeSlabType(\pocketmine\block\utils\SlabType $value) : void{
$w->writeInt(2, match($value){ $this->writeInt(2, match($value){
\pocketmine\block\utils\SlabType::BOTTOM() => 0, \pocketmine\block\utils\SlabType::BOTTOM() => 0,
\pocketmine\block\utils\SlabType::DOUBLE() => 1, \pocketmine\block\utils\SlabType::DOUBLE() => 1,
\pocketmine\block\utils\SlabType::TOP() => 2, \pocketmine\block\utils\SlabType::TOP() => 2,

View File

@ -30,7 +30,6 @@ use pocketmine\block\utils\DyeColor;
use pocketmine\data\bedrock\BannerPatternTypeIdMap; use pocketmine\data\bedrock\BannerPatternTypeIdMap;
use pocketmine\data\bedrock\DyeColorIdMap; use pocketmine\data\bedrock\DyeColorIdMap;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag; use pocketmine\nbt\tag\ListTag;
@ -65,7 +64,7 @@ class Banner extends ItemBlockWallOrFloor{
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeDyeColor($w, $this->color); $w->writeDyeColor($this->color);
} }
/** /**

View File

@ -25,7 +25,6 @@ namespace pocketmine\item;
use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\DyeColor;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumSerializer;
class Dye extends Item{ class Dye extends Item{
private DyeColor $color; private DyeColor $color;
@ -36,7 +35,7 @@ class Dye extends Item{
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writeDyeColor($w, $this->color); $w->writeDyeColor($this->color);
} }
public function getColor() : DyeColor{ public function getColor() : DyeColor{

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\entity\Living; use pocketmine\entity\Living;
use pocketmine\player\Player; use pocketmine\player\Player;
@ -38,7 +37,7 @@ class Potion extends Item implements ConsumableItem{
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writePotionType($w, $this->potionType); $w->writePotionType($this->potionType);
} }
public function getType() : PotionType{ return $this->potionType; } public function getType() : PotionType{ return $this->potionType; }

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\runtime\RuntimeDataWriter;
use pocketmine\data\runtime\RuntimeEnumSerializer;
use pocketmine\entity\Location; use pocketmine\entity\Location;
use pocketmine\entity\projectile\SplashPotion as SplashPotionEntity; use pocketmine\entity\projectile\SplashPotion as SplashPotionEntity;
use pocketmine\entity\projectile\Throwable; use pocketmine\entity\projectile\Throwable;
@ -40,7 +39,7 @@ class SplashPotion extends ProjectileItem{
} }
protected function encodeType(RuntimeDataWriter $w) : void{ protected function encodeType(RuntimeDataWriter $w) : void{
RuntimeEnumSerializer::writePotionType($w, $this->potionType); $w->writePotionType($this->potionType);
} }
public function getType() : PotionType{ return $this->potionType; } public function getType() : PotionType{ return $this->potionType; }