mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
protocol ItemStack: added equals() method to compare net itemstacks directly
this will be needed for more than just this little check once item NBT gets cleaned out properly, since we'll need to compare object equality by network layer stuff instead of internals (where different network objects might deserialize to the same internal items).
This commit is contained in:
@ -97,4 +97,17 @@ final class ItemStack{
|
||||
public function getShieldBlockingTick() : ?int{
|
||||
return $this->shieldBlockingTick;
|
||||
}
|
||||
|
||||
public function equals(ItemStack $itemStack) : bool{
|
||||
return
|
||||
$this->id === $itemStack->id &&
|
||||
$this->meta === $itemStack->meta &&
|
||||
$this->count === $itemStack->count &&
|
||||
$this->canPlaceOn === $itemStack->canPlaceOn &&
|
||||
$this->canDestroy === $itemStack->canDestroy &&
|
||||
$this->shieldBlockingTick === $itemStack->shieldBlockingTick && (
|
||||
$this->nbt === $itemStack->nbt || //this covers null === null and fast object identity
|
||||
($this->nbt !== null && $itemStack->nbt !== null && $this->nbt->equals($itemStack->nbt))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user