GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Chest Class Reference

Public Member Functions

 __construct (Level $level, CompoundTag $nbt)
 
 close ()
 
 saveNBT ()
 
 getSize ()
 
 getItem ($index)
 
 setItem ($index, Item $item)
 
 getInventory ()
 
 getRealInventory ()
 
 getDoubleInventory ()
 
 getName ()
 
 hasName ()
 
 setName ($str)
 
 isPaired ()
 
 getPair ()
 
 pairWith (Chest $tile)
 
 unpair ()
 
 getSpawnCompound ()
 
- Public Member Functions inherited from Spawnable
 spawnTo (Player $player)
 
 __construct (Level $level, CompoundTag $nbt)
 
 spawnToAll ()
 
 getSpawnCompound ()
 
 updateCompoundTag (CompoundTag $nbt, Player $player)
 
- Public Member Functions inherited from Tile
 getSaveId ()
 
 __construct (Level $level, CompoundTag $nbt)
 
 getId ()
 
 saveNBT ()
 
 getBlock ()
 
 onUpdate ()
 
 scheduleUpdate ()
 
 __destruct ()
 
 close ()
 
 getName ()
 
- Public Member Functions inherited from Position
 __construct ($x=0, $y=0, $z=0, Level $level=null)
 
 asPosition ()
 
 add ($x, $y=0, $z=0)
 
 getLevel ()
 
 setLevel (Level $level=null)
 
 isValid ()
 
 getSide ($side, $step=1)
 
 __toString ()
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
- Public Member Functions inherited from Vector3
 __construct ($x=0, $y=0, $z=0)
 
 getX ()
 
 getY ()
 
 getZ ()
 
 getFloorX ()
 
 getFloorY ()
 
 getFloorZ ()
 
 getRight ()
 
 getUp ()
 
 getForward ()
 
 getSouth ()
 
 getWest ()
 
 add ($x, $y=0, $z=0)
 
 subtract ($x=0, $y=0, $z=0)
 
 multiply ($number)
 
 divide ($number)
 
 ceil ()
 
 floor ()
 
 round ()
 
 abs ()
 
 getSide ($side, $step=1)
 
 asVector3 ()
 
 distance (Vector3 $pos)
 
 distanceSquared (Vector3 $pos)
 
 maxPlainDistance ($x=0, $z=0)
 
 length ()
 
 lengthSquared ()
 
 normalize ()
 
 dot (Vector3 $v)
 
 cross (Vector3 $v)
 
 equals (Vector3 $v)
 
 getIntermediateWithXValue (Vector3 $v, $x)
 
 getIntermediateWithYValue (Vector3 $v, $y)
 
 getIntermediateWithZValue (Vector3 $v, $z)
 
 setComponents ($x, $y, $z)
 
 fromObjectAdd (Vector3 $pos, $x, $y, $z)
 
 __toString ()
 

Protected Member Functions

 getSlotIndex ($index)
 
 checkPairing ()
 
- Protected Member Functions inherited from Spawnable
 onChanged ()
 

Protected Attributes

 $inventory
 
 $doubleInventory = null
 
- Protected Attributes inherited from Tile
 $lastUpdate
 
 $server
 
 $timings
 

Additional Inherited Members

- Static Public Member Functions inherited from Tile
static init ()
 
static createTile ($type, Level $level, CompoundTag $nbt,... $args)
 
static registerTile ($className)
 
- Static Public Member Functions inherited from Position
static fromObject (Vector3 $pos, Level $level=null)
 
- Static Public Member Functions inherited from Vector3
static getOppositeSide ($side)
 
static createRandomDirection (Random $random)
 
- Data Fields inherited from Tile
const BREWING_STAND = "BrewingStand"
 
const CHEST = "Chest"
 
const DL_DETECTOR = "DayLightDetector"
 
const ENCHANT_TABLE = "EnchantTable"
 
const FLOWER_POT = "FlowerPot"
 
const FURNACE = "Furnace"
 
const MOB_SPAWNER = "MobSpawner"
 
const SIGN = "Sign"
 
const SKULL = "Skull"
 
const ITEM_FRAME = "ItemFrame"
 
const DISPENSER = "Dispenser"
 
const DROPPER = "Dropper"
 
const CAULDRON = "Cauldron"
 
const HOPPER = "Hopper"
 
const BEACON = "Beacon"
 
const ENDER_CHEST = "EnderChest"
 
const BED = "Bed"
 
const DAY_LIGHT_DETECTOR = "DLDetector"
 
 $chunk
 
 $name
 
 $id
 
 $x
 
 $y
 
 $z
 
 $attach
 
 $metadata
 
 $closed = false
 
 $namedtag
 
 $tickTimer
 
- Data Fields inherited from Position
 $level = null
 
- Data Fields inherited from Vector3
const SIDE_DOWN = 0
 
const SIDE_UP = 1
 
const SIDE_NORTH = 2
 
const SIDE_SOUTH = 3
 
const SIDE_WEST = 4
 
const SIDE_EAST = 5
 
 $x
 
 $y
 
 $z
 
- Static Public Attributes inherited from Tile
static $tileCount = 1
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
CompoundTag  $nbt 
)

Chest constructor.

Parameters
Level$level
CompoundTag$nbt
49  {
50  parent::__construct($level, $nbt);
51  $this->inventory = new ChestInventory($this);
52  if(!isset($this->namedtag->Items) or !($this->namedtag->Items instanceof ListTag)){
53  $this->namedtag->Items = new ListTag("Items", []);
54  $this->namedtag->Items->setTagType(NBT::TAG_Compound);
55  }
56  for($i = 0; $i < $this->getSize(); ++$i){
57  $this->inventory->setItem($i, $this->getItem($i));
58  }
59  }

Member Function Documentation

◆ checkPairing()

checkPairing ( )
protected
173  {
174  if($this->isPaired() and !$this->getLevel()->isChunkLoaded($this->namedtag->pairx->getValue() >> 4, $this->namedtag->pairz->getValue() >> 4)){
175  //paired to a tile in an unloaded chunk
176  $this->doubleInventory = null;
177 
178  }elseif(($pair = $this->getPair()) instanceof Chest){
179  if(!$pair->isPaired()){
180  $pair->createPair($this);
181  $pair->checkPairing();
182  }
183  if($this->doubleInventory === null){
184  if(($p = $pair->getDoubleInventory()) instanceof DoubleChestInventory){
185  $this->doubleInventory = $p;
186  }else{
187  if(($pair->x + ($pair->z << 15)) > ($this->x + ($this->z << 15))){ //Order them correctly
188  $this->doubleInventory = new DoubleChestInventory($pair, $this);
189  }else{
190  $this->doubleInventory = new DoubleChestInventory($this, $pair);
191  }
192  }
193  }
194  }else{
195  $this->doubleInventory = null;
196  unset($this->namedtag->pairx, $this->namedtag->pairz);
197  }
198  }

◆ close()

close ( )
61  {
62  if($this->closed === false){
63  foreach($this->getInventory()->getViewers() as $player){
64  $player->removeWindow($this->getInventory());
65  }
66 
67  foreach($this->getInventory()->getViewers() as $player){
68  $player->removeWindow($this->getRealInventory());
69  }
70  parent::close();
71  }
72  }

◆ getDoubleInventory()

getDoubleInventory ( )
Returns
DoubleChestInventory|null
169  {
170  return $this->doubleInventory;
171  }

◆ getInventory()

getInventory ( )
Returns
ChestInventory|DoubleChestInventory

Implements InventoryHolder.

152  {
153  if($this->isPaired() and $this->doubleInventory === null){
154  $this->checkPairing();
155  }
156  return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory;
157  }

◆ getItem()

getItem (   $index)

This method should not be used by plugins, use the Inventory

Parameters
int$index
Returns
Item

Implements Container.

111  {
112  $i = $this->getSlotIndex($index);
113  if($i < 0){
114  return Item::get(Item::AIR, 0, 0);
115  }else{
116  return Item::nbtDeserialize($this->namedtag->Items[$i]);
117  }
118  }

◆ getName()

getName ( )
Returns
string

Implements Nameable.

203  : string{
204  return isset($this->namedtag->CustomName) ? $this->namedtag->CustomName->getValue() : "Chest";
205  }

◆ getPair()

getPair ( )
Returns
Chest
240  {
241  if($this->isPaired()){
242  $tile = $this->getLevel()->getTile(new Vector3((int) $this->namedtag["pairx"], $this->y, (int) $this->namedtag["pairz"]));
243  if($tile instanceof Chest){
244  return $tile;
245  }
246  }
247 
248  return null;
249  }

◆ getRealInventory()

getRealInventory ( )
Returns
ChestInventory
162  {
163  return $this->inventory;
164  }

◆ getSize()

getSize ( )
Returns
int

Implements Container.

85  {
86  return 27;
87  }

◆ getSlotIndex()

getSlotIndex (   $index)
protected
Parameters
$index
Returns
int
94  {
95  foreach($this->namedtag->Items as $i => $slot){
96  if((int) $slot["Slot"] === (int) $index){
97  return (int) $i;
98  }
99  }
100 
101  return -1;
102  }

◆ getSpawnCompound()

getSpawnCompound ( )
Returns
CompoundTag
307  {
308  if($this->isPaired()){
309  $c = new CompoundTag("", [
310  new StringTag("id", Tile::CHEST),
311  new IntTag("x", (int) $this->x),
312  new IntTag("y", (int) $this->y),
313  new IntTag("z", (int) $this->z),
314  new IntTag("pairx", (int) $this->namedtag["pairx"]),
315  new IntTag("pairz", (int) $this->namedtag["pairz"])
316  ]);
317  }else{
318  $c = new CompoundTag("", [
319  new StringTag("id", Tile::CHEST),
320  new IntTag("x", (int) $this->x),
321  new IntTag("y", (int) $this->y),
322  new IntTag("z", (int) $this->z)
323  ]);
324  }
325 
326  if($this->hasName()){
327  $c->CustomName = $this->namedtag->CustomName;
328  }
329 
330  return $c;
331  }

◆ hasName()

hasName ( )
Returns
bool

Implements Nameable.

210  {
211  return isset($this->namedtag->CustomName);
212  }

◆ isPaired()

isPaired ( )
Returns
bool
229  {
230  if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){
231  return false;
232  }
233 
234  return true;
235  }

◆ pairWith()

pairWith ( Chest  $tile)
Parameters
Chest$tile
Returns
bool
256  {
257  if($this->isPaired() or $tile->isPaired()){
258  return false;
259  }
260 
261  $this->createPair($tile);
262 
263  $this->spawnToAll();
264  $tile->spawnToAll();
265  $this->checkPairing();
266 
267  return true;
268  }

◆ saveNBT()

saveNBT ( )
74  {
75  $this->namedtag->Items = new ListTag("Items", []);
76  $this->namedtag->Items->setTagType(NBT::TAG_Compound);
77  for($index = 0; $index < $this->getSize(); ++$index){
78  $this->setItem($index, $this->inventory->getItem($index));
79  }
80  }

◆ setItem()

setItem (   $index,
Item  $item 
)

This method should not be used by plugins, use the Inventory

Parameters
int$index
Item$item
Returns
bool

Implements Container.

128  {
129  $i = $this->getSlotIndex($index);
130 
131  if($item->getId() === Item::AIR or $item->getCount() <= 0){
132  if($i >= 0){
133  unset($this->namedtag->Items[$i]);
134  }
135  }elseif($i < 0){
136  for($i = 0; $i <= $this->getSize(); ++$i){
137  if(!isset($this->namedtag->Items[$i])){
138  break;
139  }
140  }
141  $this->namedtag->Items[$i] = $item->nbtSerialize($index);
142  }else{
143  $this->namedtag->Items[$i] = $item->nbtSerialize($index);
144  }
145 
146  return true;
147  }

◆ setName()

setName (   $str)
Parameters
void$str

Implements Nameable.

217  {
218  if($str === ""){
219  unset($this->namedtag->CustomName);
220  return;
221  }
222 
223  $this->namedtag->CustomName = new StringTag("CustomName", $str);
224  }

◆ unpair()

unpair ( )
Returns
bool
284  {
285  if(!$this->isPaired()){
286  return false;
287  }
288 
289  $tile = $this->getPair();
290  unset($this->namedtag->pairx, $this->namedtag->pairz);
291 
292  $this->spawnToAll();
293 
294  if($tile instanceof Chest){
295  unset($tile->namedtag->pairx, $tile->namedtag->pairz);
296  $tile->checkPairing();
297  $tile->spawnToAll();
298  }
299  $this->checkPairing();
300 
301  return true;
302  }

Field Documentation

◆ $doubleInventory

$doubleInventory = null
protected

◆ $inventory

$inventory
protected

The documentation for this class was generated from the following file: