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

Public Member Functions

 __construct (string $ids="", string $data="", string $skyLight="", string $blockLight="")
 
 isEmpty ()
 
 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)
 
 getFullBlock (int $x, int $y, int $z)
 
 setBlock (int $x, int $y, int $z, $id=null, $data=null)
 
 getBlockLight (int $x, int $y, int $z)
 
 setBlockLight (int $x, int $y, int $z, int $level)
 
 getBlockSkyLight (int $x, int $y, int $z)
 
 setBlockSkyLight (int $x, int $y, int $z, int $level)
 
 getHighestBlockAt (int $x, int $z)
 
 getBlockIdColumn (int $x, int $z)
 
 getBlockDataColumn (int $x, int $z)
 
 getBlockLightColumn (int $x, int $z)
 
 getSkyLightColumn (int $x, int $z)
 
 getBlockIdArray ()
 
 getBlockDataArray ()
 
 getSkyLightArray ()
 
 getBlockLightArray ()
 
 networkSerialize ()
 
 fastSerialize ()
 

Static Public Member Functions

static fastDeserialize (string $data)
 

Protected Attributes

 $ids
 
 $data
 
 $blockLight
 
 $skyLight
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( string  $ids = "",
string  $data = "",
string  $skyLight = "",
string  $blockLight = "" 
)

SubChunk constructor.

Parameters
string$ids
string$data
string$skyLight
string$blockLight
56  {
57  self::assignData($this->ids, $ids, 4096);
58  self::assignData($this->data, $data, 2048);
59  self::assignData($this->skyLight, $skyLight, 2048, "\xff");
60  self::assignData($this->blockLight, $blockLight, 2048);
61  }

Member Function Documentation

◆ fastDeserialize()

static fastDeserialize ( string  $data)
static
Parameters
string$data
Returns
SubChunk
363  : SubChunk{
364  return new SubChunk(
365  substr($data, 0, 4096), //ids
366  substr($data, 4096, 2048), //data
367  substr($data, 6144, 2048), //sky light
368  substr($data, 8192, 2048) //block light
369  );
370  }

◆ fastSerialize()

fastSerialize ( )
Returns
string
350  : string{
351  return
352  $this->ids .
353  $this->data .
354  $this->skyLight .
356  }

◆ getBlockData()

getBlockData ( int  $x,
int  $y,
int  $z 
)
Parameters
int$x
int$y
int$z
Returns
int
102  : int{
103  $m = ord($this->data{($x << 7) + ($z << 3) + ($y >> 1)});
104  if(($y & 1) === 0){
105  return $m & 0x0f;
106  }else{
107  return $m >> 4;
108  }
109  }

◆ getBlockDataArray()

getBlockDataArray ( )
Returns
string
318  : string{
319  assert(strlen($this->data) === 2048, "Wrong length of data array, expecting 2048 bytes, got " . strlen($this->data));
320  return $this->data;
321  }

◆ getBlockDataColumn()

getBlockDataColumn ( int  $x,
int  $z 
)
Parameters
int$x
int$z
Returns
string
283  : string{
284  return substr($this->data, (($x << 7) | ($z << 3)), 8);
285  }

◆ getBlockId()

getBlockId ( int  $x,
int  $y,
int  $z 
)
Parameters
int$x
int$y
int$z
Returns
int
78  : int{
79  return ord($this->ids{($x << 8) | ($z << 4) | $y});
80  }

◆ getBlockIdArray()

getBlockIdArray ( )
Returns
string
310  : string{
311  assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids));
312  return $this->ids;
313  }

◆ getBlockIdColumn()

getBlockIdColumn ( int  $x,
int  $z 
)
Parameters
int$x
int$z
Returns
string
273  : string{
274  return substr($this->ids, (($x << 8) | ($z << 4)), 16);
275  }

◆ getBlockLight()

getBlockLight ( int  $x,
int  $y,
int  $z 
)
Parameters
int$x
int$y
int$z
Returns
int
188  : int{
189  $byte = ord($this->blockLight{($x << 7) + ($z << 3) + ($y >> 1)});
190  if(($y & 1) === 0){
191  return $byte & 0x0f;
192  }else{
193  return $byte >> 4;
194  }
195  }

◆ getBlockLightArray()

getBlockLightArray ( )
Returns
string
334  : string{
335  assert(strlen($this->blockLight) === 2048, "Wrong length of light array, expecting 2048 bytes, got " . strlen($this->blockLight));
336  return $this->blockLight;
337  }

◆ getBlockLightColumn()

getBlockLightColumn ( int  $x,
int  $z 
)
Parameters
int$x
int$z
Returns
string
293  : string{
294  return substr($this->blockLight, (($x << 7) | ($z << 3)), 8);
295  }

◆ getBlockSkyLight()

getBlockSkyLight ( int  $x,
int  $y,
int  $z 
)
Parameters
int$x
int$y
int$z
Returns
int
223  : int{
224  $byte = ord($this->skyLight{($x << 7) + ($z << 3) + ($y >> 1)});
225  if(($y & 1) === 0){
226  return $byte & 0x0f;
227  }else{
228  return $byte >> 4;
229  }
230  }

◆ getFullBlock()

getFullBlock ( int  $x,
int  $y,
int  $z 
)
Parameters
int$x
int$y
int$z
Returns
int
136  : int{
137  $i = ($x << 8) | ($z << 4) | $y;
138  if(($y & 1) === 0){
139  return (ord($this->ids{$i}) << 4) | (ord($this->data{$i >> 1}) & 0x0f);
140  }else{
141  return (ord($this->ids{$i}) << 4) | (ord($this->data{$i >> 1}) >> 4);
142  }
143  }

◆ getHighestBlockAt()

getHighestBlockAt ( int  $x,
int  $z 
)
Parameters
int$x
int$z
Returns
int
257  : int{
258  for($y = 15; $y >= 0; --$y){
259  if($this->ids{($x << 8) | ($z << 4) | $y} !== "\x00"){
260  return $y;
261  }
262  }
263 
264  return -1; //highest block not in this subchunk
265  }

◆ getSkyLightArray()

getSkyLightArray ( )
Returns
string
326  : string{
327  assert(strlen($this->skyLight) === 2048, "Wrong length of skylight array, expecting 2048 bytes, got " . strlen($this->skyLight));
328  return $this->skyLight;
329  }

◆ getSkyLightColumn()

getSkyLightColumn ( int  $x,
int  $z 
)
Parameters
int$x
int$z
Returns
string
303  : string{
304  return substr($this->skyLight, (($x << 7) | ($z << 3)), 8);
305  }

◆ isEmpty()

isEmpty ( )
Returns
bool
66  : bool{
67  assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids));
68  return substr_count($this->ids, "\x00") === 4096;
69  }

◆ networkSerialize()

networkSerialize ( )
Returns
string
342  : string{
343  // storage version, ids, data, skylight, blocklight
344  return "\x00" . $this->ids . $this->data . $this->skyLight . $this->blockLight;
345  }

◆ setBlock()

setBlock ( int  $x,
int  $y,
int  $z,
  $id = null,
  $data = null 
)
Parameters
int$x
int$y
int$z
null$id
null$data
Returns
bool
154  : bool{
155  $i = ($x << 8) | ($z << 4) | $y;
156  $changed = false;
157  if($id !== null){
158  $block = chr($id);
159  if($this->ids{$i} !== $block){
160  $this->ids{$i} = $block;
161  $changed = true;
162  }
163  }
164 
165  if($data !== null){
166  $i >>= 1;
167  $byte = ord($this->data{$i});
168  if(($y & 1) === 0){
169  $this->data{$i} = chr(($byte & 0xf0) | ($data & 0x0f));
170  }else{
171  $this->data{$i} = chr((($data & 0x0f) << 4) | ($byte & 0x0f));
172  }
173  if($this->data{$i} !== $byte){
174  $changed = true;
175  }
176  }
177 
178  return $changed;
179  }

◆ setBlockData()

setBlockData ( int  $x,
int  $y,
int  $z,
int  $data 
)
Parameters
int$x
int$y
int$z
int$data
Returns
bool
119  : bool{
120  $i = ($x << 7) | ($z << 3) | ($y >> 1);
121  if(($y & 1) === 0){
122  $this->data{$i} = chr((ord($this->data{$i}) & 0xf0) | ($data & 0x0f));
123  }else{
124  $this->data{$i} = chr((($data & 0x0f) << 4) | (ord($this->data{$i}) & 0x0f));
125  }
126  return true;
127  }

◆ setBlockId()

setBlockId ( int  $x,
int  $y,
int  $z,
int  $id 
)
Parameters
int$x
int$y
int$z
int$id
Returns
bool
90  : bool{
91  $this->ids{($x << 8) | ($z << 4) | $y} = chr($id);
92  return true;
93  }

◆ setBlockLight()

setBlockLight ( int  $x,
int  $y,
int  $z,
int  $level 
)
Parameters
int$x
int$y
int$z
int$level
Returns
bool
205  : bool{
206  $i = ($x << 7) + ($z << 3) + ($y >> 1);
207  $byte = ord($this->blockLight{$i});
208  if(($y & 1) === 0){
209  $this->blockLight{$i} = chr(($byte & 0xf0) | ($level & 0x0f));
210  }else{
211  $this->blockLight{$i} = chr((($level & 0x0f) << 4) | ($byte & 0x0f));
212  }
213  return true;
214  }

◆ setBlockSkyLight()

setBlockSkyLight ( int  $x,
int  $y,
int  $z,
int  $level 
)
Parameters
int$x
int$y
int$z
int$level
Returns
bool
240  : bool{
241  $i = ($x << 7) + ($z << 3) + ($y >> 1);
242  $byte = ord($this->skyLight{$i});
243  if(($y & 1) === 0){
244  $this->skyLight{$i} = chr(($byte & 0xf0) | ($level & 0x0f));
245  }else{
246  $this->skyLight{$i} = chr((($level & 0x0f) << 4) | ($byte & 0x0f));
247  }
248  return true;
249  }

Field Documentation

◆ $blockLight

$blockLight
protected

◆ $data

$data
protected

◆ $ids

$ids
protected

◆ $skyLight

$skyLight
protected

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