pocketmine\nbt\NBT::matchTree PHP Метод

matchTree() публичный статический Метод

public static matchTree ( CompoundTag $tag1, CompoundTag $tag2 )
$tag1 pocketmine\nbt\tag\CompoundTag
$tag2 pocketmine\nbt\tag\CompoundTag
    public static function matchTree(CompoundTag $tag1, CompoundTag $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 CompoundTag) {
                if (!self::matchTree($v, $tag2->{$k})) {
                    return false;
                }
            } elseif ($v instanceof ListTag) {
                if (!self::matchList($v, $tag2->{$k})) {
                    return false;
                }
            } else {
                if ($v->getValue() !== $tag2->{$k}->getValue()) {
                    return false;
                }
            }
        }
        return true;
    }

Usage Example

Пример #1
0
 public final function deepEquals(Item $item, $checkDamage = true, $checkCompound = true)
 {
     if ($this->equals($item, $checkDamage, $checkCompound)) {
         return true;
     } elseif ($item->hasCompoundTag() and $this->hasCompoundTag()) {
         return NBT::matchTree($this->getNamedTag(), $item->getNamedTag());
     }
     return false;
 }