protected function recalculateEffectColor()
{
$color = [0, 0, 0];
//RGB
$count = 0;
$ambient = true;
foreach ($this->effects as $effect) {
if ($effect->isVisible()) {
$c = $effect->getColor();
$color[0] += $c[0] * ($effect->getAmplifier() + 1);
$color[1] += $c[1] * ($effect->getAmplifier() + 1);
$color[2] += $c[2] * ($effect->getAmplifier() + 1);
$count += $effect->getAmplifier() + 1;
if (!$effect->isAmbient()) {
$ambient = false;
}
}
}
if ($count > 0) {
$r = $color[0] / $count & 0xff;
$g = $color[1] / $count & 0xff;
$b = $color[2] / $count & 0xff;
$this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, ($r << 16) + ($g << 8) + $b);
$this->setDataProperty(Entity::DATA_POTION_AMBIENT, Entity::DATA_TYPE_BYTE, $ambient ? 1 : 0);
} else {
$this->setDataProperty(Entity::DATA_POTION_COLOR, Entity::DATA_TYPE_INT, 0);
$this->setDataProperty(Entity::DATA_POTION_AMBIENT, Entity::DATA_TYPE_BYTE, 0);
}
}