mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +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,9 +186,11 @@ trait InventoryHelpersTrait{
|
|||||||
$item = clone $slot;
|
$item = clone $slot;
|
||||||
$item->setCount($amount);
|
$item->setCount($amount);
|
||||||
$this->setItem($slotIndex, $item);
|
$this->setItem($slotIndex, $item);
|
||||||
|
if($slot->getCount() <= 0){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $slot;
|
return $slot;
|
||||||
}
|
}
|
||||||
|
@ -85,4 +85,19 @@ class BaseInventoryTest extends TestCase{
|
|||||||
}
|
}
|
||||||
self::assertSame(20, $leftoverCount);
|
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