mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
DoubleChestInventory: remove duplicated code
This commit is contained in:
parent
685f5d562b
commit
32e03cd92d
@ -113,9 +113,7 @@ abstract class BaseInventory implements Inventory{
|
|||||||
|
|
||||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||||
if(!isset($items[$i])){
|
if(!isset($items[$i])){
|
||||||
if($this->slots[$i] !== null){
|
|
||||||
$this->clear($i, false);
|
$this->clear($i, false);
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
$this->setItem($i, $items[$i], false);
|
$this->setItem($i, $items[$i], false);
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ use pocketmine\block\tile\Chest;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_slice;
|
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||||
@ -75,29 +74,6 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Item[] $items
|
|
||||||
* @param bool $send
|
|
||||||
*/
|
|
||||||
public function setContents(array $items, bool $send = true) : void{
|
|
||||||
$size = $this->getSize();
|
|
||||||
if(count($items) > $size){
|
|
||||||
$items = array_slice($items, 0, $size, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
for($i = 0; $i < $size; ++$i){
|
|
||||||
if(!isset($items[$i])){
|
|
||||||
$this->clear($i, false);
|
|
||||||
}else{
|
|
||||||
$this->setItem($i, $items[$i], false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($send){
|
|
||||||
$this->sendContents($this->getViewers());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function onOpen(Player $who) : void{
|
protected function onOpen(Player $who) : void{
|
||||||
parent::onOpen($who);
|
parent::onOpen($who);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user