22declare(strict_types=1);
24namespace pocketmine\data\bedrock\item;
42 private array $deserializers = [];
44 public function __construct(
53 public function map(
string $id, \Closure $deserializer) : void{
54 if(isset($this->deserializers[$id])){
55 throw new \InvalidArgumentException(
"Deserializer is already assigned for \"$id\"");
57 $this->deserializers[$id] = $deserializer;
63 public function mapBlock(
string $id, \Closure $deserializer) : void{
64 $this->map($id, fn(Data $data) => $deserializer($data)->asItem());
71 if(($blockData = $data->getBlock()) !== null){
74 $block = $this->blockStateDeserializer->deserialize($blockData);
82 return RuntimeBlockStateRegistry::getInstance()->fromStateId($block)->asItem();
84 $id = $data->getName();
85 if(!isset($this->deserializers[$id])){
89 return ($this->deserializers[$id])($data);
96 $itemStack = $this->deserializeType($data->getTypeData());
98 $itemStack->
setCount($data->getCount());
99 if(($tagTag = $data->getTypeData()->getTag()) !==
null){
101 $itemStack->setNamedTag(clone $tagTag);
108 if($itemStack instanceof
Durable && $itemStack->getDamage() === 0 && ($damage = $data->getTypeData()->getMeta()) > 0){
109 $itemStack->setDamage(min($damage, $itemStack->getMaxDurability()));
deserializeType(Data $data)
mapBlock(string $id, \Closure $deserializer)
deserializeStack(SavedItemStackData $data)
map(string $id, \Closure $deserializer)