PocketMine-MP
5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
SimpleInventory.php
1
<?php
2
3
/*
4
*
5
* ____ _ _ __ __ _ __ __ ____
6
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* @author PocketMine Team
17
* @link http://www.pocketmine.net/
18
*
19
*
20
*/
21
22
declare(strict_types=1);
23
24
namespace
pocketmine\inventory
;
25
26
use
pocketmine\item\Item
;
27
use
pocketmine\item\VanillaItems
;
28
32
class
SimpleInventory
extends
BaseInventory
{
37
protected \SplFixedArray $slots;
38
39
public
function
__construct(
int
$size){
40
$this->slots = new \SplFixedArray($size);
41
parent::__construct();
42
}
43
47
public
function
getSize
() : int{
48
return $this->slots->
getSize
();
49
}
50
51
public
function
getItem
(
int
$index) :
Item
{
52
return $this->slots[$index] !== null ? clone $this->slots[$index] :
VanillaItems
::AIR();
53
}
54
55
protected
function
internalSetItem(
int
$index,
Item
$item) : void{
56
$this->slots[$index] = $item->isNull() ? null : $item;
57
}
58
63
public
function
getContents
(
bool
$includeEmpty =
false
) : array{
64
$contents = [];
65
66
foreach
($this->slots as $i => $slot){
67
if
($slot !==
null
){
68
$contents[$i] = clone $slot;
69
}elseif($includeEmpty){
70
$contents[$i] = VanillaItems::AIR();
71
}
72
}
73
74
return
$contents;
75
}
76
77
protected
function
internalSetContents
(array $items) : void{
78
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
79
if
(!isset($items[$i]) || $items[$i]->isNull()){
80
$this->slots[$i] =
null
;
81
}
else
{
82
$this->slots[$i] = clone $items[$i];
83
}
84
}
85
}
86
87
protected
function
getMatchingItemCount
(
int
$slot,
Item
$test,
bool
$checkTags) : int{
88
$slotItem = $this->slots[$slot];
89
return
$slotItem !==
null
&& $slotItem->equals($test,
true
, $checkTags) ? $slotItem->getCount() : 0;
90
}
91
92
public
function
isSlotEmpty
(
int
$index) : bool{
93
return $this->slots[$index] === null || $this->slots[$index]->isNull();
94
}
95
}
pocketmine\inventory\BaseInventory
Definition
BaseInventory.php:42
pocketmine\inventory\SimpleInventory
Definition
SimpleInventory.php:32
pocketmine\inventory\SimpleInventory\internalSetContents
internalSetContents(array $items)
Definition
SimpleInventory.php:77
pocketmine\inventory\SimpleInventory\getContents
getContents(bool $includeEmpty=false)
Definition
SimpleInventory.php:63
pocketmine\inventory\SimpleInventory\isSlotEmpty
isSlotEmpty(int $index)
Definition
SimpleInventory.php:92
pocketmine\inventory\SimpleInventory\getMatchingItemCount
getMatchingItemCount(int $slot, Item $test, bool $checkTags)
Definition
SimpleInventory.php:87
pocketmine\inventory\SimpleInventory\getItem
getItem(int $index)
Definition
SimpleInventory.php:51
pocketmine\inventory\SimpleInventory\getSize
getSize()
Definition
SimpleInventory.php:47
pocketmine\item\Item
Definition
Item.php:60
pocketmine\item\VanillaItems
Definition
VanillaItems.php:340
pocketmine\inventory
Definition
ArmorInventory.php:24
src
inventory
SimpleInventory.php
Generated by
1.12.0