mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Refactor Level::chunkBlockHash() (makes no sense to put it here)
This commit is contained in:
parent
736ec6edac
commit
0e10a149ef
@ -268,10 +268,6 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
return PHP_INT_SIZE === 8 ? (($x & 0xFFFFFFF) << 36) | (($y & Level::Y_MASK) << 28) | ($z & 0xFFFFFFF) : $x . ":" . $y . ":" . $z;
|
return PHP_INT_SIZE === 8 ? (($x & 0xFFFFFFF) << 36) | (($y & Level::Y_MASK) << 28) | ($z & 0xFFFFFFF) : $x . ":" . $y . ":" . $z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function chunkBlockHash(int $x, int $y, int $z) : int{
|
|
||||||
return ($x << 12) | ($z << 8) | $y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getBlockXYZ($hash, &$x, &$y, &$z){
|
public static function getBlockXYZ($hash, &$x, &$y, &$z){
|
||||||
if(PHP_INT_SIZE === 8){
|
if(PHP_INT_SIZE === 8){
|
||||||
$x = $hash >> 36;
|
$x = $hash >> 36;
|
||||||
|
@ -195,14 +195,14 @@ class GenericChunk implements Chunk{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockExtraData(int $x, int $y, int $z) : int{
|
public function getBlockExtraData(int $x, int $y, int $z) : int{
|
||||||
return $this->extraData[Level::chunkBlockHash($x, $y, $z)] ?? 0;
|
return $this->extraData[GenericChunk::chunkBlockHash($x, $y, $z)] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBlockExtraData(int $x, int $y, int $z, int $data){
|
public function setBlockExtraData(int $x, int $y, int $z, int $data){
|
||||||
if($data === 0){
|
if($data === 0){
|
||||||
unset($this->extraData[Level::chunkBlockHash($x, $y, $z)]);
|
unset($this->extraData[GenericChunk::chunkBlockHash($x, $y, $z)]);
|
||||||
}else{
|
}else{
|
||||||
$this->extraData[Level::chunkBlockHash($x, $y, $z)] = $data;
|
$this->extraData[GenericChunk::chunkBlockHash($x, $y, $z)] = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hasChanged = true;
|
$this->hasChanged = true;
|
||||||
@ -703,6 +703,20 @@ class GenericChunk implements Chunk{
|
|||||||
return new GenericChunk($provider, $x, $z);
|
return new GenericChunk($provider, $x, $z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a block hash from chunk block coordinates. Used for extra data keys in chunk packets.
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
|
* @param int $x 0-15
|
||||||
|
* @param int $y 0-255
|
||||||
|
* @param int $z 0-15
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function chunkBlockHash(int $x, int $y, int $z) : int{
|
||||||
|
return ($x << 12) | ($z << 8) | $y;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-orders a byte array (YZX -> XZY and vice versa)
|
* Re-orders a byte array (YZX -> XZY and vice versa)
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user