mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Use -1 for anydamage and empty string for null NBT, closes #146
This commit is contained in:
@ -158,8 +158,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function contains(Item $item){
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
foreach($this->getContents() as $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags)){
|
||||
$count -= $i->getCount();
|
||||
@ -174,8 +174,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function all(Item $item){
|
||||
$slots = [];
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags)){
|
||||
$slots[$index] = $i;
|
||||
@ -186,8 +186,8 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
public function remove(Item $item){
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags)){
|
||||
@ -198,8 +198,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function first(Item $item){
|
||||
$count = max(1, $item->getCount());
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
|
||||
foreach($this->getContents() as $index => $i){
|
||||
if($item->equals($i, $checkDamage, $checkTags) and $i->getCount() >= $count){
|
||||
@ -222,8 +222,8 @@ abstract class BaseInventory implements Inventory{
|
||||
|
||||
public function canAddItem(Item $item){
|
||||
$item = clone $item;
|
||||
$checkDamage = $item->getDamage() === null ? false : true;
|
||||
$checkTags = $item->getCompoundTag() === null ? false : true;
|
||||
$checkDamage = !$item->hasAnyDamageValue();
|
||||
$checkTags = $item->hasCompoundTag();
|
||||
for($i = 0; $i < $this->getSize(); ++$i){
|
||||
$slot = $this->getItem($i);
|
||||
if($item->equals($slot, $checkDamage, $checkTags)){
|
||||
@ -322,7 +322,7 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
foreach($itemSlots as $index => $slot){
|
||||
if($slot->equals($item, $slot->getDamage() === null ? false : true, $slot->getCompoundTag() === null ? false : true)){
|
||||
if($slot->equals($item, !$slot->hasAnyDamageValue(), $slot->hasCompoundTag())){
|
||||
$amount = min($item->getCount(), $slot->getCount());
|
||||
$slot->setCount($slot->getCount() - $amount);
|
||||
$item->setCount($item->getCount() - $amount);
|
||||
|
Reference in New Issue
Block a user