Added jsonSerialize() to Item and fixed some crafting data decode issues

This commit is contained in:
Dylan K. Taylor
2016-11-08 11:19:51 +00:00
parent bee6c546dc
commit 911529a6cc
2 changed files with 40 additions and 39 deletions

View File

@ -38,7 +38,7 @@ use pocketmine\Player;
use pocketmine\Server;
use pocketmine\utils\Config;
class Item implements ItemIds{
class Item implements ItemIds, \JsonSerializable{
/** @var NBT */
private static $cachedParser = null;
@ -738,10 +738,6 @@ class Item implements ItemIds{
return false;
}
final public function __toString() : string{
return "Item " . $this->name . " (" . $this->id . ":" . ($this->meta === null ? "?" : $this->meta) . ")x" . $this->count . ($this->hasCompoundTag() ? " tags:0x" . bin2hex($this->getCompoundTag()) : "");
}
public function getDestroySpeed(Block $block, Player $player){
return 1;
}
@ -764,4 +760,17 @@ class Item implements ItemIds{
return false;
}
final public function __toString() : string{
return "Item " . $this->name . " (" . $this->id . ":" . ($this->meta === null ? "?" : $this->meta) . ")x" . $this->count . ($this->hasCompoundTag() ? " tags:0x" . bin2hex($this->getCompoundTag()) : "");
}
final public function jsonSerialize(){
return [
"id" => $this->id,
"damage" => $this->meta,
"count" => $this->count, //TODO: separate items and stacks
"nbt" => $this->tags
];
}
}