mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 10:19:39 +00:00
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.
This commit is contained in:
parent
5c5d96d00b
commit
d5762d3f44
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user