Inventory: remove redundant return values

This commit is contained in:
Dylan K. Taylor 2019-05-20 16:30:00 +01:00
parent c21a25efb9
commit d6ce3f82b1
7 changed files with 29 additions and 58 deletions

View File

@ -60,19 +60,19 @@ class ArmorInventory extends BaseInventory{
return $this->getItem(self::SLOT_FEET); return $this->getItem(self::SLOT_FEET);
} }
public function setHelmet(Item $helmet) : bool{ public function setHelmet(Item $helmet) : void{
return $this->setItem(self::SLOT_HEAD, $helmet); $this->setItem(self::SLOT_HEAD, $helmet);
} }
public function setChestplate(Item $chestplate) : bool{ public function setChestplate(Item $chestplate) : void{
return $this->setItem(self::SLOT_CHEST, $chestplate); $this->setItem(self::SLOT_CHEST, $chestplate);
} }
public function setLeggings(Item $leggings) : bool{ public function setLeggings(Item $leggings) : void{
return $this->setItem(self::SLOT_LEGS, $leggings); $this->setItem(self::SLOT_LEGS, $leggings);
} }
public function setBoots(Item $boots) : bool{ public function setBoots(Item $boots) : void{
return $this->setItem(self::SLOT_FEET, $boots); $this->setItem(self::SLOT_FEET, $boots);
} }
} }

View File

@ -117,9 +117,7 @@ abstract class BaseInventory implements Inventory{
$this->clear($i, false); $this->clear($i, false);
} }
}else{ }else{
if(!$this->setItem($i, $items[$i], false)){ $this->setItem($i, $items[$i], false);
$this->clear($i, false);
}
} }
} }
@ -134,7 +132,7 @@ abstract class BaseInventory implements Inventory{
} }
} }
public function setItem(int $index, Item $item, bool $send = true) : bool{ public function setItem(int $index, Item $item, bool $send = true) : void{
if($item->isNull()){ if($item->isNull()){
$item = ItemFactory::air(); $item = ItemFactory::air();
}else{ }else{
@ -145,8 +143,6 @@ abstract class BaseInventory implements Inventory{
$this->slots[$index] = $item->isNull() ? null : $item; $this->slots[$index] = $item->isNull() ? null : $item;
$this->onSlotChange($index, $oldItem, $send); $this->onSlotChange($index, $oldItem, $send);
return true;
} }
public function contains(Item $item) : bool{ public function contains(Item $item) : bool{
@ -330,8 +326,8 @@ abstract class BaseInventory implements Inventory{
return $itemSlots; return $itemSlots;
} }
public function clear(int $index, bool $send = true) : bool{ public function clear(int $index, bool $send = true) : void{
return $this->setItem($index, ItemFactory::air(), $send); $this->setItem($index, ItemFactory::air(), $send);
} }
public function clearAll(bool $send = true) : void{ public function clearAll(bool $send = true) : void{

View File

@ -61,14 +61,9 @@ class CraftingGrid extends BaseInventory{
throw new \BadMethodCallException("Cannot change the size of a crafting grid"); throw new \BadMethodCallException("Cannot change the size of a crafting grid");
} }
public function setItem(int $index, Item $item, bool $send = true) : bool{ public function setItem(int $index, Item $item, bool $send = true) : void{
if(parent::setItem($index, $item, $send)){ parent::setItem($index, $item, $send);
$this->seekRecipeBounds(); $this->seekRecipeBounds();
return true;
}
return false;
} }
/** /**

View File

@ -58,13 +58,10 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->left->getSize()); return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->left->getSize());
} }
public function setItem(int $index, Item $item, bool $send = true) : bool{ public function setItem(int $index, Item $item, bool $send = true) : void{
$old = $this->getItem($index); $old = $this->getItem($index);
if($index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send)){ $index < $this->left->getSize() ? $this->left->setItem($index, $item, $send) : $this->right->setItem($index - $this->left->getSize(), $item, $send);
$this->onSlotChange($index, $old, $send); $this->onSlotChange($index, $old, $send);
return true;
}
return false;
} }
public function getContents(bool $includeEmpty = false) : array{ public function getContents(bool $includeEmpty = false) : array{

View File

@ -70,28 +70,22 @@ class FurnaceInventory extends ContainerInventory{
/** /**
* @param Item $item * @param Item $item
*
* @return bool
*/ */
public function setResult(Item $item) : bool{ public function setResult(Item $item) : void{
return $this->setItem(2, $item); $this->setItem(2, $item);
} }
/** /**
* @param Item $item * @param Item $item
*
* @return bool
*/ */
public function setFuel(Item $item) : bool{ public function setFuel(Item $item) : void{
return $this->setItem(1, $item); $this->setItem(1, $item);
} }
/** /**
* @param Item $item * @param Item $item
*
* @return bool
*/ */
public function setSmelting(Item $item) : bool{ public function setSmelting(Item $item) : void{
return $this->setItem(0, $item); $this->setItem(0, $item);
} }
} }

View File

@ -56,15 +56,12 @@ interface Inventory{
/** /**
* Puts an Item in a slot. * Puts an Item in a slot.
* If a plugin refuses the update or $index is invalid, it'll return false
* *
* @param int $index * @param int $index
* @param Item $item * @param Item $item
* @param bool $send * @param bool $send
*
* @return bool
*/ */
public function setItem(int $index, Item $item, bool $send = true) : bool; public function setItem(int $index, Item $item, bool $send = true) : void;
/** /**
* Stores the given Items in the inventory. This will try to fill * Stores the given Items in the inventory. This will try to fill
@ -182,10 +179,8 @@ interface Inventory{
* *
* @param int $index * @param int $index
* @param bool $send * @param bool $send
*
* @return bool
*/ */
public function clear(int $index, bool $send = true) : bool; public function clear(int $index, bool $send = true) : void;
/** /**
* Clears all the slots * Clears all the slots

View File

@ -119,16 +119,10 @@ class PlayerInventory extends BaseInventory{
* Sets the item in the currently-held slot to the specified item. * Sets the item in the currently-held slot to the specified item.
* *
* @param Item $item * @param Item $item
*
* @return bool
*/ */
public function setItemInHand(Item $item) : bool{ public function setItemInHand(Item $item) : void{
if($this->setItem($this->getHeldItemIndex(), $item)){ $this->setItem($this->getHeldItemIndex(), $item);
$this->sendHeldItem($this->holder->getViewers()); $this->sendHeldItem($this->holder->getViewers());
return true;
}
return false;
} }
/** /**