From 933a28537b39ae029dfe42d88de35218cfbd5549 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 25 May 2014 16:26:46 +0200 Subject: [PATCH] Fixed giving large amount of items, updated player inventory to correct size --- src/pocketmine/inventory/BaseInventory.php | 11 +++++++++++ src/pocketmine/inventory/InventoryType.php | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index fe698c2d6..3c527bb1c 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -205,6 +205,17 @@ abstract class BaseInventory implements Inventory{ public function addItem(){ /** @var Item[] $slots */ $slots = func_get_args(); + foreach($slots as $i => $slot){ + if($slot->getCount() > $slot->getMaxStackSize()){ + while($slot->getCount() > $slot->getMaxStackSize()){ + $slots[] = Item::get($slot->getID(), $slot->getDamage(), $slot->getMaxStackSize()); + $slot->setCount($slot->getCount() - $slot->getMaxStackSize()); + if(count($slots) > $this->getSize()){ //Protect against large give commands + break; + } + } + } + } for($i = 0; $i < $this->size; ++$i){ $item = $this->getItem($i); if($item->getID() === Item::AIR){ diff --git a/src/pocketmine/inventory/InventoryType.php b/src/pocketmine/inventory/InventoryType.php index 1cc07946a..b149b680f 100644 --- a/src/pocketmine/inventory/InventoryType.php +++ b/src/pocketmine/inventory/InventoryType.php @@ -55,7 +55,7 @@ class InventoryType{ static::$default[static::CHEST] = new InventoryType(27, "Chest", 0); static::$default[static::DOUBLE_CHEST] = new InventoryType(27 + 27, "Double Chest", 0); - static::$default[static::PLAYER] = new InventoryType(31, "Player", 0); //27 CONTAINER, 4 ARMOR (9 reference HOTBAR slots) + static::$default[static::PLAYER] = new InventoryType(40, "Player", 0); //27 CONTAINER, 4 ARMOR (9 reference HOTBAR slots) static::$default[static::FURNACE] = new InventoryType(3, "Furnace", 2); static::$default[static::CRAFTING] = new InventoryType(5, "Crafting", 1); //4 CRAFTING slots, 1 RESULT static::$default[static::WORKBENCH] = new InventoryType(10, "Crafting", 1); //9 CRAFTING slots, 1 RESULT