mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Merged in 1.0.6 changes, added autogenerated data for 1.1.0.3 (doesn't work yet) and deliberately made the same merge error as Mojang
This commit is contained in:
@ -201,7 +201,7 @@ class Explosion{
|
||||
|
||||
$pos = new Vector3($block->x, $block->y, $block->z);
|
||||
|
||||
for($side = 0; $side < 5; $side++){
|
||||
for($side = 0; $side <= 5; $side++){
|
||||
$sideBlock = $pos->getSide($side);
|
||||
if(!isset($this->affectedBlocks[$index = Level::blockHash($sideBlock->x, $sideBlock->y, $sideBlock->z)]) and !isset($updateBlocks[$index])){
|
||||
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockUpdateEvent($this->level->getBlock($sideBlock)));
|
||||
|
@ -190,8 +190,11 @@ class Level implements ChunkManager, Metadatable{
|
||||
private $changedBlocks = [];
|
||||
|
||||
/** @var ReversePriorityQueue */
|
||||
private $updateQueue;
|
||||
private $updateQueueIndex = [];
|
||||
private $scheduledBlockUpdateQueue;
|
||||
private $scheduledBlockUpdateQueueIndex = [];
|
||||
|
||||
/** @var \SplQueue */
|
||||
private $neighbourBlockUpdateQueue = [];
|
||||
|
||||
/** @var Player[][] */
|
||||
private $chunkSendQueue = [];
|
||||
@ -333,8 +336,11 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->generator = Generator::getGenerator($this->provider->getGenerator());
|
||||
|
||||
$this->folderName = $name;
|
||||
$this->updateQueue = new ReversePriorityQueue();
|
||||
$this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
|
||||
$this->scheduledBlockUpdateQueue = new ReversePriorityQueue();
|
||||
$this->scheduledBlockUpdateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
|
||||
|
||||
$this->neighbourBlockUpdateQueue = new \SplQueue();
|
||||
|
||||
$this->time = (int) $this->provider->getTime();
|
||||
|
||||
$this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4)));
|
||||
@ -663,11 +669,24 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
//Do block updates
|
||||
$this->timings->doTickPending->startTiming();
|
||||
while($this->updateQueue->count() > 0 and $this->updateQueue->current()["priority"] <= $currentTick){
|
||||
$block = $this->getBlock($this->updateQueue->extract()["data"]);
|
||||
unset($this->updateQueueIndex[Level::blockHash($block->x, $block->y, $block->z)]);
|
||||
|
||||
//Delayed updates
|
||||
while($this->scheduledBlockUpdateQueue->count() > 0 and $this->scheduledBlockUpdateQueue->current()["priority"] <= $currentTick){
|
||||
$block = $this->getBlock($this->scheduledBlockUpdateQueue->extract()["data"]);
|
||||
unset($this->scheduledBlockUpdateQueueIndex[Level::blockHash($block->x, $block->y, $block->z)]);
|
||||
$block->onUpdate(self::BLOCK_UPDATE_SCHEDULED);
|
||||
}
|
||||
|
||||
//Normal updates
|
||||
while($this->neighbourBlockUpdateQueue->count() > 0){
|
||||
$index = $this->neighbourBlockUpdateQueue->dequeue();
|
||||
Level::getBlockXYZ($index, $x, $y, $z);
|
||||
$this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($this->getBlock($this->temporalVector->setComponents($x, $y, $z))));
|
||||
if(!$ev->isCancelled()){
|
||||
$ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
$this->timings->doTickPending->stopTiming();
|
||||
|
||||
$this->timings->entityTick->startTiming();
|
||||
@ -1018,15 +1037,45 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method will be removed in the future due to misleading/ambiguous name. Use {@link Level#scheduleDelayedBlockUpdate} instead.
|
||||
*
|
||||
* @param Vector3 $pos
|
||||
* @param int $delay
|
||||
*/
|
||||
public function scheduleUpdate(Vector3 $pos, int $delay){
|
||||
if(isset($this->updateQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->updateQueueIndex[$index] <= $delay){
|
||||
$this->scheduleDelayedBlockUpdate($pos, $delay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a block update to be executed after the specified number of ticks.
|
||||
* Blocks will be updated with the scheduled update type.
|
||||
*
|
||||
* @param Vector3 $pos
|
||||
* @param int $delay
|
||||
*/
|
||||
public function scheduleDelayedBlockUpdate(Vector3 $pos, int $delay){
|
||||
if(isset($this->scheduledBlockUpdateQueueIndex[$index = Level::blockHash($pos->x, $pos->y, $pos->z)]) and $this->scheduledBlockUpdateQueueIndex[$index] <= $delay){
|
||||
return;
|
||||
}
|
||||
$this->updateQueueIndex[$index] = $delay;
|
||||
$this->updateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick());
|
||||
$this->scheduledBlockUpdateQueueIndex[$index] = $delay;
|
||||
$this->scheduledBlockUpdateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick());
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the blocks around the specified position to be updated at the end of this tick.
|
||||
* Blocks will be updated with the normal update type.
|
||||
*
|
||||
* @param Vector3 $pos
|
||||
*/
|
||||
public function scheduleNeighbourBlockUpdates(Vector3 $pos){
|
||||
$pos = $pos->floor();
|
||||
|
||||
$this->neighbourBlockUpdateQueue->enqueue(Level::blockHash($pos->x + 1, $pos->y, $pos->z));
|
||||
$this->neighbourBlockUpdateQueue->enqueue(Level::blockHash($pos->x - 1, $pos->y, $pos->z));
|
||||
$this->neighbourBlockUpdateQueue->enqueue(Level::blockHash($pos->x, $pos->y + 1, $pos->z));
|
||||
$this->neighbourBlockUpdateQueue->enqueue(Level::blockHash($pos->x, $pos->y - 1, $pos->z));
|
||||
$this->neighbourBlockUpdateQueue->enqueue(Level::blockHash($pos->x, $pos->y, $pos->z + 1));
|
||||
$this->neighbourBlockUpdateQueue->enqueue(Level::blockHash($pos->x, $pos->y, $pos->z - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1440,9 +1489,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
$entity->scheduleUpdate();
|
||||
}
|
||||
$ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL);
|
||||
$this->scheduleNeighbourBlockUpdates($pos);
|
||||
}
|
||||
|
||||
$this->updateAround($pos);
|
||||
}
|
||||
|
||||
$this->timings->setBlock->stopTiming();
|
||||
|
@ -307,7 +307,7 @@ class Chunk{
|
||||
* @param int $level 0-15
|
||||
*/
|
||||
public function setBlockSkyLight(int $x, int $y, int $z, int $level){
|
||||
if($this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){
|
||||
if($this->getSubChunk($y >> 4, true)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
}
|
||||
@ -334,7 +334,7 @@ class Chunk{
|
||||
* @param int $level 0-15
|
||||
*/
|
||||
public function setBlockLight(int $x, int $y, int $z, int $level){
|
||||
if($this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level)){
|
||||
if($this->getSubChunk($y >> 4, true)->setBlockLight($x, $y & 0x0f, $z, $level)){
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,11 @@ class SubChunk{
|
||||
}
|
||||
|
||||
public function isEmpty() : bool{
|
||||
assert(strlen($this->ids) === 4096, "Wrong length of ID array, expecting 4096 bytes, got " . strlen($this->ids));
|
||||
return substr_count($this->ids, "\x00") === 4096;
|
||||
return (
|
||||
substr_count($this->ids, "\x00") === 4096 and
|
||||
substr_count($this->skyLight, "\xff") === 2048 and
|
||||
substr_count($this->blockLight, "\x00") === 2048
|
||||
);
|
||||
}
|
||||
|
||||
public function getBlockId(int $x, int $y, int $z) : int{
|
||||
|
Reference in New Issue
Block a user