diff --git a/src/block/Anvil.php b/src/block/Anvil.php index 660554ac0..a859210fd 100644 --- a/src/block/Anvil.php +++ b/src/block/Anvil.php @@ -28,8 +28,8 @@ use pocketmine\block\utils\Fallable; use pocketmine\block\utils\FallableTrait; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -49,21 +49,21 @@ class Anvil extends Transparent implements Fallable{ public function getRequiredTypeDataBits() : int{ return 2; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ $this->setDamage($r->readBoundedInt(2, self::UNDAMAGED, self::VERY_DAMAGED)); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeInt(2, $this->getDamage()); } public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->setFacing($r->readHorizontalFacing()); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->getFacing()); } diff --git a/src/block/Bamboo.php b/src/block/Bamboo.php index 6011b88a1..eaf6c26db 100644 --- a/src/block/Bamboo.php +++ b/src/block/Bamboo.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Bamboo as ItemBamboo; use pocketmine\item\Fertilizer; @@ -58,13 +58,13 @@ class Bamboo extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->setLeafSize($r->readBoundedInt(2, self::NO_LEAVES, self::LARGE_LEAVES)); $this->setThick($r->readBool()); $this->setReady($r->readBool()); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(2, $this->getLeafSize()); $w->writeBool($this->isThick()); $w->writeBool($this->isReady()); diff --git a/src/block/BambooSapling.php b/src/block/BambooSapling.php index 05addc057..e1f23c565 100644 --- a/src/block/BambooSapling.php +++ b/src/block/BambooSapling.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Bamboo as ItemBamboo; use pocketmine\item\Fertilizer; @@ -39,11 +39,11 @@ final class BambooSapling extends Flowable{ public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->setReady($r->readBool()); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->isReady()); } diff --git a/src/block/Barrel.php b/src/block/Barrel.php index e26b4aa8e..2efef6bbc 100644 --- a/src/block/Barrel.php +++ b/src/block/Barrel.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\tile\Barrel as TileBarrel; use pocketmine\block\utils\AnyFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -41,12 +41,12 @@ class Barrel extends Opaque{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->setFacing($r->readFacing()); $this->setOpen($r->readBool()); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->getFacing()); $w->writeBool($this->isOpen()); } diff --git a/src/block/Bed.php b/src/block/Bed.php index 81cbd73cc..4fd65e909 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -28,8 +28,8 @@ use pocketmine\block\utils\ColoredTrait; use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\item\Item; @@ -56,13 +56,13 @@ class Bed extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->occupied = $r->readBool(); $this->head = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->occupied); $w->writeBool($this->head); diff --git a/src/block/Bedrock.php b/src/block/Bedrock.php index 8a187b741..ac8e95037 100644 --- a/src/block/Bedrock.php +++ b/src/block/Bedrock.php @@ -23,19 +23,19 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; class Bedrock extends Opaque{ private bool $burnsForever = false; public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->burnsForever = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->burnsForever); } diff --git a/src/block/Bell.php b/src/block/Bell.php index 175be9d47..bc13a3324 100644 --- a/src/block/Bell.php +++ b/src/block/Bell.php @@ -27,10 +27,10 @@ use pocketmine\block\tile\Bell as TileBell; use pocketmine\block\utils\BellAttachmentType; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -51,13 +51,13 @@ final class Bell extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ - $this->attachmentType = BlockDataReaderHelper::readBellAttachmentType($r); + protected function decodeState(RuntimeDataReader $r) : void{ + $this->attachmentType = RuntimeEnumDeserializer::readBellAttachmentType($r); $this->facing = $r->readHorizontalFacing(); } - protected function encodeState(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeBellAttachmentType($w, $this->attachmentType); + protected function encodeState(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeBellAttachmentType($w, $this->attachmentType); $w->writeHorizontalFacing($this->facing); } diff --git a/src/block/Block.php b/src/block/Block.php index baad10b8f..2d55a3879 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -29,8 +29,8 @@ namespace pocketmine\block; use pocketmine\block\tile\Spawnable; use pocketmine\block\tile\Tile; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; @@ -100,7 +100,7 @@ class Block{ final public function decodeTypeData(int $data) : void{ $typeBits = $this->getRequiredTypeDataBits(); $givenBits = $typeBits; - $reader = new BlockDataReader($givenBits, $data); + $reader = new RuntimeDataReader($givenBits, $data); $this->decodeType($reader); $readBits = $reader->getOffset(); @@ -113,7 +113,7 @@ class Block{ $typeBits = $this->getRequiredTypeDataBits(); $stateBits = $this->getRequiredStateDataBits(); $givenBits = $typeBits + $stateBits; - $reader = new BlockDataReader($givenBits, $data); + $reader = new RuntimeDataReader($givenBits, $data); $this->decodeTypeData($reader->readInt($typeBits)); $this->decodeState($reader); @@ -123,18 +123,18 @@ class Block{ } } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ //NOOP } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ //NOOP } final public function computeTypeData() : int{ $typeBits = $this->getRequiredTypeDataBits(); $requiredBits = $typeBits; - $writer = new BlockDataWriter($requiredBits); + $writer = new RuntimeDataWriter($requiredBits); $this->encodeType($writer); $writtenBits = $writer->getOffset(); @@ -152,7 +152,7 @@ class Block{ $typeBits = $this->getRequiredTypeDataBits(); $stateBits = $this->getRequiredStateDataBits(); $requiredBits = $typeBits + $stateBits; - $writer = new BlockDataWriter($requiredBits); + $writer = new RuntimeDataWriter($requiredBits); $writer->writeInt($typeBits, $this->computeTypeData()); $this->encodeState($writer); @@ -164,11 +164,11 @@ class Block{ return $writer->getValue(); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ //NOOP } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ //NOOP } diff --git a/src/block/BlockFactory.php b/src/block/BlockFactory.php index 4efc04cb6..1bc685686 100644 --- a/src/block/BlockFactory.php +++ b/src/block/BlockFactory.php @@ -50,9 +50,9 @@ use pocketmine\block\tile\Note as TileNote; use pocketmine\block\tile\ShulkerBox as TileShulkerBox; use pocketmine\block\tile\Skull as TileSkull; use pocketmine\block\tile\Smoker as TileSmoker; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\TreeType; use pocketmine\block\utils\WoodType; +use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; use pocketmine\item\Item; use pocketmine\item\ToolTier; use pocketmine\utils\AssumptionFailedError; @@ -829,9 +829,9 @@ class BlockFactory{ $v->decodeStateData($stateData); if($v->computeStateData() !== $stateData){ //if the fullID comes back different, this is a broken state that we can't rely on; map it to default - throw new InvalidBlockStateException("Corrupted state"); + throw new InvalidSerializedRuntimeDataException("Corrupted state"); } - }catch(InvalidBlockStateException $e){ //invalid property combination, leave it + }catch(InvalidSerializedRuntimeDataException $e){ //invalid property combination, leave it continue; } diff --git a/src/block/BrewingStand.php b/src/block/BrewingStand.php index cee9d0cc3..463ef5adb 100644 --- a/src/block/BrewingStand.php +++ b/src/block/BrewingStand.php @@ -26,10 +26,8 @@ namespace pocketmine\block; use pocketmine\block\tile\BrewingStand as TileBrewingStand; use pocketmine\block\utils\BrewingStandSlot; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -48,12 +46,29 @@ class BrewingStand extends Transparent{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ - $this->setSlots(BlockDataReaderHelper::readBrewingStandSlotKeySet($r)); + protected function decodeState(RuntimeDataReader $r) : void{ + $result = []; + foreach([ + BrewingStandSlot::EAST(), + BrewingStandSlot::NORTHWEST(), + BrewingStandSlot::SOUTHWEST(), + ] as $member){ + if($r->readBool()){ + $result[$member->id()] = $member; + } + } + + $this->setSlots($result); } - protected function encodeState(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeBrewingStandSlotKeySet($w, $this->slots); + protected function encodeState(RuntimeDataWriter $w) : void{ + foreach([ + \pocketmine\block\utils\BrewingStandSlot::EAST(), + \pocketmine\block\utils\BrewingStandSlot::NORTHWEST(), + \pocketmine\block\utils\BrewingStandSlot::SOUTHWEST(), + ] as $member){ + $w->writeBool(isset($this->slots[$member->id()])); + } } protected function recalculateCollisionBoxes() : array{ diff --git a/src/block/Button.php b/src/block/Button.php index 7e813af26..6cdcae351 100644 --- a/src/block/Button.php +++ b/src/block/Button.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\AnyFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -41,12 +41,12 @@ abstract class Button extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readFacing(); $this->pressed = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->facing); $w->writeBool($this->pressed); } diff --git a/src/block/Cactus.php b/src/block/Cactus.php index 83b8dcca4..cc8c602bf 100644 --- a/src/block/Cactus.php +++ b/src/block/Cactus.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; @@ -44,11 +44,11 @@ class Cactus extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(4, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->age); } diff --git a/src/block/Cake.php b/src/block/Cake.php index 1bd28aa57..cbb8f9389 100644 --- a/src/block/Cake.php +++ b/src/block/Cake.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\effect\EffectInstance; use pocketmine\entity\FoodSource; use pocketmine\entity\Living; @@ -43,11 +43,11 @@ class Cake extends Transparent implements FoodSource{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->bites = $r->readBoundedInt(3, 0, self::MAX_BITES); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->bites); } diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index f0f9b2464..5056598c3 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -26,8 +26,8 @@ namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; use pocketmine\block\utils\WoodType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -49,12 +49,12 @@ class CocoaBlock extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->age = $r->readBoundedInt(2, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeInt(2, $this->age); } diff --git a/src/block/Crops.php b/src/block/Crops.php index 15fc75752..f916dfb7d 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -41,11 +41,11 @@ abstract class Crops extends Flowable{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(3, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->age); } diff --git a/src/block/DaylightSensor.php b/src/block/DaylightSensor.php index f2f2fd6c8..8718b89c2 100644 --- a/src/block/DaylightSensor.php +++ b/src/block/DaylightSensor.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -44,12 +44,12 @@ class DaylightSensor extends Transparent{ public function getRequiredStateDataBits() : int{ return 5; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->signalStrength = $r->readBoundedInt(4, 0, 15); $this->inverted = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->signalStrength); $w->writeBool($this->inverted); } diff --git a/src/block/DetectorRail.php b/src/block/DetectorRail.php index 61667e9b8..716597214 100644 --- a/src/block/DetectorRail.php +++ b/src/block/DetectorRail.php @@ -23,20 +23,20 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; class DetectorRail extends StraightOnlyRail{ protected bool $activated = false; public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ parent::decodeState($r); $this->activated = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ parent::encodeState($w); $w->writeBool($this->activated); } diff --git a/src/block/Dirt.php b/src/block/Dirt.php index e8ae43851..a3c6da660 100644 --- a/src/block/Dirt.php +++ b/src/block/Dirt.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Hoe; use pocketmine\item\Item; use pocketmine\math\Facing; @@ -37,11 +37,11 @@ class Dirt extends Opaque{ public function getRequiredTypeDataBits() : int{ return 1; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ $this->coarse = $r->readBool(); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeBool($this->coarse); } diff --git a/src/block/Door.php b/src/block/Door.php index c00b6d171..6657a18f0 100644 --- a/src/block/Door.php +++ b/src/block/Door.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -44,14 +44,14 @@ class Door extends Transparent{ public function getRequiredStateDataBits() : int{ return 5; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->top = $r->readBool(); $this->hingeRight = $r->readBool(); $this->open = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->top); $w->writeBool($this->hingeRight); diff --git a/src/block/DoublePlant.php b/src/block/DoublePlant.php index 29f567d12..f291298f4 100644 --- a/src/block/DoublePlant.php +++ b/src/block/DoublePlant.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -36,11 +36,11 @@ class DoublePlant extends Flowable{ public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->top = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->top); } diff --git a/src/block/EndPortalFrame.php b/src/block/EndPortalFrame.php index f69262c97..5cc4294c8 100644 --- a/src/block/EndPortalFrame.php +++ b/src/block/EndPortalFrame.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; use pocketmine\block\utils\HorizontalFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -38,12 +38,12 @@ class EndPortalFrame extends Opaque{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->eye = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->eye); } diff --git a/src/block/Farmland.php b/src/block/Farmland.php index fbd2212d0..989254bc9 100644 --- a/src/block/Farmland.php +++ b/src/block/Farmland.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\event\entity\EntityTrampleFarmlandEvent; @@ -40,11 +40,11 @@ class Farmland extends Transparent{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->wetness = $r->readBoundedInt(3, 0, self::MAX_WETNESS); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->wetness); } diff --git a/src/block/FenceGate.php b/src/block/FenceGate.php index b9bc95e18..4fa531363 100644 --- a/src/block/FenceGate.php +++ b/src/block/FenceGate.php @@ -26,8 +26,8 @@ namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; use pocketmine\block\utils\WoodTypeTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -45,13 +45,13 @@ class FenceGate extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->open = $r->readBool(); $this->inWall = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->open); $w->writeBool($this->inWall); diff --git a/src/block/Fire.php b/src/block/Fire.php index c04926cc8..a176941cd 100644 --- a/src/block/Fire.php +++ b/src/block/Fire.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockBurnEvent; use pocketmine\event\block\BlockSpreadEvent; use pocketmine\math\Facing; @@ -42,11 +42,11 @@ class Fire extends BaseFire{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(4, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->age); } diff --git a/src/block/FloorCoralFan.php b/src/block/FloorCoralFan.php index 3a37af749..24769ae5b 100644 --- a/src/block/FloorCoralFan.php +++ b/src/block/FloorCoralFan.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Axis; @@ -40,11 +40,11 @@ final class FloorCoralFan extends BaseCoral{ public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->axis = $r->readHorizontalAxis(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalAxis($this->axis); } diff --git a/src/block/FrostedIce.php b/src/block/FrostedIce.php index 184f2ba87..60a42a4a5 100644 --- a/src/block/FrostedIce.php +++ b/src/block/FrostedIce.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockMeltEvent; use function mt_rand; @@ -35,11 +35,11 @@ class FrostedIce extends Ice{ public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(2, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(2, $this->age); } diff --git a/src/block/Furnace.php b/src/block/Furnace.php index 46bd76081..c1b29c986 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -26,8 +26,8 @@ namespace pocketmine\block; use pocketmine\block\tile\Furnace as TileFurnace; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; use pocketmine\block\utils\HorizontalFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -41,12 +41,12 @@ class Furnace extends Opaque{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->lit = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->lit); } diff --git a/src/block/Hopper.php b/src/block/Hopper.php index bba31f314..c1d01654c 100644 --- a/src/block/Hopper.php +++ b/src/block/Hopper.php @@ -24,11 +24,11 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\tile\Hopper as TileHopper; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\PoweredByRedstoneTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -43,16 +43,16 @@ class Hopper extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $facing = $r->readFacing(); if($facing === Facing::UP){ - throw new InvalidBlockStateException("Hopper may not face upward"); + throw new InvalidSerializedRuntimeDataException("Hopper may not face upward"); } $this->facing = $facing; $this->powered = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->facing); $w->writeBool($this->powered); } diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 38ac5fc44..cbaed26ec 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\tile\ItemFrame as TileItemFrame; use pocketmine\block\utils\AnyFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -49,12 +49,12 @@ class ItemFrame extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readFacing(); $this->hasMap = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->facing); $w->writeBool($this->hasMap); } diff --git a/src/block/Lantern.php b/src/block/Lantern.php index db560584c..bd620a58d 100644 --- a/src/block/Lantern.php +++ b/src/block/Lantern.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -39,11 +39,11 @@ class Lantern extends Transparent{ public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->hanging = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->hanging); } diff --git a/src/block/Leaves.php b/src/block/Leaves.php index 550afa322..93c423e06 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\SupportType; use pocketmine\block\utils\TreeType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; use pocketmine\item\VanillaItems; @@ -50,12 +50,12 @@ class Leaves extends Transparent{ public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->noDecay = $r->readBool(); $this->checkDecay = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->noDecay); $w->writeBool($this->checkDecay); } diff --git a/src/block/Lectern.php b/src/block/Lectern.php index e17d29961..6e7026ff8 100644 --- a/src/block/Lectern.php +++ b/src/block/Lectern.php @@ -27,8 +27,8 @@ use pocketmine\block\tile\Lectern as TileLectern; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\item\WritableBookBase; use pocketmine\math\AxisAlignedBB; @@ -49,12 +49,12 @@ class Lectern extends Transparent{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->producingSignal = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->producingSignal); } diff --git a/src/block/Lever.php b/src/block/Lever.php index d65b47849..d25ce1c44 100644 --- a/src/block/Lever.php +++ b/src/block/Lever.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\LeverFacing; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -49,13 +49,13 @@ class Lever extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ - $this->facing = BlockDataReaderHelper::readLeverFacing($r); + protected function decodeState(RuntimeDataReader $r) : void{ + $this->facing = RuntimeEnumDeserializer::readLeverFacing($r); $this->activated = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeLeverFacing($w, $this->facing); + protected function encodeState(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeLeverFacing($w, $this->facing); $w->writeBool($this->activated); } diff --git a/src/block/Light.php b/src/block/Light.php index 6f2ccbf57..f21fc35f9 100644 --- a/src/block/Light.php +++ b/src/block/Light.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -37,11 +37,11 @@ final class Light extends Flowable{ public function getRequiredTypeDataBits() : int{ return 4; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ $this->level = $r->readBoundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->level); } diff --git a/src/block/Liquid.php b/src/block/Liquid.php index 1ad1c112a..93c8219f5 100644 --- a/src/block/Liquid.php +++ b/src/block/Liquid.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\MinimumCostFlowCalculator; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\event\block\BlockFormEvent; use pocketmine\event\block\BlockSpreadEvent; @@ -51,13 +51,13 @@ abstract class Liquid extends Transparent{ public function getRequiredStateDataBits() : int{ return 5; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->decay = $r->readBoundedInt(3, 0, self::MAX_DECAY); $this->falling = $r->readBool(); $this->still = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->decay); $w->writeBool($this->falling); $w->writeBool($this->still); diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index 883eb2899..0c957a617 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\item\Item; use pocketmine\math\Axis; @@ -37,11 +37,11 @@ class NetherPortal extends Transparent{ public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->axis = $r->readHorizontalAxis(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalAxis($this->axis); } diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index 5d6bc8a31..d6c2287b1 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Item; use pocketmine\math\Facing; @@ -40,11 +40,11 @@ class NetherWartPlant extends Flowable{ public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(2, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(2, $this->age); } diff --git a/src/block/Rail.php b/src/block/Rail.php index a98b51416..5cce50949 100644 --- a/src/block/Rail.php +++ b/src/block/Rail.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\RailConnectionInfo; use pocketmine\data\bedrock\block\BlockLegacyMetadata; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\math\Facing; use function array_keys; use function implode; @@ -38,15 +38,15 @@ class Rail extends BaseRail{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $railShape = $r->readInt(4); if(!isset(RailConnectionInfo::CONNECTIONS[$railShape]) && !isset(RailConnectionInfo::CURVE_CONNECTIONS[$railShape])){ - throw new InvalidBlockStateException("Invalid rail shape $railShape"); + throw new InvalidSerializedRuntimeDataException("Invalid rail shape $railShape"); } $this->railShape = $railShape; } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->railShape); } diff --git a/src/block/RedMushroomBlock.php b/src/block/RedMushroomBlock.php index 2a4b9906b..17f9d4490 100644 --- a/src/block/RedMushroomBlock.php +++ b/src/block/RedMushroomBlock.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\MushroomBlockType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; use pocketmine\item\Item; use function mt_rand; @@ -41,12 +41,12 @@ class RedMushroomBlock extends Opaque{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ - $this->mushroomBlockType = BlockDataReaderHelper::readMushroomBlockType($r); + protected function decodeState(RuntimeDataReader $r) : void{ + $this->mushroomBlockType = RuntimeEnumDeserializer::readMushroomBlockType($r); } - protected function encodeState(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeMushroomBlockType($w, $this->mushroomBlockType); + protected function encodeState(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeMushroomBlockType($w, $this->mushroomBlockType); } public function getMushroomBlockType() : MushroomBlockType{ return $this->mushroomBlockType; } diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index a531889d1..769c7ef96 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -28,8 +28,8 @@ use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\PoweredByRedstoneTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -47,14 +47,14 @@ class RedstoneComparator extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->isSubtractMode = $r->readBool(); $this->powered = $r->readBool(); //TODO: this doesn't call the decoder from AnalogRedstoneSignalEmitter } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->isSubtractMode); $w->writeBool($this->powered); diff --git a/src/block/RedstoneLamp.php b/src/block/RedstoneLamp.php index e81f8e805..4b10797a4 100644 --- a/src/block/RedstoneLamp.php +++ b/src/block/RedstoneLamp.php @@ -24,19 +24,19 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\PoweredByRedstoneTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; class RedstoneLamp extends Opaque{ use PoweredByRedstoneTrait; public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->powered = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->powered); } diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index e0a183860..1a7ed5e3b 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Vector3; @@ -36,11 +36,11 @@ class RedstoneOre extends Opaque{ public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->lit = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->lit); } diff --git a/src/block/RedstoneRepeater.php b/src/block/RedstoneRepeater.php index 5e3ff6ba2..3b77bb262 100644 --- a/src/block/RedstoneRepeater.php +++ b/src/block/RedstoneRepeater.php @@ -26,8 +26,8 @@ namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\PoweredByRedstoneTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -46,13 +46,13 @@ class RedstoneRepeater extends Flowable{ public function getRequiredStateDataBits() : int{ return 5; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->delay = $r->readBoundedInt(2, self::MIN_DELAY - 1, self::MAX_DELAY - 1) + 1; $this->powered = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeInt(2, $this->delay - 1); $w->writeBool($this->powered); diff --git a/src/block/RedstoneTorch.php b/src/block/RedstoneTorch.php index de6f1c92f..420a07098 100644 --- a/src/block/RedstoneTorch.php +++ b/src/block/RedstoneTorch.php @@ -23,20 +23,20 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; class RedstoneTorch extends Torch{ protected bool $lit = true; public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ parent::decodeState($r); $this->lit = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ parent::encodeState($w); $w->writeBool($this->lit); } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index 39aaba3ba..82afb3334 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\TreeType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\StructureGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -49,11 +49,11 @@ class Sapling extends Flowable{ public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->ready = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->ready); } diff --git a/src/block/SeaPickle.php b/src/block/SeaPickle.php index 3dd1f74ad..4be3b89d7 100644 --- a/src/block/SeaPickle.php +++ b/src/block/SeaPickle.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Vector3; @@ -41,12 +41,12 @@ class SeaPickle extends Transparent{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->count = $r->readBoundedInt(2, self::MIN_COUNT - 1, self::MAX_COUNT - 1) + 1; $this->underwater = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(2, $this->count - 1); $w->writeBool($this->underwater); } diff --git a/src/block/ShulkerBox.php b/src/block/ShulkerBox.php index 49aa3ae85..f37a8a73f 100644 --- a/src/block/ShulkerBox.php +++ b/src/block/ShulkerBox.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\tile\ShulkerBox as TileShulkerBox; use pocketmine\block\utils\AnyFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\player\Player; @@ -37,11 +37,11 @@ class ShulkerBox extends Opaque{ public function getRequiredStateDataBits() : int{ return 0; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ //NOOP - we don't read or write facing here, because the tile persists it } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ //NOOP - we don't read or write facing here, because the tile persists it } diff --git a/src/block/SimplePressurePlate.php b/src/block/SimplePressurePlate.php index ad60f6ba5..cf203e35f 100644 --- a/src/block/SimplePressurePlate.php +++ b/src/block/SimplePressurePlate.php @@ -23,19 +23,19 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; abstract class SimplePressurePlate extends PressurePlate{ protected bool $pressed = false; public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->pressed = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->pressed); } diff --git a/src/block/Skull.php b/src/block/Skull.php index 26354c8cd..4dbdfb823 100644 --- a/src/block/Skull.php +++ b/src/block/Skull.php @@ -24,12 +24,12 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\tile\Skull as TileSkull; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\SkullType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -55,25 +55,25 @@ class Skull extends Flowable{ public function getRequiredTypeDataBits() : int{ return 3; } - protected function decodeType(BlockDataReader $r) : void{ - $this->skullType = BlockDataReaderHelper::readSkullType($r); + protected function decodeType(RuntimeDataReader $r) : void{ + $this->skullType = RuntimeEnumDeserializer::readSkullType($r); } - protected function encodeType(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeSkullType($w, $this->skullType); + protected function encodeType(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeSkullType($w, $this->skullType); } public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $facing = $r->readFacing(); if($facing === Facing::DOWN){ - throw new InvalidBlockStateException("Skull may not face down"); + throw new InvalidSerializedRuntimeDataException("Skull may not face down"); } $this->facing = $facing; } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->facing); } diff --git a/src/block/Slab.php b/src/block/Slab.php index e562c7adb..a1604d79c 100644 --- a/src/block/Slab.php +++ b/src/block/Slab.php @@ -25,10 +25,10 @@ namespace pocketmine\block; use pocketmine\block\utils\SlabType; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -46,12 +46,12 @@ class Slab extends Transparent{ public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ - $this->slabType = BlockDataReaderHelper::readSlabType($r); + protected function decodeState(RuntimeDataReader $r) : void{ + $this->slabType = RuntimeEnumDeserializer::readSlabType($r); } - protected function encodeState(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeSlabType($w, $this->slabType); + protected function encodeState(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeSlabType($w, $this->slabType); } public function isTransparent() : bool{ diff --git a/src/block/SnowLayer.php b/src/block/SnowLayer.php index 6642faaa8..d629d4d04 100644 --- a/src/block/SnowLayer.php +++ b/src/block/SnowLayer.php @@ -26,8 +26,8 @@ namespace pocketmine\block; use pocketmine\block\utils\Fallable; use pocketmine\block\utils\FallableTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockMeltEvent; use pocketmine\item\Item; use pocketmine\item\VanillaItems; @@ -49,11 +49,11 @@ class SnowLayer extends Flowable implements Fallable{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->layers = $r->readBoundedInt(3, self::MIN_LAYERS - 1, self::MAX_LAYERS - 1) + 1; } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->layers - 1); } diff --git a/src/block/Sponge.php b/src/block/Sponge.php index ed25d8fb6..d2752a18f 100644 --- a/src/block/Sponge.php +++ b/src/block/Sponge.php @@ -23,19 +23,19 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; class Sponge extends Opaque{ protected bool $wet = false; public function getRequiredTypeDataBits() : int{ return 1; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ $this->wet = $r->readBool(); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeBool($this->wet); } diff --git a/src/block/Stair.php b/src/block/Stair.php index 6ccfb1312..67a3d7b40 100644 --- a/src/block/Stair.php +++ b/src/block/Stair.php @@ -26,8 +26,8 @@ namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\StairShape; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; @@ -49,12 +49,12 @@ class Stair extends Transparent{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->upsideDown = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->upsideDown); } diff --git a/src/block/StraightOnlyRail.php b/src/block/StraightOnlyRail.php index 0d125baa7..1c09c3cae 100644 --- a/src/block/StraightOnlyRail.php +++ b/src/block/StraightOnlyRail.php @@ -23,11 +23,11 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\RailConnectionInfo; use pocketmine\data\bedrock\block\BlockLegacyMetadata; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use function array_keys; use function implode; @@ -40,15 +40,15 @@ class StraightOnlyRail extends BaseRail{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $railShape = $r->readInt(3); if(!isset(RailConnectionInfo::CONNECTIONS[$railShape])){ - throw new InvalidBlockStateException("No rail shape matches meta $railShape"); + throw new InvalidSerializedRuntimeDataException("No rail shape matches meta $railShape"); } $this->railShape = $railShape; } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->railShape); } diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index 9643b7c4f..f91f13a5e 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\event\block\BlockGrowEvent; use pocketmine\item\Fertilizer; use pocketmine\item\Item; @@ -40,11 +40,11 @@ class Sugarcane extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(4, 0, self::MAX_AGE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->age); } diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index 0220125c4..54e785664 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\entity\Living; use pocketmine\event\block\BlockGrowEvent; @@ -48,11 +48,11 @@ class SweetBerryBush extends Flowable{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->age = $r->readBoundedInt(3, self::STAGE_SAPLING, self::STAGE_MATURE); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->age); } diff --git a/src/block/TNT.php b/src/block/TNT.php index a62f59e3c..30ebb42f6 100644 --- a/src/block/TNT.php +++ b/src/block/TNT.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\entity\Location; use pocketmine\entity\object\PrimedTNT; @@ -47,21 +47,21 @@ class TNT extends Opaque{ public function getRequiredTypeDataBits() : int{ return 1; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ $this->worksUnderwater = $r->readBool(); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeBool($this->worksUnderwater); } public function getRequiredStateDataBits() : int{ return 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->unstable = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->unstable); } diff --git a/src/block/Torch.php b/src/block/Torch.php index 6d887f2c4..dbb9014a8 100644 --- a/src/block/Torch.php +++ b/src/block/Torch.php @@ -23,10 +23,10 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\InvalidSerializedRuntimeDataException; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -40,15 +40,15 @@ class Torch extends Flowable{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $facing = $r->readFacing(); if($facing === Facing::DOWN){ - throw new InvalidBlockStateException("Torch cannot have a DOWN facing"); + throw new InvalidSerializedRuntimeDataException("Torch cannot have a DOWN facing"); } $this->facing = $facing; } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->facing); } diff --git a/src/block/Trapdoor.php b/src/block/Trapdoor.php index 4291e4ba4..74306d35e 100644 --- a/src/block/Trapdoor.php +++ b/src/block/Trapdoor.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; use pocketmine\block\utils\SupportType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -43,13 +43,13 @@ class Trapdoor extends Transparent{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->top = $r->readBool(); $this->open = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->top); $w->writeBool($this->open); diff --git a/src/block/Tripwire.php b/src/block/Tripwire.php index 53722d996..1971b391c 100644 --- a/src/block/Tripwire.php +++ b/src/block/Tripwire.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\item\VanillaItems; @@ -36,14 +36,14 @@ class Tripwire extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->triggered = $r->readBool(); $this->suspended = $r->readBool(); $this->connected = $r->readBool(); $this->disarmed = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeBool($this->triggered); $w->writeBool($this->suspended); $w->writeBool($this->connected); diff --git a/src/block/TripwireHook.php b/src/block/TripwireHook.php index 76cfa931c..bd240d20e 100644 --- a/src/block/TripwireHook.php +++ b/src/block/TripwireHook.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -41,13 +41,13 @@ class TripwireHook extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); $this->connected = $r->readBool(); $this->powered = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); $w->writeBool($this->connected); $w->writeBool($this->powered); diff --git a/src/block/UnknownBlock.php b/src/block/UnknownBlock.php index 0bf147778..753aee99d 100644 --- a/src/block/UnknownBlock.php +++ b/src/block/UnknownBlock.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; class UnknownBlock extends Transparent{ @@ -36,13 +36,13 @@ class UnknownBlock extends Transparent{ $this->stateData = $stateData; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ //use type instead of state, so we don't lose any information like colour //this might be an improperly registered plugin block $this->stateData = $r->readInt(Block::INTERNAL_STATE_DATA_BITS); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeInt(Block::INTERNAL_STATE_DATA_BITS, $this->stateData); } diff --git a/src/block/Vine.php b/src/block/Vine.php index e0bb154dc..d716b5eb8 100644 --- a/src/block/Vine.php +++ b/src/block/Vine.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Entity; use pocketmine\item\Item; use pocketmine\math\Axis; @@ -42,13 +42,13 @@ class Vine extends Flowable{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ foreach(Facing::HORIZONTAL as $facing){ $this->setFace($facing, $r->readBool()); } } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ foreach(Facing::HORIZONTAL as $facing){ $w->writeBool($this->hasFace($facing)); } diff --git a/src/block/Wall.php b/src/block/Wall.php index 15b6b6486..e3ceff6ce 100644 --- a/src/block/Wall.php +++ b/src/block/Wall.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\SupportType; use pocketmine\block\utils\WallConnectionType; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\math\Axis; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Facing; @@ -45,12 +45,12 @@ class Wall extends Transparent{ public function getRequiredStateDataBits() : int{ return 9; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->connections = $r->readWallConnections(); $this->post = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeWallConnections($this->connections); $w->writeBool($this->post); } diff --git a/src/block/WallCoralFan.php b/src/block/WallCoralFan.php index a0d710d70..9164c2cf1 100644 --- a/src/block/WallCoralFan.php +++ b/src/block/WallCoralFan.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\HorizontalFacingTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Axis; @@ -39,11 +39,11 @@ final class WallCoralFan extends BaseCoral{ public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); } diff --git a/src/block/Wood.php b/src/block/Wood.php index 46bb4afa6..d31d65f0e 100644 --- a/src/block/Wood.php +++ b/src/block/Wood.php @@ -25,8 +25,8 @@ namespace pocketmine\block; use pocketmine\block\utils\PillarRotationTrait; use pocketmine\block\utils\WoodTypeTrait; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Axe; use pocketmine\item\Item; use pocketmine\math\Vector3; @@ -40,11 +40,11 @@ class Wood extends Opaque{ public function getRequiredTypeDataBits() : int{ return 1; } - protected function decodeType(BlockDataReader $r) : void{ + protected function decodeType(RuntimeDataReader $r) : void{ $this->stripped = $r->readBool(); } - protected function encodeType(BlockDataWriter $w) : void{ + protected function encodeType(RuntimeDataWriter $w) : void{ $w->writeBool($this->stripped); } diff --git a/src/block/utils/AnalogRedstoneSignalEmitterTrait.php b/src/block/utils/AnalogRedstoneSignalEmitterTrait.php index 513ca4776..22d266aa7 100644 --- a/src/block/utils/AnalogRedstoneSignalEmitterTrait.php +++ b/src/block/utils/AnalogRedstoneSignalEmitterTrait.php @@ -23,19 +23,19 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; trait AnalogRedstoneSignalEmitterTrait{ protected int $signalStrength = 0; public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->signalStrength = $r->readBoundedInt(4, 0, 15); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->signalStrength); } diff --git a/src/block/utils/AnyFacingTrait.php b/src/block/utils/AnyFacingTrait.php index 580dbbd66..c6ccd5645 100644 --- a/src/block/utils/AnyFacingTrait.php +++ b/src/block/utils/AnyFacingTrait.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\math\Facing; trait AnyFacingTrait{ @@ -32,11 +32,11 @@ trait AnyFacingTrait{ public function getRequiredStateDataBits() : int{ return 3; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readFacing(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeFacing($this->facing); } diff --git a/src/block/utils/ColoredTrait.php b/src/block/utils/ColoredTrait.php index 0b4cb1d6b..3529f45af 100644 --- a/src/block/utils/ColoredTrait.php +++ b/src/block/utils/ColoredTrait.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\block\Block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; trait ColoredTrait{ /** @var DyeColor */ @@ -36,13 +36,13 @@ trait ColoredTrait{ public function getRequiredTypeDataBits() : int{ return 4; } /** @see Block::decodeType() */ - protected function decodeType(BlockDataReader $r) : void{ - $this->color = BlockDataReaderHelper::readDyeColor($r); + protected function decodeType(RuntimeDataReader $r) : void{ + $this->color = RuntimeEnumDeserializer::readDyeColor($r); } /** @see Block::encodeType() */ - protected function encodeType(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeDyeColor($w, $this->color); + protected function encodeType(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeDyeColor($w, $this->color); } public function getColor() : DyeColor{ return $this->color; } diff --git a/src/block/utils/CoralTypeTrait.php b/src/block/utils/CoralTypeTrait.php index ab6fd66f1..2e301f302 100644 --- a/src/block/utils/CoralTypeTrait.php +++ b/src/block/utils/CoralTypeTrait.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\block\Block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataReaderHelper; -use pocketmine\data\runtime\block\BlockDataWriter; -use pocketmine\data\runtime\block\BlockDataWriterHelper; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; +use pocketmine\data\runtime\RuntimeEnumDeserializer; +use pocketmine\data\runtime\RuntimeEnumSerializer; trait CoralTypeTrait{ protected CoralType $coralType; @@ -36,14 +36,14 @@ trait CoralTypeTrait{ public function getRequiredTypeDataBits() : int{ return 4; } /** @see Block::decodeType() */ - protected function decodeType(BlockDataReader $r) : void{ - $this->coralType = BlockDataReaderHelper::readCoralType($r); + protected function decodeType(RuntimeDataReader $r) : void{ + $this->coralType = RuntimeEnumDeserializer::readCoralType($r); $this->dead = $r->readBool(); } /** @see Block::encodeType() */ - protected function encodeType(BlockDataWriter $w) : void{ - BlockDataWriterHelper::writeCoralType($w, $this->coralType); + protected function encodeType(RuntimeDataWriter $w) : void{ + RuntimeEnumSerializer::writeCoralType($w, $this->coralType); $w->writeBool($this->dead); } diff --git a/src/block/utils/HorizontalFacingTrait.php b/src/block/utils/HorizontalFacingTrait.php index cadcf2ede..c20bab71e 100644 --- a/src/block/utils/HorizontalFacingTrait.php +++ b/src/block/utils/HorizontalFacingTrait.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -33,11 +33,11 @@ trait HorizontalFacingTrait{ public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->facing = $r->readHorizontalFacing(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeHorizontalFacing($this->facing); } diff --git a/src/block/utils/PillarRotationTrait.php b/src/block/utils/PillarRotationTrait.php index 03176ed92..c8fe6216b 100644 --- a/src/block/utils/PillarRotationTrait.php +++ b/src/block/utils/PillarRotationTrait.php @@ -24,8 +24,8 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\block\Block; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\item\Item; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -38,11 +38,11 @@ trait PillarRotationTrait{ public function getRequiredStateDataBits() : int{ return 2; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->axis = $r->readAxis(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeAxis($this->axis); } diff --git a/src/block/utils/RailPoweredByRedstoneTrait.php b/src/block/utils/RailPoweredByRedstoneTrait.php index 7a402d8e2..361129518 100644 --- a/src/block/utils/RailPoweredByRedstoneTrait.php +++ b/src/block/utils/RailPoweredByRedstoneTrait.php @@ -23,20 +23,20 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; trait RailPoweredByRedstoneTrait{ use PoweredByRedstoneTrait; public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ parent::decodeState($r); $this->powered = $r->readBool(); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ parent::encodeState($w); $w->writeBool($this->powered); } diff --git a/src/block/utils/SignLikeRotationTrait.php b/src/block/utils/SignLikeRotationTrait.php index b67829492..e5773dbbd 100644 --- a/src/block/utils/SignLikeRotationTrait.php +++ b/src/block/utils/SignLikeRotationTrait.php @@ -23,8 +23,8 @@ declare(strict_types=1); namespace pocketmine\block\utils; -use pocketmine\data\runtime\block\BlockDataReader; -use pocketmine\data\runtime\block\BlockDataWriter; +use pocketmine\data\runtime\RuntimeDataReader; +use pocketmine\data\runtime\RuntimeDataWriter; use function floor; trait SignLikeRotationTrait{ @@ -33,11 +33,11 @@ trait SignLikeRotationTrait{ public function getRequiredStateDataBits() : int{ return 4; } - protected function decodeState(BlockDataReader $r) : void{ + protected function decodeState(RuntimeDataReader $r) : void{ $this->rotation = $r->readBoundedInt(4, 0, 15); } - protected function encodeState(BlockDataWriter $w) : void{ + protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(4, $this->rotation); } diff --git a/src/block/utils/InvalidBlockStateException.php b/src/data/runtime/InvalidSerializedRuntimeDataException.php similarity index 86% rename from src/block/utils/InvalidBlockStateException.php rename to src/data/runtime/InvalidSerializedRuntimeDataException.php index f42581340..899a206f6 100644 --- a/src/block/utils/InvalidBlockStateException.php +++ b/src/data/runtime/InvalidSerializedRuntimeDataException.php @@ -21,8 +21,8 @@ declare(strict_types=1); -namespace pocketmine\block\utils; +namespace pocketmine\data\runtime; -class InvalidBlockStateException extends \UnexpectedValueException{ +final class InvalidSerializedRuntimeDataException extends \UnexpectedValueException{ } diff --git a/src/data/runtime/block/BlockDataReader.php b/src/data/runtime/RuntimeDataReader.php similarity index 89% rename from src/data/runtime/block/BlockDataReader.php rename to src/data/runtime/RuntimeDataReader.php index 5164ff53e..46c59cb27 100644 --- a/src/data/runtime/block/BlockDataReader.php +++ b/src/data/runtime/RuntimeDataReader.php @@ -21,15 +21,14 @@ declare(strict_types=1); -namespace pocketmine\data\runtime\block; +namespace pocketmine\data\runtime; -use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\block\utils\WallConnectionType; use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\utils\AssumptionFailedError; -final class BlockDataReader{ +final class RuntimeDataReader{ private int $offset = 0; @@ -52,7 +51,7 @@ final class BlockDataReader{ public function readBoundedInt(int $bits, int $min, int $max) : int{ $result = $this->readInt($bits); if($result < $min || $result > $max){ - throw new InvalidBlockStateException("Value is outside the range $min - $max"); + throw new InvalidSerializedRuntimeDataException("Value is outside the range $min - $max"); } return $result; } @@ -79,7 +78,7 @@ final class BlockDataReader{ 3 => Facing::SOUTH, 4 => Facing::WEST, 5 => Facing::EAST, - default => throw new InvalidBlockStateException("Invalid facing value") + default => throw new InvalidSerializedRuntimeDataException("Invalid facing value") }; } @@ -88,7 +87,7 @@ final class BlockDataReader{ 0 => Axis::X, 1 => Axis::Z, 2 => Axis::Y, - default => throw new InvalidBlockStateException("Invalid axis value") + default => throw new InvalidSerializedRuntimeDataException("Invalid axis value") }; } diff --git a/src/data/runtime/block/BlockDataWriter.php b/src/data/runtime/RuntimeDataWriter.php similarity index 97% rename from src/data/runtime/block/BlockDataWriter.php rename to src/data/runtime/RuntimeDataWriter.php index a4d87a5df..c00759237 100644 --- a/src/data/runtime/block/BlockDataWriter.php +++ b/src/data/runtime/RuntimeDataWriter.php @@ -21,14 +21,14 @@ declare(strict_types=1); -namespace pocketmine\data\runtime\block; +namespace pocketmine\data\runtime; use pocketmine\block\utils\WallConnectionType; use pocketmine\math\Axis; use pocketmine\math\Facing; use pocketmine\utils\AssumptionFailedError; -final class BlockDataWriter{ +final class RuntimeDataWriter{ private int $value = 0; private int $offset = 0; diff --git a/src/data/runtime/RuntimeEnumDeserializer.php b/src/data/runtime/RuntimeEnumDeserializer.php new file mode 100644 index 000000000..80739026c --- /dev/null +++ b/src/data/runtime/RuntimeEnumDeserializer.php @@ -0,0 +1,108 @@ +readInt(2)){ + 0 => \pocketmine\block\utils\BellAttachmentType::CEILING(), + 1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(), + 2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(), + 3 => \pocketmine\block\utils\BellAttachmentType::TWO_WALLS(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for BellAttachmentType") + }; + } + + public static function readCoralType(RuntimeDataReader $r) : \pocketmine\block\utils\CoralType{ + return match($r->readInt(3)){ + 0 => \pocketmine\block\utils\CoralType::BRAIN(), + 1 => \pocketmine\block\utils\CoralType::BUBBLE(), + 2 => \pocketmine\block\utils\CoralType::FIRE(), + 3 => \pocketmine\block\utils\CoralType::HORN(), + 4 => \pocketmine\block\utils\CoralType::TUBE(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for CoralType") + }; + } + + public static function readDyeColor(RuntimeDataReader $r) : \pocketmine\block\utils\DyeColor{ + return match($r->readInt(4)){ + 0 => \pocketmine\block\utils\DyeColor::BLACK(), + 1 => \pocketmine\block\utils\DyeColor::BLUE(), + 2 => \pocketmine\block\utils\DyeColor::BROWN(), + 3 => \pocketmine\block\utils\DyeColor::CYAN(), + 4 => \pocketmine\block\utils\DyeColor::GRAY(), + 5 => \pocketmine\block\utils\DyeColor::GREEN(), + 6 => \pocketmine\block\utils\DyeColor::LIGHT_BLUE(), + 7 => \pocketmine\block\utils\DyeColor::LIGHT_GRAY(), + 8 => \pocketmine\block\utils\DyeColor::LIME(), + 9 => \pocketmine\block\utils\DyeColor::MAGENTA(), + 10 => \pocketmine\block\utils\DyeColor::ORANGE(), + 11 => \pocketmine\block\utils\DyeColor::PINK(), + 12 => \pocketmine\block\utils\DyeColor::PURPLE(), + 13 => \pocketmine\block\utils\DyeColor::RED(), + 14 => \pocketmine\block\utils\DyeColor::WHITE(), + 15 => \pocketmine\block\utils\DyeColor::YELLOW(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for DyeColor") + }; + } + + public static function readLeverFacing(RuntimeDataReader $r) : \pocketmine\block\utils\LeverFacing{ + return match($r->readInt(3)){ + 0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(), + 1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(), + 2 => \pocketmine\block\utils\LeverFacing::EAST(), + 3 => \pocketmine\block\utils\LeverFacing::NORTH(), + 4 => \pocketmine\block\utils\LeverFacing::SOUTH(), + 5 => \pocketmine\block\utils\LeverFacing::UP_AXIS_X(), + 6 => \pocketmine\block\utils\LeverFacing::UP_AXIS_Z(), + 7 => \pocketmine\block\utils\LeverFacing::WEST(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for LeverFacing") + }; + } + + public static function readMushroomBlockType(RuntimeDataReader $r) : \pocketmine\block\utils\MushroomBlockType{ + return match($r->readInt(4)){ + 0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(), + 1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(), + 2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(), + 3 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTH(), + 4 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHEAST(), + 5 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHWEST(), + 6 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTH(), + 7 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHEAST(), + 8 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHWEST(), + 9 => \pocketmine\block\utils\MushroomBlockType::CAP_WEST(), + 10 => \pocketmine\block\utils\MushroomBlockType::PORES(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for MushroomBlockType") + }; + } + + public static function readSkullType(RuntimeDataReader $r) : \pocketmine\block\utils\SkullType{ + return match($r->readInt(3)){ + 0 => \pocketmine\block\utils\SkullType::CREEPER(), + 1 => \pocketmine\block\utils\SkullType::DRAGON(), + 2 => \pocketmine\block\utils\SkullType::PLAYER(), + 3 => \pocketmine\block\utils\SkullType::SKELETON(), + 4 => \pocketmine\block\utils\SkullType::WITHER_SKELETON(), + 5 => \pocketmine\block\utils\SkullType::ZOMBIE(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SkullType") + }; + } + + public static function readSlabType(RuntimeDataReader $r) : \pocketmine\block\utils\SlabType{ + return match($r->readInt(2)){ + 0 => \pocketmine\block\utils\SlabType::BOTTOM(), + 1 => \pocketmine\block\utils\SlabType::DOUBLE(), + 2 => \pocketmine\block\utils\SlabType::TOP(), + default => throw new InvalidSerializedRuntimeDataException("Invalid serialized value for SlabType") + }; + } + +} diff --git a/src/data/runtime/block/BlockDataWriterHelper.php b/src/data/runtime/RuntimeEnumSerializer.php similarity index 55% rename from src/data/runtime/block/BlockDataWriterHelper.php rename to src/data/runtime/RuntimeEnumSerializer.php index 1a49fac72..728fdf827 100644 --- a/src/data/runtime/block/BlockDataWriterHelper.php +++ b/src/data/runtime/RuntimeEnumSerializer.php @@ -1,41 +1,16 @@ writeInt(2, match($value){ \pocketmine\block\utils\BellAttachmentType::CEILING() => 0, \pocketmine\block\utils\BellAttachmentType::FLOOR() => 1, @@ -45,21 +20,7 @@ final class BlockDataWriterHelper{ }); } - /** - * @param \pocketmine\block\utils\BrewingStandSlot[] $value - * @phpstan-param array $value - */ - public static function writeBrewingStandSlotKeySet(BlockDataWriter $w, array $value) : void{ - foreach([ - \pocketmine\block\utils\BrewingStandSlot::EAST(), - \pocketmine\block\utils\BrewingStandSlot::NORTHWEST(), - \pocketmine\block\utils\BrewingStandSlot::SOUTHWEST(), - ] as $member){ - $w->writeBool(isset($value[$member->id()])); - } - } - - public static function writeCoralType(BlockDataWriter $w, CoralType $value) : void{ + public static function writeCoralType(RuntimeDataWriter $w, \pocketmine\block\utils\CoralType $value) : void{ $w->writeInt(3, match($value){ \pocketmine\block\utils\CoralType::BRAIN() => 0, \pocketmine\block\utils\CoralType::BUBBLE() => 1, @@ -70,7 +31,7 @@ final class BlockDataWriterHelper{ }); } - public static function writeDyeColor(BlockDataWriter $w, DyeColor $value) : void{ + public static function writeDyeColor(RuntimeDataWriter $w, \pocketmine\block\utils\DyeColor $value) : void{ $w->writeInt(4, match($value){ \pocketmine\block\utils\DyeColor::BLACK() => 0, \pocketmine\block\utils\DyeColor::BLUE() => 1, @@ -92,7 +53,7 @@ final class BlockDataWriterHelper{ }); } - public static function writeLeverFacing(BlockDataWriter $w, LeverFacing $value) : void{ + public static function writeLeverFacing(RuntimeDataWriter $w, \pocketmine\block\utils\LeverFacing $value) : void{ $w->writeInt(3, match($value){ \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X() => 0, \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z() => 1, @@ -106,7 +67,7 @@ final class BlockDataWriterHelper{ }); } - public static function writeMushroomBlockType(BlockDataWriter $w, MushroomBlockType $value) : void{ + public static function writeMushroomBlockType(RuntimeDataWriter $w, \pocketmine\block\utils\MushroomBlockType $value) : void{ $w->writeInt(4, match($value){ \pocketmine\block\utils\MushroomBlockType::ALL_CAP() => 0, \pocketmine\block\utils\MushroomBlockType::CAP_EAST() => 1, @@ -123,7 +84,7 @@ final class BlockDataWriterHelper{ }); } - public static function writeSkullType(BlockDataWriter $w, SkullType $value) : void{ + public static function writeSkullType(RuntimeDataWriter $w, \pocketmine\block\utils\SkullType $value) : void{ $w->writeInt(3, match($value){ \pocketmine\block\utils\SkullType::CREEPER() => 0, \pocketmine\block\utils\SkullType::DRAGON() => 1, @@ -135,7 +96,7 @@ final class BlockDataWriterHelper{ }); } - public static function writeSlabType(BlockDataWriter $w, SlabType $value) : void{ + public static function writeSlabType(RuntimeDataWriter $w, \pocketmine\block\utils\SlabType $value) : void{ $w->writeInt(2, match($value){ \pocketmine\block\utils\SlabType::BOTTOM() => 0, \pocketmine\block\utils\SlabType::DOUBLE() => 1, @@ -144,27 +105,4 @@ final class BlockDataWriterHelper{ }); } - public static function writeStairShape(BlockDataWriter $w, StairShape $value) : void{ - $w->writeInt(3, match($value){ - \pocketmine\block\utils\StairShape::INNER_LEFT() => 0, - \pocketmine\block\utils\StairShape::INNER_RIGHT() => 1, - \pocketmine\block\utils\StairShape::OUTER_LEFT() => 2, - \pocketmine\block\utils\StairShape::OUTER_RIGHT() => 3, - \pocketmine\block\utils\StairShape::STRAIGHT() => 4, - default => throw new \pocketmine\utils\AssumptionFailedError("All StairShape cases should be covered") - }); - } - - public static function writeTreeType(BlockDataWriter $w, TreeType $value) : void{ - $w->writeInt(3, match($value){ - \pocketmine\block\utils\TreeType::ACACIA() => 0, - \pocketmine\block\utils\TreeType::BIRCH() => 1, - \pocketmine\block\utils\TreeType::DARK_OAK() => 2, - \pocketmine\block\utils\TreeType::JUNGLE() => 3, - \pocketmine\block\utils\TreeType::OAK() => 4, - \pocketmine\block\utils\TreeType::SPRUCE() => 5, - default => throw new \pocketmine\utils\AssumptionFailedError("All TreeType cases should be covered") - }); - } - } diff --git a/src/data/runtime/block/BlockDataReaderHelper.php b/src/data/runtime/block/BlockDataReaderHelper.php deleted file mode 100644 index b8a3f7703..000000000 --- a/src/data/runtime/block/BlockDataReaderHelper.php +++ /dev/null @@ -1,174 +0,0 @@ -readInt(2)){ - 0 => \pocketmine\block\utils\BellAttachmentType::CEILING(), - 1 => \pocketmine\block\utils\BellAttachmentType::FLOOR(), - 2 => \pocketmine\block\utils\BellAttachmentType::ONE_WALL(), - 3 => \pocketmine\block\utils\BellAttachmentType::TWO_WALLS(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for BellAttachmentType") - }; - } - - /** - * @return \pocketmine\block\utils\BrewingStandSlot[] - * @phpstan-return array - */ - public static function readBrewingStandSlotKeySet(BlockDataReader $r) : array{ - $result = []; - foreach([ - \pocketmine\block\utils\BrewingStandSlot::EAST(), - \pocketmine\block\utils\BrewingStandSlot::NORTHWEST(), - \pocketmine\block\utils\BrewingStandSlot::SOUTHWEST(), - ] as $member){ - if($r->readBool()){ - $result[$member->id()] = $member; - } - } - return $result; - } - - public static function readCoralType(BlockDataReader $r) : CoralType{ - return match($r->readInt(3)){ - 0 => \pocketmine\block\utils\CoralType::BRAIN(), - 1 => \pocketmine\block\utils\CoralType::BUBBLE(), - 2 => \pocketmine\block\utils\CoralType::FIRE(), - 3 => \pocketmine\block\utils\CoralType::HORN(), - 4 => \pocketmine\block\utils\CoralType::TUBE(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for CoralType") - }; - } - - public static function readDyeColor(BlockDataReader $r) : DyeColor{ - return match($r->readInt(4)){ - 0 => \pocketmine\block\utils\DyeColor::BLACK(), - 1 => \pocketmine\block\utils\DyeColor::BLUE(), - 2 => \pocketmine\block\utils\DyeColor::BROWN(), - 3 => \pocketmine\block\utils\DyeColor::CYAN(), - 4 => \pocketmine\block\utils\DyeColor::GRAY(), - 5 => \pocketmine\block\utils\DyeColor::GREEN(), - 6 => \pocketmine\block\utils\DyeColor::LIGHT_BLUE(), - 7 => \pocketmine\block\utils\DyeColor::LIGHT_GRAY(), - 8 => \pocketmine\block\utils\DyeColor::LIME(), - 9 => \pocketmine\block\utils\DyeColor::MAGENTA(), - 10 => \pocketmine\block\utils\DyeColor::ORANGE(), - 11 => \pocketmine\block\utils\DyeColor::PINK(), - 12 => \pocketmine\block\utils\DyeColor::PURPLE(), - 13 => \pocketmine\block\utils\DyeColor::RED(), - 14 => \pocketmine\block\utils\DyeColor::WHITE(), - 15 => \pocketmine\block\utils\DyeColor::YELLOW(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for DyeColor") - }; - } - - public static function readLeverFacing(BlockDataReader $r) : LeverFacing{ - return match($r->readInt(3)){ - 0 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_X(), - 1 => \pocketmine\block\utils\LeverFacing::DOWN_AXIS_Z(), - 2 => \pocketmine\block\utils\LeverFacing::EAST(), - 3 => \pocketmine\block\utils\LeverFacing::NORTH(), - 4 => \pocketmine\block\utils\LeverFacing::SOUTH(), - 5 => \pocketmine\block\utils\LeverFacing::UP_AXIS_X(), - 6 => \pocketmine\block\utils\LeverFacing::UP_AXIS_Z(), - 7 => \pocketmine\block\utils\LeverFacing::WEST(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for LeverFacing") - }; - } - - public static function readMushroomBlockType(BlockDataReader $r) : MushroomBlockType{ - return match($r->readInt(4)){ - 0 => \pocketmine\block\utils\MushroomBlockType::ALL_CAP(), - 1 => \pocketmine\block\utils\MushroomBlockType::CAP_EAST(), - 2 => \pocketmine\block\utils\MushroomBlockType::CAP_MIDDLE(), - 3 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTH(), - 4 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHEAST(), - 5 => \pocketmine\block\utils\MushroomBlockType::CAP_NORTHWEST(), - 6 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTH(), - 7 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHEAST(), - 8 => \pocketmine\block\utils\MushroomBlockType::CAP_SOUTHWEST(), - 9 => \pocketmine\block\utils\MushroomBlockType::CAP_WEST(), - 10 => \pocketmine\block\utils\MushroomBlockType::PORES(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for MushroomBlockType") - }; - } - - public static function readSkullType(BlockDataReader $r) : SkullType{ - return match($r->readInt(3)){ - 0 => \pocketmine\block\utils\SkullType::CREEPER(), - 1 => \pocketmine\block\utils\SkullType::DRAGON(), - 2 => \pocketmine\block\utils\SkullType::PLAYER(), - 3 => \pocketmine\block\utils\SkullType::SKELETON(), - 4 => \pocketmine\block\utils\SkullType::WITHER_SKELETON(), - 5 => \pocketmine\block\utils\SkullType::ZOMBIE(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for SkullType") - }; - } - - public static function readSlabType(BlockDataReader $r) : SlabType{ - return match($r->readInt(2)){ - 0 => \pocketmine\block\utils\SlabType::BOTTOM(), - 1 => \pocketmine\block\utils\SlabType::DOUBLE(), - 2 => \pocketmine\block\utils\SlabType::TOP(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for SlabType") - }; - } - - public static function readStairShape(BlockDataReader $r) : StairShape{ - return match($r->readInt(3)){ - 0 => \pocketmine\block\utils\StairShape::INNER_LEFT(), - 1 => \pocketmine\block\utils\StairShape::INNER_RIGHT(), - 2 => \pocketmine\block\utils\StairShape::OUTER_LEFT(), - 3 => \pocketmine\block\utils\StairShape::OUTER_RIGHT(), - 4 => \pocketmine\block\utils\StairShape::STRAIGHT(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for StairShape") - }; - } - - public static function readTreeType(BlockDataReader $r) : TreeType{ - return match($r->readInt(3)){ - 0 => \pocketmine\block\utils\TreeType::ACACIA(), - 1 => \pocketmine\block\utils\TreeType::BIRCH(), - 2 => \pocketmine\block\utils\TreeType::DARK_OAK(), - 3 => \pocketmine\block\utils\TreeType::JUNGLE(), - 4 => \pocketmine\block\utils\TreeType::OAK(), - 5 => \pocketmine\block\utils\TreeType::SPRUCE(), - default => throw new \pocketmine\block\utils\InvalidBlockStateException("Invalid serialized value for TreeType") - }; - } - -}