public function getFlowVector()
{
$vector = new Vector3(0, 0, 0);
if ($this->temporalVector === null) {
$this->temporalVector = new Vector3(0, 0, 0);
}
$decay = $this->getEffectiveFlowDecay($this);
for ($j = 0; $j < 4; ++$j) {
$x = $this->x;
$y = $this->y;
$z = $this->z;
if ($j === 0) {
--$x;
} elseif ($j === 1) {
++$x;
} elseif ($j === 2) {
--$z;
} elseif ($j === 3) {
++$z;
}
$sideBlock = $this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y, $z));
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
if ($blockDecay < 0) {
if (!$sideBlock->canBeFlowedInto()) {
continue;
}
$blockDecay = $this->getEffectiveFlowDecay($this->getLevel()->getBlock($this->temporalVector->setComponents($x, $y - 1, $z)));
if ($blockDecay >= 0) {
$realDecay = $blockDecay - ($decay - 8);
$vector->x += ($sideBlock->x - $this->x) * $realDecay;
$vector->y += ($sideBlock->y - $this->y) * $realDecay;
$vector->z += ($sideBlock->z - $this->z) * $realDecay;
}
continue;
} else {
$realDecay = $blockDecay - $decay;
$vector->x += ($sideBlock->x - $this->x) * $realDecay;
$vector->y += ($sideBlock->y - $this->y) * $realDecay;
$vector->z += ($sideBlock->z - $this->z) * $realDecay;
}
}
if ($this->getDamage() >= 8) {
$falling = false;
if (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z - 1))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y, $this->z + 1))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y, $this->z))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y, $this->z))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y + 1, $this->z - 1))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x, $this->y + 1, $this->z + 1))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x - 1, $this->y + 1, $this->z))->canBeFlowedInto()) {
$falling = true;
} elseif (!$this->getLevel()->getBlock($this->temporalVector->setComponents($this->x + 1, $this->y + 1, $this->z))->canBeFlowedInto()) {
$falling = true;
}
if ($falling) {
$vector = $vector->normalize()->add(0, -6, 0);
}
}
return $vector->normalize();
}