mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Beware matching items that aren't actually correct
This would only ever happen if we received the actions in the wrong order, but that wouldn't surprise me.
This commit is contained in:
@ -106,6 +106,9 @@ abstract class BaseInventory implements Inventory{
|
||||
return $this->slots[$index] !== null ? clone $this->slots[$index] : ItemFactory::get(Item::AIR, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getContents() : array{
|
||||
return array_filter($this->slots->toArray(), function(Item $item = null){ return $item !== null; });
|
||||
}
|
||||
@ -196,13 +199,13 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
}
|
||||
|
||||
public function first(Item $item) : int{
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
public function first(Item $item, bool $exact = false) : int{
|
||||
$count = $exact ? $item->getCount() : max(1, $item->getCount());
|
||||
$checkDamage = $exact || !$item->hasAnyDamageValue();
|
||||
$checkTags = $exact || $item->hasCompoundTag();
|
||||
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags) and $i->getCount() >= $count){
|
||||
if($item->equals($i, $checkDamage, $checkTags) and ($i->getCount() === $count or (!$exact and $i->getCount() > $count))){
|
||||
return $index;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user