Added custom block data (example, chests), better deep checking of same NBT

This commit is contained in:
Shoghi Cervantes
2015-08-07 17:24:35 +02:00
parent e9c981b586
commit 696edfd31f
10 changed files with 179 additions and 17 deletions

View File

@ -104,11 +104,11 @@ class NBT{
* @return Item
*/
public static function getItemHelper(Compound $tag){
if(!isset($tag->id) or !isset($tag->Damage) or !isset($tag->Count)){
if(!isset($tag->id) or !isset($tag->Count)){
return Item::get(0);
}
$item = Item::get($tag->id->getValue(), $tag->Damage->getValue(), $tag->Count->getValue());
$item = Item::get($tag->id->getValue(), !isset($tag->Damage) ? 0 : $tag->Damage->getValue(), $tag->Count->getValue());
if(isset($tag->tag) and $tag->tag instanceof Compound){
$item->setNamedTag($tag->tag);
@ -117,6 +117,70 @@ class NBT{
return $item;
}
public static function matchList(Enum $tag1, Enum $tag2){
if($tag1->getName() !== $tag2->getName() or $tag1->getCount() !== $tag2->getCount()){
return false;
}
foreach($tag1 as $k => $v){
if(!($v instanceof Tag)){
continue;
}
if(!isset($tag2->{$k}) or !($tag2->{$k} instanceof $v)){
return false;
}
if($v instanceof Compound){
if(!self::matchTree($v, $tag2->{$k})){
return false;
}
}elseif($v instanceof Enum){
if(!self::matchList($v, $tag2->{$k})){
return false;
}
}else{
if($v->getValue() !== $tag2->{$k}->getValue()){
return false;
}
}
}
return true;
}
public static function matchTree(Compound $tag1, Compound $tag2){
if($tag1->getName() !== $tag2->getName() or $tag1->getCount() !== $tag2->getCount()){
return false;
}
foreach($tag1 as $k => $v){
if(!($v instanceof Tag)){
continue;
}
if(!isset($tag2->{$k}) or !($tag2->{$k} instanceof $v)){
return false;
}
if($v instanceof Compound){
if(!self::matchTree($v, $tag2->{$k})){
return false;
}
}elseif($v instanceof Enum){
if(!self::matchList($v, $tag2->{$k})){
return false;
}
}else{
if($v->getValue() !== $tag2->{$k}->getValue()){
return false;
}
}
}
return true;
}
public function get($len){
if($len < 0){
$this->offset = strlen($this->buffer) - 1;