mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +00:00
World: group light-related functions
i don't know why these were dumped between getBlock() and setBlock() to begin with.
This commit is contained in:
parent
f01b7b74ba
commit
3768f3008e
@ -1245,99 +1245,6 @@ class World implements ChunkManager{
|
|||||||
return $light < 0 ? 0 : $light;
|
return $light < 0 ? 0 : $light;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $x
|
|
||||||
* @param int $y
|
|
||||||
* @param int $z
|
|
||||||
*
|
|
||||||
* @return int bitmap, (id << 4) | data
|
|
||||||
*/
|
|
||||||
public function getFullBlock(int $x, int $y, int $z) : int{
|
|
||||||
return $this->getChunk($x >> 4, $z >> 4, false)->getFullBlock($x & 0x0f, $y, $z & 0x0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isInWorld(int $x, int $y, int $z) : bool{
|
|
||||||
return (
|
|
||||||
$x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and
|
|
||||||
$y < $this->worldHeight and $y >= 0 and
|
|
||||||
$z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Block object at the Vector3 location. This method wraps around {@link getBlockAt}, converting the
|
|
||||||
* vector components to integers.
|
|
||||||
*
|
|
||||||
* Note: If you're using this for performance-sensitive code, and you're guaranteed to be supplying ints in the
|
|
||||||
* specified vector, consider using {@link getBlockAt} instead for better performance.
|
|
||||||
*
|
|
||||||
* @param Vector3 $pos
|
|
||||||
* @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
|
|
||||||
* @param bool $addToCache Whether to cache the block object created by this method call.
|
|
||||||
*
|
|
||||||
* @return Block
|
|
||||||
*/
|
|
||||||
public function getBlock(Vector3 $pos, bool $cached = true, bool $addToCache = true) : Block{
|
|
||||||
return $this->getBlockAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z), $cached, $addToCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the Block object at the specified coordinates.
|
|
||||||
*
|
|
||||||
* Note for plugin developers: If you are using this method a lot (thousands of times for many positions for
|
|
||||||
* example), you may want to set addToCache to false to avoid using excessive amounts of memory.
|
|
||||||
*
|
|
||||||
* @param int $x
|
|
||||||
* @param int $y
|
|
||||||
* @param int $z
|
|
||||||
* @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
|
|
||||||
* @param bool $addToCache Whether to cache the block object created by this method call.
|
|
||||||
*
|
|
||||||
* @return Block
|
|
||||||
*/
|
|
||||||
public function getBlockAt(int $x, int $y, int $z, bool $cached = true, bool $addToCache = true) : Block{
|
|
||||||
$fullState = 0;
|
|
||||||
$relativeBlockHash = null;
|
|
||||||
$chunkHash = World::chunkHash($x >> 4, $z >> 4);
|
|
||||||
|
|
||||||
if($this->isInWorld($x, $y, $z)){
|
|
||||||
$relativeBlockHash = World::chunkBlockHash($x, $y, $z);
|
|
||||||
|
|
||||||
if($cached and isset($this->blockCache[$chunkHash][$relativeBlockHash])){
|
|
||||||
return $this->blockCache[$chunkHash][$relativeBlockHash];
|
|
||||||
}
|
|
||||||
|
|
||||||
$chunk = $this->chunks[$chunkHash] ?? null;
|
|
||||||
if($chunk !== null){
|
|
||||||
$fullState = $chunk->getFullBlock($x & 0x0f, $y, $z & 0x0f);
|
|
||||||
}else{
|
|
||||||
$addToCache = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$block = BlockFactory::fromFullBlock($fullState);
|
|
||||||
$block->position($this, $x, $y, $z);
|
|
||||||
|
|
||||||
static $dynamicStateRead = false;
|
|
||||||
|
|
||||||
if($dynamicStateRead){
|
|
||||||
//this call was generated by a parent getBlock() call calculating dynamic stateinfo
|
|
||||||
//don't calculate dynamic state and don't add to block cache (since it won't have dynamic state calculated).
|
|
||||||
//this ensures that it's impossible for dynamic state properties to recursively depend on each other.
|
|
||||||
$addToCache = false;
|
|
||||||
}else{
|
|
||||||
$dynamicStateRead = true;
|
|
||||||
$block->readStateFromWorld();
|
|
||||||
$dynamicStateRead = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($addToCache and $relativeBlockHash !== null){
|
|
||||||
$this->blockCache[$chunkHash][$relativeBlockHash] = $block;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function updateAllLight(Vector3 $pos){
|
public function updateAllLight(Vector3 $pos){
|
||||||
$this->updateBlockSkyLight($pos->x, $pos->y, $pos->z);
|
$this->updateBlockSkyLight($pos->x, $pos->y, $pos->z);
|
||||||
$this->updateBlockLight($pos->x, $pos->y, $pos->z);
|
$this->updateBlockLight($pos->x, $pos->y, $pos->z);
|
||||||
@ -1435,6 +1342,99 @@ class World implements ChunkManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
*
|
||||||
|
* @return int bitmap, (id << 4) | data
|
||||||
|
*/
|
||||||
|
public function getFullBlock(int $x, int $y, int $z) : int{
|
||||||
|
return $this->getChunk($x >> 4, $z >> 4, false)->getFullBlock($x & 0x0f, $y, $z & 0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isInWorld(int $x, int $y, int $z) : bool{
|
||||||
|
return (
|
||||||
|
$x <= Limits::INT32_MAX and $x >= Limits::INT32_MIN and
|
||||||
|
$y < $this->worldHeight and $y >= 0 and
|
||||||
|
$z <= Limits::INT32_MAX and $z >= Limits::INT32_MIN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Block object at the Vector3 location. This method wraps around {@link getBlockAt}, converting the
|
||||||
|
* vector components to integers.
|
||||||
|
*
|
||||||
|
* Note: If you're using this for performance-sensitive code, and you're guaranteed to be supplying ints in the
|
||||||
|
* specified vector, consider using {@link getBlockAt} instead for better performance.
|
||||||
|
*
|
||||||
|
* @param Vector3 $pos
|
||||||
|
* @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
|
||||||
|
* @param bool $addToCache Whether to cache the block object created by this method call.
|
||||||
|
*
|
||||||
|
* @return Block
|
||||||
|
*/
|
||||||
|
public function getBlock(Vector3 $pos, bool $cached = true, bool $addToCache = true) : Block{
|
||||||
|
return $this->getBlockAt((int) floor($pos->x), (int) floor($pos->y), (int) floor($pos->z), $cached, $addToCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the Block object at the specified coordinates.
|
||||||
|
*
|
||||||
|
* Note for plugin developers: If you are using this method a lot (thousands of times for many positions for
|
||||||
|
* example), you may want to set addToCache to false to avoid using excessive amounts of memory.
|
||||||
|
*
|
||||||
|
* @param int $x
|
||||||
|
* @param int $y
|
||||||
|
* @param int $z
|
||||||
|
* @param bool $cached Whether to use the block cache for getting the block (faster, but may be inaccurate)
|
||||||
|
* @param bool $addToCache Whether to cache the block object created by this method call.
|
||||||
|
*
|
||||||
|
* @return Block
|
||||||
|
*/
|
||||||
|
public function getBlockAt(int $x, int $y, int $z, bool $cached = true, bool $addToCache = true) : Block{
|
||||||
|
$fullState = 0;
|
||||||
|
$relativeBlockHash = null;
|
||||||
|
$chunkHash = World::chunkHash($x >> 4, $z >> 4);
|
||||||
|
|
||||||
|
if($this->isInWorld($x, $y, $z)){
|
||||||
|
$relativeBlockHash = World::chunkBlockHash($x, $y, $z);
|
||||||
|
|
||||||
|
if($cached and isset($this->blockCache[$chunkHash][$relativeBlockHash])){
|
||||||
|
return $this->blockCache[$chunkHash][$relativeBlockHash];
|
||||||
|
}
|
||||||
|
|
||||||
|
$chunk = $this->chunks[$chunkHash] ?? null;
|
||||||
|
if($chunk !== null){
|
||||||
|
$fullState = $chunk->getFullBlock($x & 0x0f, $y, $z & 0x0f);
|
||||||
|
}else{
|
||||||
|
$addToCache = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$block = BlockFactory::fromFullBlock($fullState);
|
||||||
|
$block->position($this, $x, $y, $z);
|
||||||
|
|
||||||
|
static $dynamicStateRead = false;
|
||||||
|
|
||||||
|
if($dynamicStateRead){
|
||||||
|
//this call was generated by a parent getBlock() call calculating dynamic stateinfo
|
||||||
|
//don't calculate dynamic state and don't add to block cache (since it won't have dynamic state calculated).
|
||||||
|
//this ensures that it's impossible for dynamic state properties to recursively depend on each other.
|
||||||
|
$addToCache = false;
|
||||||
|
}else{
|
||||||
|
$dynamicStateRead = true;
|
||||||
|
$block->readStateFromWorld();
|
||||||
|
$dynamicStateRead = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($addToCache and $relativeBlockHash !== null){
|
||||||
|
$this->blockCache[$chunkHash][$relativeBlockHash] = $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $block;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the block at the given Vector3 coordinates.
|
* Sets the block at the given Vector3 coordinates.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user