mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Added item stack serialize/deserialize methods
This commit is contained in:
@ -102,7 +102,7 @@ final class ItemSerializer{
|
||||
*
|
||||
* @throws ItemTypeSerializeException
|
||||
*/
|
||||
public function serialize(Item $item) : Data{
|
||||
public function serializeType(Item $item) : Data{
|
||||
if($item->isNull()){
|
||||
throw new \InvalidArgumentException("Cannot serialize a null itemstack");
|
||||
}
|
||||
@ -128,7 +128,7 @@ final class ItemSerializer{
|
||||
}
|
||||
|
||||
if($locatedSerializer === null){
|
||||
throw new ItemTypeSerializeException("No serializer registered for " . get_class($item) . " " . $item->getName());
|
||||
throw new ItemTypeSerializeException("No serializer registered for " . get_class($item) . " ($index) " . $item->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,6 +153,17 @@ final class ItemSerializer{
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function serializeStack(Item $item, ?int $slot = null) : SavedItemStackData{
|
||||
return new SavedItemStackData(
|
||||
$this->serializeType($item),
|
||||
$item->getCount(),
|
||||
$slot,
|
||||
null,
|
||||
[], //we currently represent canDestroy and canPlaceOn via NBT, like PC
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-template TBlockType of Block
|
||||
* @phpstan-param TBlockType $block
|
||||
|
Reference in New Issue
Block a user