Fixed InventoryHelpersTrait::addItem() cannot add items with a count greater than maxstack (#4283)

This commit is contained in:
aieuo 2021-06-27 00:48:53 +09:00 committed by GitHub
parent 444d902990
commit a6039ad733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -186,7 +186,9 @@ trait InventoryHelpersTrait{
$item = clone $slot;
$item->setCount($amount);
$this->setItem($slotIndex, $item);
break;
if($slot->getCount() <= 0){
break;
}
}
}

View File

@ -85,4 +85,19 @@ class BaseInventoryTest extends TestCase{
}
self::assertSame(20, $leftoverCount);
}
public function testAddItemWithOversizedCount() : void{
$inventory = new class(10) extends SimpleInventory{
};
$leftover = $inventory->addItem(VanillaItems::APPLE()->setCount(100));
self::assertCount(0, $leftover);
$count = 0;
foreach($inventory->getContents() as $item){
self::assertTrue($item->equals(VanillaItems::APPLE()));
$count += $item->getCount();
}
self::assertSame(100, $count);
}
}