From 3ddfb9792108e31eb9c7ce8ae87ec9d46185403d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 19 Oct 2016 09:41:59 +0100 Subject: [PATCH] Support PC item save format with string ID, close #32 (#33) * Fixed #32 * StringTag check, throw exception for other types * Short, not int * Fix misleading exception message --- src/pocketmine/nbt/NBT.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/nbt/NBT.php b/src/pocketmine/nbt/NBT.php index ea7f57300..a2ba63ba5 100644 --- a/src/pocketmine/nbt/NBT.php +++ b/src/pocketmine/nbt/NBT.php @@ -107,7 +107,15 @@ class NBT{ return Item::get(0); } - $item = Item::get($tag->id->getValue(), !isset($tag->Damage) ? 0 : $tag->Damage->getValue(), $tag->Count->getValue()); + if($tag->id instanceof ShortTag){ + $item = Item::get($tag->id->getValue(), !isset($tag->Damage) ? 0 : $tag->Damage->getValue(), $tag->Count->getValue()); + }elseif($tag->id instanceof StringTag){ //PC item save format + $item = Item::fromString($tag->id->getValue()); + $item->setDamage(!isset($tag->Damage) ? 0 : $tag->Damage->getValue()); + $item->setCount($tag->Count->getValue()); + }else{ + throw new \InvalidArgumentException("Item CompoundTag ID must be an instance of StringTag or ShortTag, " . get_class($tag->id) . " given"); + } if(isset($tag->tag) and $tag->tag instanceof CompoundTag){ $item->setNamedTag($tag->tag);