mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +00:00
Added API method Item->equalsExact() and removed some boilerplate code
This commit is contained in:
parent
0e51820dfb
commit
bd64172750
@ -2238,7 +2238,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
$item = $this->inventory->getItemInHand();
|
||||
$oldItem = clone $item;
|
||||
if($this->level->useItemOn($blockVector, $item, $face, $packet->trData->clickPos, $this, true)){
|
||||
if(!$item->equals($oldItem) or $item->getCount() !== $oldItem->getCount()){
|
||||
if(!$item->equalsExact($oldItem)){
|
||||
$this->inventory->setItemInHand($item);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
}
|
||||
@ -2270,7 +2270,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
|
||||
if($this->canInteract($blockVector->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 6) and $this->level->useBreakOn($blockVector, $item, $this, true)){
|
||||
if($this->isSurvival()){
|
||||
if(!$item->equals($oldItem) or $item->getCount() !== $oldItem->getCount()){
|
||||
if(!$item->equalsExact($oldItem)){
|
||||
$this->inventory->setItemInHand($item);
|
||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||
}
|
||||
|
@ -189,7 +189,7 @@ class SimpleInventoryTransaction implements InventoryTransaction{
|
||||
$sortedThisLoop = 0;
|
||||
foreach($list as $i => $action){
|
||||
$actionSource = $action->getSourceItem();
|
||||
if($actionSource->equals($lastTargetItem) and $actionSource->getCount() === $lastTargetItem->getCount()){
|
||||
if($actionSource->equalsExact($lastTargetItem)){
|
||||
$lastTargetItem = $action->getTargetItem();
|
||||
unset($list[$i]);
|
||||
$sortedThisLoop++;
|
||||
|
@ -75,7 +75,7 @@ class SlotChangeAction extends InventoryAction{
|
||||
*/
|
||||
public function isValid(Player $source) : bool{
|
||||
$check = $this->inventory->getItem($this->inventorySlot);
|
||||
return $check->equals($this->sourceItem) and $check->getCount() === $this->sourceItem->getCount();
|
||||
return $check->equalsExact($this->sourceItem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -883,6 +883,16 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the specified item stack has the same ID, damage, NBT and count as this item stack.
|
||||
* @param Item $other
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
final public function equalsExact(Item $other) : bool{
|
||||
return $this->equals($other, true, true) and $this->count === $other->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Item#equals} instead, this method will be removed in the future.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user