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

Public Member Functions

 __construct (int $chunkX, int $chunkZ, array $subChunks=[], array $entities=[], array $tiles=[], string $biomeIds="", array $heightMap=[])
 
 getX ()
 
 getZ ()
 
 setX (int $x)
 
 setZ (int $z)
 
 getHeight ()
 
 getFullBlock (int $x, int $y, int $z)
 
 setBlock (int $x, int $y, int $z, $blockId=null, $meta=null)
 
 getBlockId (int $x, int $y, int $z)
 
 setBlockId (int $x, int $y, int $z, int $id)
 
 getBlockData (int $x, int $y, int $z)
 
 setBlockData (int $x, int $y, int $z, int $data)
 
 getBlockExtraData (int $x, int $y, int $z)
 
 setBlockExtraData (int $x, int $y, int $z, int $data)
 
 getBlockSkyLight (int $x, int $y, int $z)
 
 setBlockSkyLight (int $x, int $y, int $z, int $level)
 
 getBlockLight (int $x, int $y, int $z)
 
 setBlockLight (int $x, int $y, int $z, int $level)
 
 getHighestBlockAt (int $x, int $z)
 
 getHeightMap (int $x, int $z)
 
 setHeightMap (int $x, int $z, int $value)
 
 recalculateHeightMap ()
 
 recalculateHeightMapColumn (int $x, int $z)
 
 populateSkyLight ()
 
 getBiomeId (int $x, int $z)
 
 setBiomeId (int $x, int $z, int $biomeId)
 
 getBlockIdColumn (int $x, int $z)
 
 getBlockDataColumn (int $x, int $z)
 
 getBlockSkyLightColumn (int $x, int $z)
 
 getBlockLightColumn (int $x, int $z)
 
 isLightPopulated ()
 
 setLightPopulated (bool $value=true)
 
 isPopulated ()
 
 setPopulated (bool $value=true)
 
 isGenerated ()
 
 setGenerated (bool $value=true)
 
 addEntity (Entity $entity)
 
 removeEntity (Entity $entity)
 
 addTile (Tile $tile)
 
 removeTile (Tile $tile)
 
 getEntities ()
 
 getTiles ()
 
 getTile (int $x, int $y, int $z)
 
 unload (bool $safe=true)
 
 initChunk (Level $level)
 
 getBiomeIdArray ()
 
 getHeightMapArray ()
 
 getBlockExtraDataArray ()
 
 hasChanged ()
 
 setChanged (bool $value=true)
 
 getSubChunk (int $y, bool $generateNew=false)
 
 setSubChunk (int $y, SubChunk $subChunk=null, bool $allowEmpty=false)
 
 getSubChunks ()
 
 getHighestSubChunkIndex ()
 
 getSubChunkSendCount ()
 
 pruneEmptySubChunks ()
 
 networkSerialize ()
 
 fastSerialize ()
 

Static Public Member Functions

static fastDeserialize (string $data)
 
static getEmptyChunk (int $x, int $z)
 
static chunkBlockHash (int $x, int $y, int $z)
 

Data Fields

const MAX_SUBCHUNKS = 16
 

Protected Attributes

 $x
 
 $z
 
 $hasChanged = false
 
 $isInit = false
 
 $lightPopulated = false
 
 $terrainGenerated = false
 
 $terrainPopulated = false
 
 $height = Chunk::MAX_SUBCHUNKS
 
 $subChunks = []
 
 $emptySubChunk = null
 
 $tiles = []
 
 $tileList = []
 
 $entities = []
 
 $heightMap = []
 
 $biomeIds
 
 $extraData = []
 
 $NBTtiles = []
 
 $NBTentities = []
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( int  $chunkX,
int  $chunkZ,
array  $subChunks = [],
array  $entities = [],
array  $tiles = [],
string  $biomeIds = "",
array  $heightMap = [] 
)
Parameters
int$chunkX
int$chunkZ
SubChunk[]$subChunks
CompoundTag[]$entities
CompoundTag[]$tiles
string$biomeIds
int[]$heightMap
93  {
94  $this->x = $chunkX;
95  $this->z = $chunkZ;
96 
97  $this->height = Chunk::MAX_SUBCHUNKS; //TODO: add a way of changing this
98 
99  $this->emptySubChunk = new EmptySubChunk();
100 
101  foreach($subChunks as $y => $subChunk){
102  if($y < 0 or $y >= $this->height){
103  throw new ChunkException("Invalid subchunk index $y!");
104  }
105  if($subChunk->isEmpty()){
106  $this->subChunks[$y] = $this->emptySubChunk;
107  }else{
108  $this->subChunks[$y] = $subChunk;
109  }
110  }
111 
112  for($i = 0; $i < $this->height; ++$i){
113  if(!isset($this->subChunks[$i])){
114  $this->subChunks[$i] = $this->emptySubChunk;
115  }
116  }
117 
118  if(count($heightMap) === 256){
119  $this->heightMap = $heightMap;
120  }else{
121  assert(count($heightMap) === 0, "Wrong HeightMap value count, expected 256, got " . count($heightMap));
122  $val = ($this->height * 16);
123  $this->heightMap = array_fill(0, 256, $val);
124  }
125 
126  if(strlen($biomeIds) === 256){
127  $this->biomeIds = $biomeIds;
128  }else{
129  assert(strlen($biomeIds) === 0, "Wrong BiomeIds value count, expected 256, got " . strlen($biomeIds));
130  $this->biomeIds = str_repeat("\x00", 256);
131  }
132 
133  $this->NBTtiles = $tiles;
134  $this->NBTentities = $entities;
135  }

Member Function Documentation

◆ addEntity()

addEntity ( Entity  $entity)
Parameters
Entity$entity
575  {
576  $this->entities[$entity->getId()] = $entity;
577  if(!($entity instanceof Player) and $this->isInit){
578  $this->hasChanged = true;
579  }
580  }

◆ addTile()

addTile ( Tile  $tile)
Parameters
Tile$tile
595  {
596  $this->tiles[$tile->getId()] = $tile;
597  if(isset($this->tileList[$index = (($tile->x & 0x0f) << 12) | (($tile->z & 0x0f) << 8) | ($tile->y & 0xff)]) and $this->tileList[$index] !== $tile){
598  $this->tileList[$index]->close();
599  }
600  $this->tileList[$index] = $tile;
601  if($this->isInit){
602  $this->hasChanged = true;
603  }
604  }

◆ chunkBlockHash()

static chunkBlockHash ( int  $x,
int  $y,
int  $z 
)
static

Creates a block hash from chunk block coordinates. Used for extra data keys in chunk packets.

976  : int{
977  return ($x << 12) | ($z << 8) | $y;
978  }

◆ fastDeserialize()

static fastDeserialize ( string  $data)
static

Deserializes a fast-serialized chunk

Parameters
string$data
Returns
Chunk
939  {
940  $stream = new BinaryStream();
941  $stream->setBuffer($data);
942  $data = null;
943  $x = $stream->getInt();
944  $z = $stream->getInt();
945  $subChunks = [];
946  $count = $stream->getByte();
947  for($y = 0; $y < $count; ++$y){
948  $subChunks[$stream->getByte()] = SubChunk::fastDeserialize($stream->get(10240));
949  }
950  $heightMap = array_values(unpack("v*", $stream->get(512)));
951  $biomeIds = $stream->get(256);
952 
953  $chunk = new Chunk($x, $z, $subChunks, [], [], $biomeIds, $heightMap);
954  $flags = $stream->getByte();
955  $chunk->lightPopulated = (bool) ($flags & 4);
956  $chunk->terrainPopulated = (bool) ($flags & 2);
957  $chunk->terrainGenerated = (bool) ($flags & 1);
958  return $chunk;
959  }

◆ fastSerialize()

fastSerialize ( )

Fast-serializes the chunk for passing between threads TODO: tiles and entities

Returns
string
911  : string{
912  $stream = new BinaryStream();
913  $stream->putInt($this->x);
914  $stream->putInt($this->z);
915  $count = 0;
916  $subChunks = "";
917  foreach($this->subChunks as $y => $subChunk){
918  if($subChunk instanceof EmptySubChunk){
919  continue;
920  }
921  ++$count;
922  $subChunks .= chr($y) . $subChunk->fastSerialize();
923  }
924  $stream->putByte($count);
925  $stream->put($subChunks);
926  $stream->put(pack("v*", ...$this->heightMap) .
927  $this->biomeIds .
928  chr(($this->lightPopulated ? 4 : 0) | ($this->terrainPopulated ? 2 : 0) | ($this->terrainGenerated ? 1 : 0)));
929  return $stream->getBuffer();
930  }

◆ getBiomeId()

getBiomeId ( int  $x,
int  $z 
)

Returns the biome ID at the specified X/Z chunk block coordinates

Parameters
int$x0-15
int$z0-15
Returns
int 0-255
454  : int{
455  return ord($this->biomeIds{($z << 4) | $x});
456  }

◆ getBiomeIdArray()

getBiomeIdArray ( )
Returns
string
742  : string{
743  return $this->biomeIds;
744  }

◆ getBlockData()

getBlockData ( int  $x,
int  $y,
int  $z 
)

Returns the block meta value at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
Returns
int 0-15
239  : int{
240  return $this->getSubChunk($y >> 4)->getBlockData($x, $y & 0x0f, $z);
241  }

◆ getBlockDataColumn()

getBlockDataColumn ( int  $x,
int  $z 
)

Returns a column of block meta values from bottom to top at the specified X/Z chunk block coordinates.

Parameters
int$x0-15
int$z0-15
Returns
string
492  : string{
493  $result = "";
494  foreach($this->subChunks as $subChunk){
495  $result .= $subChunk->getBlockDataColumn($x, $z);
496  }
497  return $result;
498  }

◆ getBlockExtraData()

getBlockExtraData ( int  $x,
int  $y,
int  $z 
)

Returns the raw block extra data value at the specified chunk block coordinates, or 0 if no data exists

Parameters
int$x0-15
int$y
int$z0-15
Returns
int bitmap, (meta << 8) | id
266  : int{
267  return $this->extraData[Chunk::chunkBlockHash($x, $y, $z)] ?? 0;
268  }

◆ getBlockExtraDataArray()

getBlockExtraDataArray ( )
Returns
int[]
756  : array{
757  return $this->extraData;
758  }

◆ getBlockId()

getBlockId ( int  $x,
int  $y,
int  $z 
)

Returns the block ID at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
Returns
int 0-255
212  : int{
213  return $this->getSubChunk($y >> 4)->getBlockId($x, $y & 0x0f, $z);
214  }

◆ getBlockIdColumn()

getBlockIdColumn ( int  $x,
int  $z 
)

Returns a column of block IDs from bottom to top at the specified X/Z chunk block coordinates.

Parameters
int$x0-15
int$z0-15
Returns
string
477  : string{
478  $result = "";
479  foreach($this->subChunks as $subChunk){
480  $result .= $subChunk->getBlockIdColumn($x, $z);
481  }
482  return $result;
483  }

◆ getBlockLight()

getBlockLight ( int  $x,
int  $y,
int  $z 
)

Returns the block light level at the specified chunk block coordinates

Parameters
int$x0-15
int$y0-15
int$z0-15
Returns
int 0-15
324  : int{
325  return $this->getSubChunk($y >> 4)->getBlockLight($x, $y & 0x0f, $z);
326  }

◆ getBlockLightColumn()

getBlockLightColumn ( int  $x,
int  $z 
)

Returns a column of block light values from bottom to top at the specified X/Z chunk block coordinates.

Parameters
int$x0-15
int$z0-15
Returns
string
522  : string{
523  $result = "";
524  foreach($this->subChunks as $subChunk){
525  $result .= $subChunk->getBlockLightColumn($x, $z);
526  }
527  return $result;
528  }

◆ getBlockSkyLight()

getBlockSkyLight ( int  $x,
int  $y,
int  $z 
)

Returns the sky light level at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
Returns
int 0-15
297  : int{
298  return $this->getSubChunk($y >> 4)->getBlockSkyLight($x, $y & 0x0f, $z);
299  }

◆ getBlockSkyLightColumn()

getBlockSkyLightColumn ( int  $x,
int  $z 
)

Returns a column of sky light values from bottom to top at the specified X/Z chunk block coordinates.

Parameters
int$x0-15
int$z0-15
Returns
string
507  : string{
508  $result = "";
509  foreach($this->subChunks as $subChunk){
510  $result .= $subChunk->getSkyLightColumn($x, $z);
511  }
512  return $result;
513  }

◆ getEmptyChunk()

static getEmptyChunk ( int  $x,
int  $z 
)
static
962  : Chunk{
963  return new Chunk($x, $z);
964  }

◆ getEntities()

getEntities ( )

Returns an array of entities currently using this chunk.

Returns
Entity[]
622  : array{
623  return $this->entities;
624  }

◆ getFullBlock()

getFullBlock ( int  $x,
int  $y,
int  $z 
)

Returns a bitmap of block ID and meta at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
Returns
int bitmap, (id << 4) | meta
180  : int{
181  return $this->getSubChunk($y >> 4)->getFullBlock($x, $y & 0x0f, $z);
182  }

◆ getHeight()

getHeight ( )

Returns the chunk height in count of subchunks.

Returns
int
167  : int{
168  return $this->height;
169  }

◆ getHeightMap()

getHeightMap ( int  $x,
int  $z 
)

Returns the heightmap value at the specified X/Z chunk block coordinates

Parameters
int$x0-15
int$z0-15
Returns
int
373  : int{
374  return $this->heightMap[($z << 4) | $x];
375  }

◆ getHeightMapArray()

getHeightMapArray ( )
Returns
int[]
749  : array{
750  return $this->heightMap;
751  }

◆ getHighestBlockAt()

getHighestBlockAt ( int  $x,
int  $z 
)

Returns the Y coordinate of the highest non-air block at the specified X/Z chunk block coordinates

Parameters
int$x0-15
int$z0-15
Returns
int 0-255, or -1 if there are no blocks in the column
350  : int{
351  $index = $this->getHighestSubChunkIndex();
352  if($index === -1){
353  return -1;
354  }
355  $height = $index << 4;
356  for($y = $index; $y >= 0; --$y){
357  $height = $this->getSubChunk($y)->getHighestBlockAt($x, $z) | ($y << 4);
358  if($height !== -1){
359  return $height;
360  }
361  }
362  return -1;
363  }

◆ getHighestSubChunkIndex()

getHighestSubChunkIndex ( )

Returns the Y coordinate of the highest non-empty subchunk in this chunk.

Returns
int
825  : int{
826  for($y = count($this->subChunks) - 1; $y >= 0; --$y){
827  if($this->subChunks[$y] === null or $this->subChunks[$y] instanceof EmptySubChunk){
828  //No need to thoroughly prune empties at runtime, this will just reduce performance.
829  continue;
830  }
831  break;
832  }
833 
834  return $y;
835  }

◆ getSubChunk()

getSubChunk ( int  $y,
bool  $generateNew = false 
)

Returns the subchunk at the specified subchunk Y coordinate, or an empty, unmodifiable stub if it does not exist or the coordinate is out of range.

Parameters
int$y
bool$generateNewWhether to create a new, modifiable subchunk if there is not one in place
Returns
SubChunk|EmptySubChunk
782  : SubChunk{
783  if($y < 0 or $y >= $this->height){
784  return $this->emptySubChunk;
785  }elseif($generateNew and $this->subChunks[$y] instanceof EmptySubChunk){
786  $this->subChunks[$y] = new SubChunk();
787  }
788  assert($this->subChunks[$y] !== null, "Somehow something broke, no such subchunk at index $y");
789  return $this->subChunks[$y];
790  }

◆ getSubChunks()

getSubChunks ( )
Returns
SubChunk[]
816  : array{
817  return $this->subChunks;
818  }

◆ getSubChunkSendCount()

getSubChunkSendCount ( )

Returns the count of subchunks that need sending to players

Returns
int
842  : int{
843  return $this->getHighestSubChunkIndex() + 1;
844  }

◆ getTile()

getTile ( int  $x,
int  $y,
int  $z 
)

Returns the tile at the specified chunk block coordinates, or null if no tile exists.

Parameters
int$x0-15
int$y
int$z0-15
Returns
Tile|null
642  {
643  $index = ($x << 12) | ($z << 8) | $y;
644  return $this->tileList[$index] ?? null;
645  }

◆ getTiles()

getTiles ( )
Returns
Tile[]
629  : array{
630  return $this->tiles;
631  }

◆ getX()

getX ( )
Returns
int
140  : int{
141  return $this->x;
142  }

◆ getZ()

getZ ( )
Returns
int
147  : int{
148  return $this->z;
149  }

◆ hasChanged()

hasChanged ( )
Returns
bool
763  : bool{
764  return $this->hasChanged;
765  }

◆ initChunk()

initChunk ( Level  $level)

Deserializes tiles and entities from NBT

Parameters
Level$level
682  {
683  if(!$this->isInit){
684  $changed = false;
685  if($this->NBTentities !== null){
686  $level->timings->syncChunkLoadEntitiesTimer->startTiming();
687  foreach($this->NBTentities as $nbt){
688  if($nbt instanceof CompoundTag){
689  if(!isset($nbt->id)){
690  $changed = true;
691  continue;
692  }
693 
694  if(($nbt["Pos"][0] >> 4) !== $this->x or ($nbt["Pos"][2] >> 4) !== $this->z){
695  $changed = true;
696  continue; //Fixes entities allocated in wrong chunks.
697  }
698 
699  if(!(($entity = Entity::createEntity($nbt["id"], $level, $nbt)) instanceof Entity)){
700  $changed = true;
701  continue;
702  }
703  }
704  }
705  $level->timings->syncChunkLoadEntitiesTimer->stopTiming();
706 
707  $level->timings->syncChunkLoadTileEntitiesTimer->startTiming();
708  foreach($this->NBTtiles as $nbt){
709  if($nbt instanceof CompoundTag){
710  if(!isset($nbt->id)){
711  $changed = true;
712  continue;
713  }
714 
715  if(($nbt["x"] >> 4) !== $this->x or ($nbt["z"] >> 4) !== $this->z){
716  $changed = true;
717  continue; //Fixes tiles allocated in wrong chunks.
718  }
719 
720  if(Tile::createTile($nbt["id"], $level, $nbt) === null){
721  $changed = true;
722  continue;
723  }
724  }
725  }
726 
727  $level->timings->syncChunkLoadTileEntitiesTimer->stopTiming();
728 
729  $this->NBTentities = null;
730  $this->NBTtiles = null;
731  }
732 
733  $this->hasChanged = $changed;
734 
735  $this->isInit = true;
736  }
737  }

◆ isGenerated()

isGenerated ( )
Returns
bool
561  : bool{
563  }

◆ isLightPopulated()

isLightPopulated ( )
Returns
bool
533  : bool{
534  return $this->lightPopulated;
535  }

◆ isPopulated()

isPopulated ( )
Returns
bool
547  : bool{
549  }

◆ networkSerialize()

networkSerialize ( )

Serializes the chunk for sending to players

Returns
string
870  : string{
871  $result = "";
872  $subChunkCount = $this->getSubChunkSendCount();
873  $result .= chr($subChunkCount);
874  for($y = 0; $y < $subChunkCount; ++$y){
875  $result .= $this->subChunks[$y]->networkSerialize();
876  }
877  $result .= pack("v*", ...$this->heightMap)
878  . $this->biomeIds
879  . chr(0); //border block array count
880  //Border block entry format: 1 byte (4 bits X, 4 bits Z). These are however useless since they crash the regular client.
881 
882  $extraData = new BinaryStream();
883  $extraData->putVarInt(count($this->extraData)); //WHY, Mojang, WHY
884  foreach($this->extraData as $key => $value){
885  $extraData->putVarInt($key);
886  $extraData->putLShort($value);
887  }
888  $result .= $extraData->getBuffer();
889 
890  if(count($this->tiles) > 0){
891  $nbt = new NBT(NBT::LITTLE_ENDIAN);
892  $list = [];
893  foreach($this->tiles as $tile){
894  if($tile instanceof Spawnable){
895  $list[] = $tile->getSpawnCompound();
896  }
897  }
898  $nbt->setData($list);
899  $result .= $nbt->write(true);
900  }
901 
902  return $result;
903  }

◆ populateSkyLight()

populateSkyLight ( )

Performs basic sky light population on the chunk. This does not cater for adjacent sky light, this performs direct sky light population only. This may cause some strange visual artifacts if the chunk is light-populated after being terrain-populated.

TODO: fast adjacent light spread

424  {
425  for($x = 0; $x < 16; ++$x){
426  for($z = 0; $z < 16; ++$z){
427  $heightMap = $this->getHeightMap($x, $z);
428  $y = ($this->getHighestSubChunkIndex() + 1) << 4;
429  for(; $y >= $heightMap; --$y){
430  $this->setBlockSkyLight($x, $y, $z, 15);
431  }
432  $light = 15;
433  for(; $y > 0; --$y){
434  if($light > 0){
435  $light -= Block::$lightFilter[$this->getBlockId($x, $y, $z)];
436  if($light < 0){
437  $light = 0;
438  }
439  }
440  $this->setBlockSkyLight($x, $y, $z, $light);
441  }
442  }
443  }
444  }

◆ pruneEmptySubChunks()

pruneEmptySubChunks ( )

Disposes of empty subchunks

849  {
850  foreach($this->subChunks as $y => $subChunk){
851  if($y < 0 or $y >= $this->height){
852  assert(false, "Invalid subchunk index");
853  unset($this->subChunks[$y]);
854  }elseif($subChunk instanceof EmptySubChunk){
855  continue;
856  }elseif($subChunk->isEmpty()){ //normal subchunk full of air, remove it and replace it with an empty stub
857  $this->subChunks[$y] = $this->emptySubChunk;
858  }else{
859  continue; //do not set changed
860  }
861  $this->hasChanged = true;
862  }
863  }

◆ recalculateHeightMap()

recalculateHeightMap ( )

Recalculates the heightmap for the whole chunk.

390  {
391  for($z = 0; $z < 16; ++$z){
392  for($x = 0; $x < 16; ++$x){
394  }
395  }
396  }

◆ recalculateHeightMapColumn()

recalculateHeightMapColumn ( int  $x,
int  $z 
)

Recalculates the heightmap for the block column at the specified X/Z chunk coordinates

Parameters
int$x0-15
int$z0-15
Returns
int New calculated heightmap value (0-256 inclusive)
406  : int{
407  $max = $this->getHighestBlockAt($x, $z);
408  for($y = $max; $y >= 0; --$y){
409  if(Block::$lightFilter[$id = $this->getBlockId($x, $y, $z)] > 1 or Block::$diffusesSkyLight[$id]){
410  break;
411  }
412  }
413  $this->setHeightMap($x, $z, $y + 1);
414  return $y + 1;
415  }

◆ removeEntity()

removeEntity ( Entity  $entity)
Parameters
Entity$entity
585  {
586  unset($this->entities[$entity->getId()]);
587  if(!($entity instanceof Player) and $this->isInit){
588  $this->hasChanged = true;
589  }
590  }

◆ removeTile()

removeTile ( Tile  $tile)
Parameters
Tile$tile
609  {
610  unset($this->tiles[$tile->getId()]);
611  unset($this->tileList[(($tile->x & 0x0f) << 12) | (($tile->z & 0x0f) << 8) | ($tile->y & 0xff)]);
612  if($this->isInit){
613  $this->hasChanged = true;
614  }
615  }

◆ setBiomeId()

setBiomeId ( int  $x,
int  $z,
int  $biomeId 
)

Sets the biome ID at the specified X/Z chunk block coordinates

Parameters
int$x0-15
int$z0-15
int$biomeId0-255
465  {
466  $this->hasChanged = true;
467  $this->biomeIds{($z << 4) | $x} = chr($biomeId & 0xff);
468  }

◆ setBlock()

setBlock ( int  $x,
int  $y,
int  $z,
  $blockId = null,
  $meta = null 
)

Sets block ID and meta in one call at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
int | null$blockId0-255 if null, does not change
int | null$meta0-15 if null, does not change
Returns
bool
195  : bool{
196  if($this->getSubChunk($y >> 4, true)->setBlock($x, $y & 0x0f, $z, $blockId !== null ? ($blockId & 0xff) : null, $meta !== null ? ($meta & 0x0f) : null)){
197  $this->hasChanged = true;
198  return true;
199  }
200  return false;
201  }

◆ setBlockData()

setBlockData ( int  $x,
int  $y,
int  $z,
int  $data 
)

Sets the block meta value at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
int$data0-15
251  {
252  if($this->getSubChunk($y >> 4)->setBlockData($x, $y & 0x0f, $z, $data)){
253  $this->hasChanged = true;
254  }
255  }

◆ setBlockExtraData()

setBlockExtraData ( int  $x,
int  $y,
int  $z,
int  $data 
)

Sets the raw block extra data value at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
int$databitmap, (meta << 8) | id
278  {
279  if($data === 0){
280  unset($this->extraData[Chunk::chunkBlockHash($x, $y, $z)]);
281  }else{
282  $this->extraData[Chunk::chunkBlockHash($x, $y, $z)] = $data;
283  }
284 
285  $this->hasChanged = true;
286  }

◆ setBlockId()

setBlockId ( int  $x,
int  $y,
int  $z,
int  $id 
)

Sets the block ID at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
int$id0-255
224  {
225  if($this->getSubChunk($y >> 4, true)->setBlockId($x, $y & 0x0f, $z, $id)){
226  $this->hasChanged = true;
227  }
228  }

◆ setBlockLight()

setBlockLight ( int  $x,
int  $y,
int  $z,
int  $level 
)

Sets the block light level at the specified chunk block coordinates

Parameters
int$x0-15
int$y0-15
int$z0-15
int$level0-15
336  {
337  if($this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level)){
338  $this->hasChanged = true;
339  }
340  }

◆ setBlockSkyLight()

setBlockSkyLight ( int  $x,
int  $y,
int  $z,
int  $level 
)

Sets the sky light level at the specified chunk block coordinates

Parameters
int$x0-15
int$y
int$z0-15
int$level0-15
309  {
310  if($this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){
311  $this->hasChanged = true;
312  }
313  }

◆ setChanged()

setChanged ( bool  $value = true)
Parameters
bool$value
770  {
771  $this->hasChanged = $value;
772  }

◆ setGenerated()

setGenerated ( bool  $value = true)
Parameters
bool$value
568  {
569  $this->terrainGenerated = $value;
570  }

◆ setHeightMap()

setHeightMap ( int  $x,
int  $z,
int  $value 
)

Returns the heightmap value at the specified X/Z chunk block coordinates

Parameters
int$x0-15
int$z0-15
int$value
383  {
384  $this->heightMap[($z << 4) | $x] = $value;
385  }

◆ setLightPopulated()

setLightPopulated ( bool  $value = true)
Parameters
bool$value
540  {
541  $this->lightPopulated = $value;
542  }

◆ setPopulated()

setPopulated ( bool  $value = true)
Parameters
bool$value
554  {
555  $this->terrainPopulated = $value;
556  }

◆ setSubChunk()

setSubChunk ( int  $y,
SubChunk  $subChunk = null,
bool  $allowEmpty = false 
)

Sets a subchunk in the chunk index

Parameters
int$y
SubChunk | null$subChunk
bool$allowEmptyWhether to check if the chunk is empty, and if so replace it with an empty stub
Returns
bool
800  : bool{
801  if($y < 0 or $y >= $this->height){
802  return false;
803  }
804  if($subChunk === null or ($subChunk->isEmpty() and !$allowEmpty)){
805  $this->subChunks[$y] = $this->emptySubChunk;
806  }else{
807  $this->subChunks[$y] = $subChunk;
808  }
809  $this->hasChanged = true;
810  return true;
811  }

◆ setX()

setX ( int  $x)
151  {
152  $this->x = $x;
153  }

◆ setZ()

setZ ( int  $z)
Parameters
int$z
158  {
159  $this->z = $z;
160  }

◆ unload()

unload ( bool  $safe = true)

Unloads the chunk, closing entities and tiles.

Parameters
bool$safeWhether to check if there are still players using this chunk
Returns
bool
654  : bool{
655  if($safe){
656  foreach($this->getEntities() as $entity){
657  if($entity instanceof Player){
658  return false;
659  }
660  }
661  }
662 
663  foreach($this->getEntities() as $entity){
664  if($entity instanceof Player){
665  continue;
666  }
667  $entity->close();
668  }
669 
670  foreach($this->getTiles() as $tile){
671  $tile->close();
672  }
673 
674  return true;
675  }

Field Documentation

◆ $biomeIds

$biomeIds
protected

◆ $emptySubChunk

$emptySubChunk = null
protected

◆ $entities

$entities = []
protected

◆ $extraData

$extraData = []
protected

◆ $hasChanged

$hasChanged = false
protected

◆ $height

$height = Chunk::MAX_SUBCHUNKS
protected

◆ $heightMap

$heightMap = []
protected

◆ $isInit

$isInit = false
protected

◆ $lightPopulated

$lightPopulated = false
protected

◆ $NBTentities

$NBTentities = []
protected

◆ $NBTtiles

$NBTtiles = []
protected

◆ $subChunks

$subChunks = []
protected

◆ $terrainGenerated

$terrainGenerated = false
protected

◆ $terrainPopulated

$terrainPopulated = false
protected

◆ $tileList

$tileList = []
protected

◆ $tiles

$tiles = []
protected

◆ $x

$x
protected

◆ $z

$z
protected

◆ MAX_SUBCHUNKS

const MAX_SUBCHUNKS = 16

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