49    public const DEFAULT_DURATION = 600; 
 
   50    public const DEFAULT_DURATION_CHANGE_ON_USE = 0; 
 
   52    public const UPDATE_DELAY = 10; 
 
   53    public const REAPPLICATION_DELAY = 40; 
 
   55    public const DEFAULT_RADIUS = 3.0; 
 
   56    public const DEFAULT_RADIUS_CHANGE_ON_PICKUP = -0.5; 
 
   57    public const DEFAULT_RADIUS_CHANGE_ON_USE = -0.5; 
 
   58    public const DEFAULT_RADIUS_CHANGE_PER_TICK = -(self::DEFAULT_RADIUS / self::DEFAULT_DURATION); 
 
   60    protected const TAG_POTION_ID = 
"PotionId"; 
 
   61    protected const TAG_SPAWN_TICK = 
"SpawnTick"; 
 
   62    protected const TAG_DURATION = 
"Duration"; 
 
   63    protected const TAG_PICKUP_COUNT = 
"PickupCount"; 
 
   64    protected const TAG_DURATION_ON_USE = 
"DurationOnUse"; 
 
   65    protected const TAG_REAPPLICATION_DELAY = 
"ReapplicationDelay"; 
 
   66    protected const TAG_INITIAL_RADIUS = 
"InitialRadius"; 
 
   67    protected const TAG_RADIUS = 
"Radius"; 
 
   68    protected const TAG_RADIUS_CHANGE_ON_PICKUP = 
"RadiusChangeOnPickup"; 
 
   69    protected const TAG_RADIUS_ON_USE = 
"RadiusOnUse"; 
 
   70    protected const TAG_RADIUS_PER_TICK = 
"RadiusPerTick"; 
 
   71    protected const TAG_EFFECTS = 
"mobEffects"; 
 
   73    public static function getNetworkTypeId() : 
string{ 
return EntityIds::AREA_EFFECT_CLOUD; }
 
   75    protected int $age = 0;
 
   80    protected array $victims = [];
 
   82    protected int $maxAge = self::DEFAULT_DURATION;
 
   83    protected int $maxAgeChangeOnUse = self::DEFAULT_DURATION_CHANGE_ON_USE;
 
   85    protected int $reapplicationDelay = self::REAPPLICATION_DELAY;
 
   87    protected int $pickupCount = 0;
 
   88    protected float $radiusChangeOnPickup = self::DEFAULT_RADIUS_CHANGE_ON_PICKUP;
 
   90    protected float $initialRadius = self::DEFAULT_RADIUS;
 
   91    protected float $radius = self::DEFAULT_RADIUS;
 
   92    protected float $radiusChangeOnUse = self::DEFAULT_RADIUS_CHANGE_ON_USE;
 
   93    protected float $radiusChangePerTick = self::DEFAULT_RADIUS_CHANGE_PER_TICK;
 
   95    public function __construct(
 
   99        parent::__construct($location, $nbt);
 
  108    protected function initEntity(
CompoundTag $nbt) : void{
 
  109        parent::initEntity($nbt);
 
  112        $this->effectCollection->getEffectAddHooks()->add(
function() : 
void{ $this->networkPropertiesDirty = 
true; });
 
  113        $this->effectCollection->getEffectRemoveHooks()->add(
function() : 
void{ $this->networkPropertiesDirty = 
true; });
 
  114        $this->effectCollection->setEffectFilterForBubbles(
static fn(EffectInstance $e) : 
bool => $e->isVisible());
 
  116        $worldTime = $this->getWorld()->getTime();
 
  117        $this->age = max($worldTime - $nbt->getLong(self::TAG_SPAWN_TICK, $worldTime), 0);
 
  118        $this->maxAge = $nbt->getInt(self::TAG_DURATION, self::DEFAULT_DURATION);
 
  119        $this->maxAgeChangeOnUse = $nbt->getInt(self::TAG_DURATION_ON_USE, self::DEFAULT_DURATION_CHANGE_ON_USE);
 
  120        $this->pickupCount = $nbt->getInt(self::TAG_PICKUP_COUNT, 0);
 
  121        $this->reapplicationDelay = $nbt->getInt(self::TAG_REAPPLICATION_DELAY, self::REAPPLICATION_DELAY);
 
  123        $this->initialRadius = $nbt->getFloat(self::TAG_INITIAL_RADIUS, self::DEFAULT_RADIUS);
 
  124        $this->setRadius($nbt->getFloat(self::TAG_RADIUS, $this->initialRadius));
 
  125        $this->radiusChangeOnPickup = $nbt->getFloat(self::TAG_RADIUS_CHANGE_ON_PICKUP, self::DEFAULT_RADIUS_CHANGE_ON_PICKUP);
 
  126        $this->radiusChangeOnUse = $nbt->getFloat(self::TAG_RADIUS_ON_USE, self::DEFAULT_RADIUS_CHANGE_ON_USE);
 
  127        $this->radiusChangePerTick = $nbt->getFloat(self::TAG_RADIUS_PER_TICK, self::DEFAULT_RADIUS_CHANGE_PER_TICK);
 
  129        $effectsTag = $nbt->
getListTag(self::TAG_EFFECTS, CompoundTag::class);
 
  130        if($effectsTag !== 
null){
 
  131            foreach($effectsTag as $e){
 
  132                $effect = EffectIdMap::getInstance()->fromId($e->getByte(
"Id"));
 
  133                if($effect === 
null){
 
  137                $this->effectCollection->add(
new EffectInstance(
 
  139                    $e->getInt(
"Duration"),
 
  140                    Binary::unsignByte($e->getByte(
"Amplifier")),
 
  141                    $e->getByte(
"ShowParticles", 1) !== 0,
 
  142                    $e->getByte(
"Ambient", 0) !== 0
 
  148    public function saveNBT() : CompoundTag{
 
  149        $nbt = parent::saveNBT();
 
  151        $nbt->
setLong(self::TAG_SPAWN_TICK, $this->getWorld()->getTime() - $this->age);
 
  152        $nbt->
setShort(self::TAG_POTION_ID, PotionTypeIds::WATER); 
 
  153        $nbt->
setInt(self::TAG_DURATION, $this->maxAge);
 
  154        $nbt->
setInt(self::TAG_DURATION_ON_USE, $this->maxAgeChangeOnUse);
 
  155        $nbt->
setInt(self::TAG_PICKUP_COUNT, $this->pickupCount);
 
  156        $nbt->
setInt(self::TAG_REAPPLICATION_DELAY, $this->reapplicationDelay);
 
  157        $nbt->
setFloat(self::TAG_INITIAL_RADIUS, $this->initialRadius);
 
  158        $nbt->
setFloat(self::TAG_RADIUS, $this->radius);
 
  159        $nbt->
setFloat(self::TAG_RADIUS_CHANGE_ON_PICKUP, $this->radiusChangeOnPickup);
 
  160        $nbt->
setFloat(self::TAG_RADIUS_ON_USE, $this->radiusChangeOnUse);
 
  161        $nbt->
setFloat(self::TAG_RADIUS_PER_TICK, $this->radiusChangePerTick);
 
  163        if(count($this->effectCollection->all()) > 0){
 
  165            foreach($this->effectCollection->all() as $effect){
 
  166                $effects[] = CompoundTag::create()
 
  167                    ->setByte(
"Id", EffectIdMap::getInstance()->toId($effect->getType()))
 
  168                    ->setByte(
"Amplifier", Binary::signByte($effect->getAmplifier()))
 
  169                    ->setInt(
"Duration", $effect->getDuration())
 
  170                    ->setByte(
"Ambient", $effect->isAmbient() ? 1 : 0)
 
  171                    ->setByte(
"ShowParticles", $effect->isVisible() ? 1 : 0);
 
  173            $nbt->
setTag(self::TAG_EFFECTS, 
new ListTag($effects));
 
  179    public function isFireProof() : bool{
 
  183    public function canBeCollidedWith() : bool{
 
  195        return $this->effectCollection;
 
  202        return $this->initialRadius;
 
 
  209        return $this->radius;
 
 
  216        $this->radius = $radius;
 
  217        $this->setSize($this->getInitialSizeInfo());
 
  218        $this->networkPropertiesDirty = 
true;
 
 
  228        return $this->radiusChangeOnPickup;
 
 
  238        $this->radiusChangeOnPickup = $radiusChangeOnPickup;
 
 
  246        return $this->radiusChangeOnUse;
 
 
  254        $this->radiusChangeOnUse = $radiusChangeOnUse;
 
 
  262        return $this->radiusChangePerTick;
 
 
  269        $this->radiusChangePerTick = $radiusChangePerTick;
 
 
  276        return $this->maxAge;
 
 
  283        $this->maxAge = $maxAge;
 
 
  291        return $this->maxAgeChangeOnUse;
 
 
  299        $this->maxAgeChangeOnUse = $maxAgeChangeOnUse;
 
 
  306        return $this->reapplicationDelay;
 
 
  313        $this->reapplicationDelay = $delay;
 
 
  316    protected function entityBaseTick(
int $tickDiff = 1) : bool{
 
  317        $hasUpdate = parent::entityBaseTick($tickDiff);
 
  319        $this->age += $tickDiff;
 
  320        $radius = $this->radius + ($this->radiusChangePerTick * $tickDiff);
 
  322            $this->flagForDespawn();
 
  325        $this->setRadius($radius);
 
  326        if($this->age >= self::UPDATE_DELAY && ($this->age % self::UPDATE_DELAY) === 0){
 
  327            if($this->age > $this->maxAge){
 
  328                $this->flagForDespawn();
 
  332            foreach($this->victims as $entityId => $expiration){
 
  333                if($this->age >= $expiration){
 
  334                    unset($this->victims[$entityId]);
 
  341            foreach($this->getWorld()->getCollidingEntities($this->getBoundingBox(), $this) as $entity){
 
  342                if(!$entity instanceof Living || isset($this->victims[$entity->getId()])){
 
  345                $entityPosition = $entity->getPosition();
 
  346                $xDiff = $entityPosition->getX() - $this->location->getX();
 
  347                $zDiff = $entityPosition->getZ() - $this->location->getZ();
 
  348                if(($xDiff ** 2 + $zDiff ** 2) > $this->radius ** 2){
 
  351                $entities[] = $entity;
 
  352                if($this->radiusChangeOnUse !== 0.0){
 
  353                    $radiusChange += $this->radiusChangeOnUse;
 
  354                    if($this->radius + $radiusChange <= 0){
 
  358                if($this->maxAgeChangeOnUse !== 0){
 
  359                    $maxAgeChange += $this->maxAgeChangeOnUse;
 
  360                    if($this->maxAge + $maxAgeChange <= 0){
 
  365            if(count($entities) === 0){
 
  369            $ev = 
new AreaEffectCloudApplyEvent($this, $entities);
 
  371            if($ev->isCancelled()){
 
  375            foreach($ev->getAffectedEntities() as $entity){
 
  376                foreach($this->effectCollection->all() as $effect){
 
  377                    $effect = clone $effect; 
 
  378                    if($effect->getType() instanceof InstantEffect){
 
  379                        $effect->getType()->applyEffect($entity, $effect, 0.5, $this);
 
  381                        $entity->getEffects()->add($effect->setDuration((
int) round($effect->getDuration() / 4)));
 
  384                if($this->reapplicationDelay !== 0){
 
  385                    $this->victims[$entity->getId()] = $this->age + $this->reapplicationDelay;
 
  389            $radius = $this->radius + $radiusChange;
 
  390            $maxAge = $this->maxAge + $maxAgeChange;
 
  391            if($radius <= 0 || $maxAge <= 0){
 
  392                $this->flagForDespawn();
 
  395            $this->setRadius($radius);
 
  396            $this->setMaxAge($maxAge);
 
  403    protected function syncNetworkData(EntityMetadataCollection $properties) : void{
 
  404        parent::syncNetworkData($properties);
 
  407        $properties->setFloat(EntityMetadataProperties::AREA_EFFECT_CLOUD_RADIUS, $this->radius);
 
  408        $properties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt((
 
  409            count($this->effectCollection->all()) === 0 ? PotionSplashParticle::DEFAULT_COLOR() : $this->effectCollection->getBubbleColor()
 
  413        $properties->setByte(EntityMetadataProperties::POTION_AMBIENT, 0);
 
  414        $properties->setInt(EntityMetadataProperties::AREA_EFFECT_CLOUD_DURATION, -1);
 
  415        $properties->setFloat(EntityMetadataProperties::AREA_EFFECT_CLOUD_RADIUS_CHANGE_ON_PICKUP, 0);
 
  416        $properties->setFloat(EntityMetadataProperties::AREA_EFFECT_CLOUD_RADIUS_PER_TICK, 0);
 
  417        $properties->setInt(EntityMetadataProperties::AREA_EFFECT_CLOUD_SPAWN_TIME, 0);
 
  418        $properties->setFloat(EntityMetadataProperties::AREA_EFFECT_CLOUD_PICKUP_COUNT, 0);
 
  419        $properties->setInt(EntityMetadataProperties::AREA_EFFECT_CLOUD_WAITING, 0);
 
  425        parent::destroyCycles();