mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 14:05:35 +00:00
Check for existence of ChunkUtils extension
This commit is contained in:
parent
ddfe828445
commit
8caabd3267
@ -23,84 +23,86 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\level\format\io;
|
namespace pocketmine\level\format\io;
|
||||||
|
|
||||||
class ChunkUtils{
|
if(!extension_loaded('pocketmine_chunkutils')){
|
||||||
|
class ChunkUtils{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-orders a byte array (YZX -> XZY and vice versa)
|
* Re-orders a byte array (YZX -> XZY and vice versa)
|
||||||
*
|
*
|
||||||
* @param string $array length 4096
|
* @param string $array length 4096
|
||||||
*
|
*
|
||||||
* @return string length 4096
|
* @return string length 4096
|
||||||
*/
|
*/
|
||||||
final public static function reorderByteArray(string $array) : string{
|
final public static function reorderByteArray(string $array) : string{
|
||||||
$result = str_repeat("\x00", 4096);
|
$result = str_repeat("\x00", 4096);
|
||||||
if($array !== $result){
|
if($array !== $result){
|
||||||
$i = 0;
|
$i = 0;
|
||||||
for($x = 0; $x < 16; ++$x){
|
for($x = 0; $x < 16; ++$x){
|
||||||
$zM = $x + 256;
|
$zM = $x + 256;
|
||||||
for($z = $x; $z < $zM; $z += 16){
|
for($z = $x; $z < $zM; $z += 16){
|
||||||
$yM = $z + 4096;
|
$yM = $z + 4096;
|
||||||
for($y = $z; $y < $yM; $y += 256){
|
for($y = $z; $y < $yM; $y += 256){
|
||||||
$result{$i} = $array{$y};
|
$result{$i} = $array{$y};
|
||||||
++$i;
|
++$i;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Re-orders a nibble array (YZX -> XZY and vice versa)
|
|
||||||
*
|
|
||||||
* @param string $array length 2048
|
|
||||||
* @param string $commonValue length 1 common value to fill the default array with and to expect, may improve sort time
|
|
||||||
*
|
|
||||||
* @return string length 2048
|
|
||||||
*/
|
|
||||||
final public static function reorderNibbleArray(string $array, string $commonValue = "\x00") : string{
|
|
||||||
$result = str_repeat($commonValue, 2048);
|
|
||||||
|
|
||||||
if($array !== $result){
|
|
||||||
$i = 0;
|
|
||||||
for($x = 0; $x < 8; ++$x){
|
|
||||||
for($z = 0; $z < 16; ++$z){
|
|
||||||
$zx = (($z << 3) | $x);
|
|
||||||
for($y = 0; $y < 8; ++$y){
|
|
||||||
$j = (($y << 8) | $zx);
|
|
||||||
$j80 = ($j | 0x80);
|
|
||||||
if($array{$j} === $commonValue and $array{$j80} === $commonValue){
|
|
||||||
//values are already filled
|
|
||||||
}else{
|
|
||||||
$i1 = ord($array{$j});
|
|
||||||
$i2 = ord($array{$j80});
|
|
||||||
$result{$i} = chr(($i2 << 4) | ($i1 & 0x0f));
|
|
||||||
$result{$i | 0x80} = chr(($i1 >> 4) | ($i2 & 0xf0));
|
|
||||||
}
|
}
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$i += 128;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
/**
|
||||||
}
|
* Re-orders a nibble array (YZX -> XZY and vice versa)
|
||||||
|
*
|
||||||
|
* @param string $array length 2048
|
||||||
|
* @param string $commonValue length 1 common value to fill the default array with and to expect, may improve sort time
|
||||||
|
*
|
||||||
|
* @return string length 2048
|
||||||
|
*/
|
||||||
|
final public static function reorderNibbleArray(string $array, string $commonValue = "\x00") : string{
|
||||||
|
$result = str_repeat($commonValue, 2048);
|
||||||
|
|
||||||
/**
|
if($array !== $result){
|
||||||
* Converts pre-MCPE-1.0 biome color array to biome ID array.
|
$i = 0;
|
||||||
*
|
for($x = 0; $x < 8; ++$x){
|
||||||
* @param int[] $array of biome color values
|
for($z = 0; $z < 16; ++$z){
|
||||||
*
|
$zx = (($z << 3) | $x);
|
||||||
* @return string
|
for($y = 0; $y < 8; ++$y){
|
||||||
*/
|
$j = (($y << 8) | $zx);
|
||||||
public static function convertBiomeColors(array $array) : string{
|
$j80 = ($j | 0x80);
|
||||||
$result = str_repeat("\x00", 256);
|
if($array{$j} === $commonValue and $array{$j80} === $commonValue){
|
||||||
foreach($array as $i => $color){
|
//values are already filled
|
||||||
$result{$i} = chr(($color >> 24) & 0xff);
|
}else{
|
||||||
|
$i1 = ord($array{$j});
|
||||||
|
$i2 = ord($array{$j80});
|
||||||
|
$result{$i} = chr(($i2 << 4) | ($i1 & 0x0f));
|
||||||
|
$result{$i | 0x80} = chr(($i1 >> 4) | ($i2 & 0xf0));
|
||||||
|
}
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$i += 128;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts pre-MCPE-1.0 biome color array to biome ID array.
|
||||||
|
*
|
||||||
|
* @param int[] $array of biome color values
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function convertBiomeColors(array $array) : string{
|
||||||
|
$result = str_repeat("\x00", 256);
|
||||||
|
foreach($array as $i => $color){
|
||||||
|
$result{$i} = chr(($color >> 24) & 0xff);
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user