From d5762d3f4487772ffb6b7c77af4cd659585f6520 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 27 Aug 2022 19:18:30 +0100 Subject: [PATCH] Item: allow describing type data to a reader as well as a writer we don't currently need this, but it's better to have it in case we need it after PM5 release. This is also now consistent with blocks. --- src/item/Banner.php | 3 ++- src/item/CoralFan.php | 3 ++- src/item/Dye.php | 3 ++- src/item/Item.php | 5 +++-- src/item/ItemBlock.php | 3 ++- src/item/Potion.php | 3 ++- src/item/SplashPotion.php | 3 ++- src/item/SuspiciousStew.php | 3 ++- 8 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/item/Banner.php b/src/item/Banner.php index 80def9ad5..6cb91eb6a 100644 --- a/src/item/Banner.php +++ b/src/item/Banner.php @@ -29,6 +29,7 @@ use pocketmine\block\utils\BannerPatternLayer; use pocketmine\block\utils\DyeColor; use pocketmine\data\bedrock\BannerPatternTypeIdMap; use pocketmine\data\bedrock\DyeColorIdMap; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\nbt\NBT; use pocketmine\nbt\tag\CompoundTag; @@ -63,7 +64,7 @@ class Banner extends ItemBlockWallOrFloor{ return $this; } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->dyeColor($this->color); } diff --git a/src/item/CoralFan.php b/src/item/CoralFan.php index acb8d3577..c3f23d2ca 100644 --- a/src/item/CoralFan.php +++ b/src/item/CoralFan.php @@ -27,6 +27,7 @@ use pocketmine\block\Block; use pocketmine\block\utils\CoralType; use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\VanillaBlocks; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\math\Axis; use pocketmine\math\Facing; @@ -41,7 +42,7 @@ final class CoralFan extends Item{ parent::__construct($identifier, VanillaBlocks::CORAL_FAN()->getName()); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ //this is aliased to ensure a compile error in case the functions in Item or Block start to differ in future //right now we can directly reuse encodeType from CoralTypeTrait, but that might silently stop working if Item //were to be altered. CoralTypeTrait was originally intended for blocks, so it's better not to assume anything. diff --git a/src/item/Dye.php b/src/item/Dye.php index 6f550ae18..4a32983d8 100644 --- a/src/item/Dye.php +++ b/src/item/Dye.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\item; use pocketmine\block\utils\DyeColor; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; class Dye extends Item{ @@ -34,7 +35,7 @@ class Dye extends Item{ parent::__construct($identifier, $name); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->dyeColor($this->color); } diff --git a/src/item/Item.php b/src/item/Item.php index 7170f4fab..32bf0ff44 100644 --- a/src/item/Item.php +++ b/src/item/Item.php @@ -32,6 +32,7 @@ use pocketmine\block\BlockToolType; use pocketmine\block\VanillaBlocks; use pocketmine\data\bedrock\EnchantmentIdMap; use pocketmine\data\bedrock\item\ItemTypeDeserializeException; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\data\SavedDataLoadingException; use pocketmine\entity\Entity; @@ -435,11 +436,11 @@ class Item implements \JsonSerializable{ final public function computeTypeData() : int{ $writer = new RuntimeDataWriter(16); //TODO: max bits should be a constant instead of being hardcoded all over the place - $this->encodeType($writer); + $this->describeType($writer); return $writer->getValue(); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ //NOOP } diff --git a/src/item/ItemBlock.php b/src/item/ItemBlock.php index 20504e8d0..0c50d0adb 100644 --- a/src/item/ItemBlock.php +++ b/src/item/ItemBlock.php @@ -26,6 +26,7 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\block\BlockFactory; use pocketmine\block\VanillaBlocks; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; /** @@ -52,7 +53,7 @@ final class ItemBlock extends Item{ $this->maxStackSize = $block->getMaxStackSize(); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->int(Block::INTERNAL_STATE_DATA_BITS, $this->blockTypeData); } diff --git a/src/item/Potion.php b/src/item/Potion.php index 5848dee47..1933c9909 100644 --- a/src/item/Potion.php +++ b/src/item/Potion.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\item; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Living; use pocketmine\player\Player; @@ -36,7 +37,7 @@ class Potion extends Item implements ConsumableItem{ parent::__construct($identifier, $name); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->potionType($this->potionType); } diff --git a/src/item/SplashPotion.php b/src/item/SplashPotion.php index ca4023e6a..462b670b3 100644 --- a/src/item/SplashPotion.php +++ b/src/item/SplashPotion.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\item; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; use pocketmine\entity\Location; use pocketmine\entity\projectile\SplashPotion as SplashPotionEntity; @@ -38,7 +39,7 @@ class SplashPotion extends ProjectileItem{ parent::__construct($identifier, $name); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->potionType($this->potionType); } diff --git a/src/item/SuspiciousStew.php b/src/item/SuspiciousStew.php index e6b9895e0..8f5eb3e2d 100644 --- a/src/item/SuspiciousStew.php +++ b/src/item/SuspiciousStew.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\item; +use pocketmine\data\runtime\RuntimeDataReader; use pocketmine\data\runtime\RuntimeDataWriter; class SuspiciousStew extends Food{ @@ -34,7 +35,7 @@ class SuspiciousStew extends Food{ parent::__construct($identifier, $name); } - protected function encodeType(RuntimeDataWriter $w) : void{ + protected function describeType(RuntimeDataReader|RuntimeDataWriter $w) : void{ $w->suspiciousStewType($this->suspiciousStewType); }