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
This commit is contained in:
Dylan K. Taylor 2016-10-19 09:41:59 +01:00 committed by GitHub
parent e7e476b65e
commit 3ddfb97921

View File

@ -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);