pocketmine\item\Item::deepEquals PHP Method

deepEquals() final public method

final public deepEquals ( Item $item, boolean $checkDamage = true, boolean $checkCompound = true, boolean $checkCount = false ) : boolean
$item Item
$checkDamage boolean
$checkCompound boolean
$checkCount boolean
return boolean
    public final function deepEquals(Item $item, bool $checkDamage = true, bool $checkCompound = true, bool $checkCount = false) : bool
    {
        if ($this->equals($item, $checkDamage, $checkCompound, $checkCount)) {
            return true;
        } elseif ($item->hasCompoundTag() and $this->hasCompoundTag()) {
            return NBT::matchTree($this->getNamedTag(), $item->getNamedTag());
        }
        return false;
    }

Usage Example

Example #1
0
 public function onRename(Player $player, Item $resultItem) : bool
 {
     if (!$resultItem->deepEquals($this->getItem(self::TARGET), true, false, true)) {
         //Item does not match target item. Everything must match except the tags.
         return false;
     }
     if ($player->getExpLevel() < $resultItem->getRepairCost()) {
         //Not enough exp
         return false;
     }
     $player->setExpLevel($player->getExpLevel() - $resultItem->getRepairCost());
     $this->clearAll();
     if (!$player->getServer()->allowInventoryCheats and !$player->isCreative()) {
         if (!$player->getFloatingInventory()->canAddItem($resultItem)) {
             return false;
         }
         $player->getFloatingInventory()->addItem($resultItem);
     }
     return true;
 }