Fixed giving large amount of items, updated player inventory to correct size

This commit is contained in:
Shoghi Cervantes 2014-05-25 16:26:46 +02:00
parent 4f2856dc09
commit 933a28537b
2 changed files with 12 additions and 1 deletions

View File

@ -205,6 +205,17 @@ abstract class BaseInventory implements Inventory{
public function addItem(){ public function addItem(){
/** @var Item[] $slots */ /** @var Item[] $slots */
$slots = func_get_args(); $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){ for($i = 0; $i < $this->size; ++$i){
$item = $this->getItem($i); $item = $this->getItem($i);
if($item->getID() === Item::AIR){ if($item->getID() === Item::AIR){

View File

@ -55,7 +55,7 @@ class InventoryType{
static::$default[static::CHEST] = new InventoryType(27, "Chest", 0); static::$default[static::CHEST] = new InventoryType(27, "Chest", 0);
static::$default[static::DOUBLE_CHEST] = new InventoryType(27 + 27, "Double 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::FURNACE] = new InventoryType(3, "Furnace", 2);
static::$default[static::CRAFTING] = new InventoryType(5, "Crafting", 1); //4 CRAFTING slots, 1 RESULT 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 static::$default[static::WORKBENCH] = new InventoryType(10, "Crafting", 1); //9 CRAFTING slots, 1 RESULT