Skip to content

Commit

Permalink
Get rid of EffectContainer::defaultBubbleColor
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanCraft623 committed Dec 12, 2024
1 parent 4ab9bc7 commit 6d854d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
18 changes: 4 additions & 14 deletions src/entity/effect/EffectContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class EffectContainer{
*/
protected ObjectSet $effectRemoveHooks;

protected Color $defaultBubbleColor;

protected ?Color $bubbleColor = null;
protected Color $bubbleColor;

protected bool $onlyAmbientEffects = false;

Expand All @@ -65,7 +63,7 @@ class EffectContainer{
protected \Closure $effectValidatorForBubbles;

public function __construct(){
$this->defaultBubbleColor = new Color(0, 0, 0, 0);
$this->bubbleColor = new Color(0, 0, 0, 0);
$this->effectAddHooks = new ObjectSet();
$this->effectRemoveHooks = new ObjectSet();

Expand Down Expand Up @@ -200,21 +198,13 @@ protected function recalculateEffectColor() : void{
$this->bubbleColor = Color::mix(...$colors);
$this->onlyAmbientEffects = $ambient;
}else{
$this->bubbleColor = null;
$this->bubbleColor = new Color(0, 0, 0, 0);
$this->onlyAmbientEffects = false;
}
}

public function getDefaultBubbleColor() : Color{
return $this->defaultBubbleColor;
}

public function setDefaultBubbleColor(Color $color) : void{
$this->defaultBubbleColor = $color;
}

public function getBubbleColor() : Color{
return $this->bubbleColor ?? $this->defaultBubbleColor;
return $this->bubbleColor;
}

public function hasOnlyAmbientEffects() : bool{
Expand Down
5 changes: 3 additions & 2 deletions src/entity/object/AreaEffectCloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt);

$this->effectContainer = new EffectContainer();
$this->effectContainer->setDefaultBubbleColor(PotionSplashParticle::DEFAULT_COLOR());
$this->effectContainer->getEffectAddHooks()->add(function() : void{ $this->networkPropertiesDirty = true; });
$this->effectContainer->getEffectRemoveHooks()->add(function() : void{ $this->networkPropertiesDirty = true; });
$this->effectContainer->setEffectFilterForBubbles(function(EffectInstance $effect) : bool{
Expand Down Expand Up @@ -452,7 +451,9 @@ protected function syncNetworkData(EntityMetadataCollection $properties) : void{
$properties->setFloat(EntityMetadataProperties::AREA_EFFECT_CLOUD_RADIUS, $this->radius);
$properties->setFloat(EntityMetadataProperties::AREA_EFFECT_CLOUD_PICKUP_COUNT, $this->pickupCount);
$properties->setInt(EntityMetadataProperties::AREA_EFFECT_CLOUD_WAITING, $spawnTime + $this->waiting);
$properties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt($this->effectContainer->getBubbleColor()->toARGB()));
$properties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt((
count($this->effectContainer->all()) === 0 ? PotionSplashParticle::DEFAULT_COLOR() : $this->effectContainer->getBubbleColor()
)->toARGB()));
$properties->setByte(EntityMetadataProperties::POTION_AMBIENT, $this->effectContainer->hasOnlyAmbientEffects() ? 1 : 0);

//TODO: HACK! we purposely fill these in with invalid values to disable the client-sided radius calculation.
Expand Down

0 comments on commit 6d854d3

Please sign in to comment.