Added compound tag checking for Item->equals()

This commit is contained in:
Shoghi Cervantes
2015-08-06 20:25:22 +02:00
parent a65109ff34
commit 091d0b3ff9
7 changed files with 29 additions and 22 deletions

View File

@ -160,8 +160,9 @@ 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;
foreach($this->getContents() as $i){
if($item->equals($i, $checkDamage)){
if($item->equals($i, $checkDamage, $checkTags)){
$count -= $i->getCount();
if($count <= 0){
return true;
@ -175,8 +176,9 @@ abstract class BaseInventory implements Inventory{
public function all(Item $item){
$slots = [];
$checkDamage = $item->getDamage() === null ? false : true;
$checkTags = $item->getCompoundTag() === null ? false : true;
foreach($this->getContents() as $index => $i){
if($item->equals($i, $checkDamage)){
if($item->equals($i, $checkDamage, $checkTags)){
$slots[$index] = $i;
}
}
@ -186,8 +188,10 @@ abstract class BaseInventory implements Inventory{
public function remove(Item $item){
$checkDamage = $item->getDamage() === null ? false : true;
$checkTags = $item->getCompoundTag() === null ? false : true;
foreach($this->getContents() as $index => $i){
if($item->equals($i, $checkDamage)){
if($item->equals($i, $checkDamage, $checkTags)){
$this->clear($index);
}
}
@ -196,8 +200,10 @@ 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;
foreach($this->getContents() as $index => $i){
if($item->equals($i, $checkDamage) and $i->getCount() >= $count){
if($item->equals($i, $checkDamage, $checkTags) and $i->getCount() >= $count){
return $index;
}
}
@ -218,9 +224,10 @@ 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;
for($i = 0; $i < $this->getSize(); ++$i){
$slot = $this->getItem($i);
if($item->equals($slot, $checkDamage)){
if($item->equals($slot, $checkDamage, $checkTags)){
if(($diff = $slot->getMaxStackSize() - $slot->getCount()) > 0){
$item->setCount($item->getCount() - $diff);
}
@ -258,7 +265,7 @@ abstract class BaseInventory implements Inventory{
}
foreach($itemSlots as $index => $slot){
if($slot->equals($item, true) and $item->getCount() < $item->getMaxStackSize()){
if($slot->equals($item) and $item->getCount() < $item->getMaxStackSize()){
$amount = min($item->getMaxStackSize() - $item->getCount(), $slot->getCount(), $this->getMaxStackSize());
if($amount > 0){
$slot->setCount($slot->getCount() - $amount);
@ -316,7 +323,7 @@ abstract class BaseInventory implements Inventory{
}
foreach($itemSlots as $index => $slot){
if($slot->equals($item, $slot->getDamage() === null ? false : true)){
if($slot->equals($item, $slot->getDamage() === null ? false : true, $slot->getCompoundTag() === null ? false : true)){
$amount = min($item->getCount(), $slot->getCount());
$slot->setCount($slot->getCount() - $amount);
$item->setCount($item->getCount() - $amount);

View File

@ -443,7 +443,7 @@ class CraftingManager{
foreach($ingredients as $item){
$amount = $item->getCount();
foreach($checkInput as $k => $checkItem){
if($checkItem->equals($item, $checkItem->getDamage() === null ? false : true)){
if($checkItem->equals($item, $checkItem->getDamage() === null ? false : true, $checkItem->getCompoundTag() === null ? false : true)){
$remove = min($checkItem->getCount(), $amount);
$checkItem->setCount($checkItem->getCount() - $remove);
if($checkItem->getCount() === 0){
@ -506,7 +506,7 @@ class CraftingManager{
foreach($input as $item){
$amount = $item->getCount();
foreach($checkInput as $k => $checkItem){
if($checkItem->equals($item, $checkItem->getDamage() === null ? false : true)){
if($checkItem->equals($item, $checkItem->getDamage() === null ? false : true, $checkItem->getCompoundTag() === null ? false : true)){
$remove = min($checkItem->getCount(), $amount);
$checkItem->setCount($checkItem->getCount() - $remove);
if($checkItem->getCount() === 0){
@ -540,7 +540,7 @@ class CraftingManager{
}
$checkResult = $recipe->getResult();
if($checkResult->equals($result, true) and $checkResult->getCount() === $result->getCount()){
if($checkResult->equals($result) and $checkResult->getCount() === $result->getCount()){
return $recipe;
}

View File

@ -87,7 +87,7 @@ class ShapelessRecipe implements Recipe{
if($item->getCount() <= 0){
break;
}
if($ingredient->equals($item, $item->getDamage() === null ? false : true)){
if($ingredient->equals($item, $item->getDamage() === null ? false : true, $item->getCompoundTag() === null ? false : true)){
unset($this->ingredients[$index]);
$item->setCount($item->getCount() - 1);
}

View File

@ -98,7 +98,7 @@ class SimpleTransactionGroup implements TransactionGroup{
}
$checkSourceItem = $ts->getInventory()->getItem($ts->getSlot());
$sourceItem = $ts->getSourceItem();
if(!$checkSourceItem->equals($sourceItem, true) or $sourceItem->getCount() !== $checkSourceItem->getCount()){
if(!$checkSourceItem->equals($sourceItem) or $sourceItem->getCount() !== $checkSourceItem->getCount()){
return false;
}
if($sourceItem->getId() !== Item::AIR){
@ -108,7 +108,7 @@ class SimpleTransactionGroup implements TransactionGroup{
foreach($needItems as $i => $needItem){
foreach($haveItems as $j => $haveItem){
if($needItem->equals($haveItem, true)){
if($needItem->equals($haveItem)){
$amount = min($needItem->getCount(), $haveItem->getCount());
$needItem->setCount($needItem->getCount() - $amount);
$haveItem->setCount($haveItem->getCount() - $amount);