mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Fixed InventoryHelpersTrait::addItem() cannot add items with a count greater than maxstack (#4283)
This commit is contained in:
parent
444d902990
commit
a6039ad733
@ -186,7 +186,9 @@ trait InventoryHelpersTrait{
|
||||
$item = clone $slot;
|
||||
$item->setCount($amount);
|
||||
$this->setItem($slotIndex, $item);
|
||||
break;
|
||||
if($slot->getCount() <= 0){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user