mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Item: do not compare serialized NBT in equals()
this isn't cached anymore, and would be a performance drag. It would be nice to have some kind of fast path for this, but comparing NBT binary isn't it.
This commit is contained in:
parent
6c7dada232
commit
9b02b8e51e
@ -735,20 +735,9 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
* @param bool $checkCompound Whether to verify that the items' NBT match.
|
||||
*/
|
||||
final public function equals(Item $item, bool $checkDamage = true, bool $checkCompound = true) : bool{
|
||||
if($this->id === $item->getId() and (!$checkDamage or $this->getDamage() === $item->getDamage())){
|
||||
if($checkCompound){
|
||||
if($item->getCompoundTag() === $this->getCompoundTag()){
|
||||
return true;
|
||||
}elseif($this->hasCompoundTag() and $item->hasCompoundTag()){
|
||||
//Serialized NBT didn't match, check the cached object tree.
|
||||
return $this->getNamedTag()->equals($item->getNamedTag());
|
||||
}
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->id === $item->getId() and
|
||||
(!$checkDamage or $this->getDamage() === $item->getDamage()) and
|
||||
(!$checkCompound or $this->getNamedTag()->equals($item->getNamedTag()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user