mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 18:59:00 +00:00
Improved speed of some int arrays, fixed block metadata
This commit is contained in:
parent
9f953fa675
commit
866fde5351
@ -862,6 +862,12 @@ class Block extends Position implements Metadatable{
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Vector3 $pos1
|
||||
* @param Vector3 $pos2
|
||||
*
|
||||
* @return MovingObjectPosition
|
||||
*/
|
||||
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){
|
||||
$bb = $this->getBoundingBox();
|
||||
if($bb === null){
|
||||
@ -952,8 +958,10 @@ class Block extends Position implements Metadatable{
|
||||
|
||||
public function getMetadata($metadataKey){
|
||||
if($this->getLevel() instanceof Level){
|
||||
$this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
|
||||
return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function hasMetadata($metadataKey){
|
||||
|
@ -327,18 +327,11 @@ class Chunk extends BaseFullChunk{
|
||||
$chunk->blockLight = substr($data, $offset, 16384);
|
||||
$offset += 16384;
|
||||
|
||||
$chunk->heightMap = [];
|
||||
$chunk->biomeColors = [];
|
||||
$hm = unpack("C*", substr($data, $offset, 256));
|
||||
$chunk->heightMap = array_values(unpack("C*", substr($data, $offset, 256)));
|
||||
$offset += 256;
|
||||
$bc = unpack("N*", substr($data, $offset, 1024));
|
||||
$chunk->biomeColors = array_values(unpack("N*", substr($data, $offset, 1024)));
|
||||
$offset += 1024;
|
||||
|
||||
for($i = 0; $i < 256; ++$i){
|
||||
$chunk->biomeColors[$i] = $bc[$i + 1];
|
||||
$chunk->heightMap[$i] = $hm[$i + 1];
|
||||
}
|
||||
|
||||
$flags = ord($data{$offset++});
|
||||
|
||||
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", $flags & 0b1);
|
||||
@ -352,9 +345,6 @@ class Chunk extends BaseFullChunk{
|
||||
}
|
||||
|
||||
public function toFastBinary(){
|
||||
$heightMap = pack("C*", ...$this->getHeightMapArray());
|
||||
$biomeColors = pack("N*", ...$this->getBiomeColorArray());
|
||||
|
||||
return
|
||||
Binary::writeInt($this->x) .
|
||||
Binary::writeInt($this->z) .
|
||||
@ -362,8 +352,8 @@ class Chunk extends BaseFullChunk{
|
||||
$this->getBlockDataArray() .
|
||||
$this->getBlockSkyLightArray() .
|
||||
$this->getBlockLightArray() .
|
||||
$heightMap .
|
||||
$biomeColors .
|
||||
pack("C*", ...$this->getHeightMapArray()) .
|
||||
pack("N*", ...$this->getBiomeColorArray()) .
|
||||
chr(($this->isLightPopulated() ? 1 << 2 : 0) + ($this->isPopulated() ? 1 << 1 : 0) + ($this->isGenerated() ? 1 : 0));
|
||||
}
|
||||
|
||||
|
@ -32,12 +32,9 @@ class IntArray extends NamedTag{
|
||||
}
|
||||
|
||||
public function read(NBT $nbt){
|
||||
$this->value = [];
|
||||
[];
|
||||
$size = $nbt->getInt();
|
||||
$value = unpack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", $nbt->get($size * 4));
|
||||
foreach($value as $i => $v){
|
||||
$this->value[$i - 1] = $v;
|
||||
}
|
||||
$this->value = array_values(unpack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", $nbt->get($size * 4)));
|
||||
}
|
||||
|
||||
public function write(NBT $nbt){
|
||||
|
Loading…
x
Reference in New Issue
Block a user