public function onUpdate($type)
{
if ($type === Level::BLOCK_UPDATE_NORMAL) {
$this->checkForHarden();
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
} elseif ($type === Level::BLOCK_UPDATE_SCHEDULED) {
if ($this->temporalVector === null) {
$this->temporalVector = new Vector3(0, 0, 0);
}
$decay = $this->getFlowDecay($this);
$multiplier = $this instanceof Lava ? 2 : 1;
$flag = true;
if ($decay > 0) {
$smallestFlowDecay = -100;
$this->adjacentSources = 0;
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z - 1)), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z + 1)), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y, $this->z)), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y, $this->z)), $smallestFlowDecay);
$k = $smallestFlowDecay + $multiplier;
if ($k >= 8 or $smallestFlowDecay < 0) {
$k = -1;
}
if (($topFlowDecay = $this->getFlowDecay($this->level->getBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y + 1, $this->z))))) >= 0) {
if ($topFlowDecay >= 8) {
$k = $topFlowDecay;
} else {
$k = $topFlowDecay | 0x8;
}
}
if ($this->adjacentSources >= 2 and $this instanceof Water) {
$bottomBlock = $this->level->getBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y - 1, $this->z)));
if ($bottomBlock->isSolid()) {
$k = 0;
} elseif ($bottomBlock instanceof Water and $bottomBlock->getDamage() === 0) {
$k = 0;
}
}
if ($this instanceof Lava and $decay < 8 and $k < 8 and $k > 1 and mt_rand(0, 4) !== 0) {
$k = $decay;
$flag = false;
}
if ($k !== $decay) {
$decay = $k;
if ($decay < 0) {
$this->getLevel()->setBlock($this, new Air(), true);
} else {
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true);
$this->getLevel()->scheduleUpdate($this, $this->tickRate());
}
} elseif ($flag) {
//$this->getLevel()->scheduleUpdate($this, $this->tickRate());
//$this->updateFlow();
}
} else {
//$this->updateFlow();
}
$bottomBlock = $this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y - 1, $this->z));
if ($bottomBlock->canBeFlowedInto() or $bottomBlock instanceof Liquid) {
if ($this instanceof Lava and $bottomBlock instanceof Water) {
$this->getLevel()->setBlock($bottomBlock, Block::get(Item::STONE), true);
$this->triggerLavaMixEffects($bottomBlock);
return;
}
if ($decay >= 8) {
//$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay), true);
//$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
$this->flowIntoBlock($bottomBlock, $decay);
} else {
//$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay + 8), true);
//$this->getLevel()->scheduleUpdate($bottomBlock, $this->tickRate());
$this->flowIntoBlock($bottomBlock, $decay | 0x8);
}
} elseif ($decay >= 0 and ($decay === 0 or !$bottomBlock->canBeFlowedInto())) {
$flags = $this->getOptimalFlowDirections();
$l = $decay + $multiplier;
if ($decay >= 8) {
$l = 1;
}
if ($l >= 8) {
$this->checkForHarden();
return;
}
if ($flags[0]) {
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y, $this->z)), $l);
}
if ($flags[1]) {
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y, $this->z)), $l);
}
if ($flags[2]) {
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z - 1)), $l);
}
if ($flags[3]) {
$this->flowIntoBlock($this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z + 1)), $l);
}
}
$this->checkForHarden();
}
}