mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 03:08:58 +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){
|
public function calculateIntercept(Vector3 $pos1, Vector3 $pos2){
|
||||||
$bb = $this->getBoundingBox();
|
$bb = $this->getBoundingBox();
|
||||||
if($bb === null){
|
if($bb === null){
|
||||||
@ -952,8 +958,10 @@ class Block extends Position implements Metadatable{
|
|||||||
|
|
||||||
public function getMetadata($metadataKey){
|
public function getMetadata($metadataKey){
|
||||||
if($this->getLevel() instanceof Level){
|
if($this->getLevel() instanceof Level){
|
||||||
$this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
|
return $this->getLevel()->getBlockMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasMetadata($metadataKey){
|
public function hasMetadata($metadataKey){
|
||||||
|
@ -327,18 +327,11 @@ class Chunk extends BaseFullChunk{
|
|||||||
$chunk->blockLight = substr($data, $offset, 16384);
|
$chunk->blockLight = substr($data, $offset, 16384);
|
||||||
$offset += 16384;
|
$offset += 16384;
|
||||||
|
|
||||||
$chunk->heightMap = [];
|
$chunk->heightMap = array_values(unpack("C*", substr($data, $offset, 256)));
|
||||||
$chunk->biomeColors = [];
|
|
||||||
$hm = unpack("C*", substr($data, $offset, 256));
|
|
||||||
$offset += 256;
|
$offset += 256;
|
||||||
$bc = unpack("N*", substr($data, $offset, 1024));
|
$chunk->biomeColors = array_values(unpack("N*", substr($data, $offset, 1024)));
|
||||||
$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++});
|
$flags = ord($data{$offset++});
|
||||||
|
|
||||||
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", $flags & 0b1);
|
$chunk->nbt->TerrainGenerated = new Byte("TerrainGenerated", $flags & 0b1);
|
||||||
@ -352,9 +345,6 @@ class Chunk extends BaseFullChunk{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function toFastBinary(){
|
public function toFastBinary(){
|
||||||
$heightMap = pack("C*", ...$this->getHeightMapArray());
|
|
||||||
$biomeColors = pack("N*", ...$this->getBiomeColorArray());
|
|
||||||
|
|
||||||
return
|
return
|
||||||
Binary::writeInt($this->x) .
|
Binary::writeInt($this->x) .
|
||||||
Binary::writeInt($this->z) .
|
Binary::writeInt($this->z) .
|
||||||
@ -362,8 +352,8 @@ class Chunk extends BaseFullChunk{
|
|||||||
$this->getBlockDataArray() .
|
$this->getBlockDataArray() .
|
||||||
$this->getBlockSkyLightArray() .
|
$this->getBlockSkyLightArray() .
|
||||||
$this->getBlockLightArray() .
|
$this->getBlockLightArray() .
|
||||||
$heightMap .
|
pack("C*", ...$this->getHeightMapArray()) .
|
||||||
$biomeColors .
|
pack("N*", ...$this->getBiomeColorArray()) .
|
||||||
chr(($this->isLightPopulated() ? 1 << 2 : 0) + ($this->isPopulated() ? 1 << 1 : 0) + ($this->isGenerated() ? 1 : 0));
|
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){
|
public function read(NBT $nbt){
|
||||||
$this->value = [];
|
[];
|
||||||
$size = $nbt->getInt();
|
$size = $nbt->getInt();
|
||||||
$value = unpack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", $nbt->get($size * 4));
|
$this->value = array_values(unpack($nbt->endianness === NBT::LITTLE_ENDIAN ? "V*" : "N*", $nbt->get($size * 4)));
|
||||||
foreach($value as $i => $v){
|
|
||||||
$this->value[$i - 1] = $v;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write(NBT $nbt){
|
public function write(NBT $nbt){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user