From 9ec40c421fad00ec6c77bfd71816712ddb33452c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 27 Jan 2019 19:45:15 +0000 Subject: [PATCH] Split up Effects into a bunch of classes Server-side levitation now works too. --- src/pocketmine/entity/Effect.php | 187 +++--------------- .../entity/effect/AbsorptionEffect.php | 42 ++++ .../entity/effect/HealthBoostEffect.php | 39 ++++ src/pocketmine/entity/effect/HungerEffect.php | 44 +++++ .../entity/effect/InstantDamageEffect.php | 50 +++++ .../entity/effect/InstantEffect.php | 38 ++++ .../entity/effect/InstantHealthEffect.php | 39 ++++ .../entity/effect/InvisibilityEffect.php | 41 ++++ .../entity/effect/LevitationEffect.php | 51 +++++ src/pocketmine/entity/effect/PoisonEffect.php | 56 ++++++ .../entity/effect/RegenerationEffect.php | 47 +++++ .../entity/effect/SaturationEffect.php | 39 ++++ .../entity/effect/SlownessEffect.php | 42 ++++ src/pocketmine/entity/effect/SpeedEffect.php | 42 ++++ src/pocketmine/entity/effect/WitherEffect.php | 45 +++++ .../entity/projectile/SplashPotion.php | 5 +- 16 files changed, 649 insertions(+), 158 deletions(-) create mode 100644 src/pocketmine/entity/effect/AbsorptionEffect.php create mode 100644 src/pocketmine/entity/effect/HealthBoostEffect.php create mode 100644 src/pocketmine/entity/effect/HungerEffect.php create mode 100644 src/pocketmine/entity/effect/InstantDamageEffect.php create mode 100644 src/pocketmine/entity/effect/InstantEffect.php create mode 100644 src/pocketmine/entity/effect/InstantHealthEffect.php create mode 100644 src/pocketmine/entity/effect/InvisibilityEffect.php create mode 100644 src/pocketmine/entity/effect/LevitationEffect.php create mode 100644 src/pocketmine/entity/effect/PoisonEffect.php create mode 100644 src/pocketmine/entity/effect/RegenerationEffect.php create mode 100644 src/pocketmine/entity/effect/SaturationEffect.php create mode 100644 src/pocketmine/entity/effect/SlownessEffect.php create mode 100644 src/pocketmine/entity/effect/SpeedEffect.php create mode 100644 src/pocketmine/entity/effect/WitherEffect.php diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 96299d3ca..f35b4dc96 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -23,11 +23,19 @@ declare(strict_types=1); namespace pocketmine\entity; -use pocketmine\event\entity\EntityDamageByChildEntityEvent; -use pocketmine\event\entity\EntityDamageByEntityEvent; -use pocketmine\event\entity\EntityDamageEvent; -use pocketmine\event\entity\EntityRegainHealthEvent; -use pocketmine\event\player\PlayerExhaustEvent; +use pocketmine\entity\effect\AbsorptionEffect; +use pocketmine\entity\effect\HealthBoostEffect; +use pocketmine\entity\effect\HungerEffect; +use pocketmine\entity\effect\InstantDamageEffect; +use pocketmine\entity\effect\InstantHealthEffect; +use pocketmine\entity\effect\InvisibilityEffect; +use pocketmine\entity\effect\LevitationEffect; +use pocketmine\entity\effect\PoisonEffect; +use pocketmine\entity\effect\RegenerationEffect; +use pocketmine\entity\effect\SaturationEffect; +use pocketmine\entity\effect\SlownessEffect; +use pocketmine\entity\effect\SpeedEffect; +use pocketmine\entity\effect\WitherEffect; use pocketmine\utils\Color; use function constant; use function defined; @@ -65,31 +73,31 @@ class Effect{ protected static $effects = []; public static function init() : void{ - self::registerEffect(new Effect(Effect::SPEED, "%potion.moveSpeed", new Color(0x7c, 0xaf, 0xc6))); - self::registerEffect(new Effect(Effect::SLOWNESS, "%potion.moveSlowdown", new Color(0x5a, 0x6c, 0x81), true)); + self::registerEffect(new SpeedEffect(Effect::SPEED, "%potion.moveSpeed", new Color(0x7c, 0xaf, 0xc6))); + self::registerEffect(new SlownessEffect(Effect::SLOWNESS, "%potion.moveSlowdown", new Color(0x5a, 0x6c, 0x81), true)); self::registerEffect(new Effect(Effect::HASTE, "%potion.digSpeed", new Color(0xd9, 0xc0, 0x43))); self::registerEffect(new Effect(Effect::MINING_FATIGUE, "%potion.digSlowDown", new Color(0x4a, 0x42, 0x17), true)); self::registerEffect(new Effect(Effect::STRENGTH, "%potion.damageBoost", new Color(0x93, 0x24, 0x23))); - self::registerEffect(new Effect(Effect::INSTANT_HEALTH, "%potion.heal", new Color(0xf8, 0x24, 0x23), false, 1, false)); - self::registerEffect(new Effect(Effect::INSTANT_DAMAGE, "%potion.harm", new Color(0x43, 0x0a, 0x09), true, 1, false)); + self::registerEffect(new InstantHealthEffect(Effect::INSTANT_HEALTH, "%potion.heal", new Color(0xf8, 0x24, 0x23), false, false)); + self::registerEffect(new InstantDamageEffect(Effect::INSTANT_DAMAGE, "%potion.harm", new Color(0x43, 0x0a, 0x09), true, false)); self::registerEffect(new Effect(Effect::JUMP_BOOST, "%potion.jump", new Color(0x22, 0xff, 0x4c))); self::registerEffect(new Effect(Effect::NAUSEA, "%potion.confusion", new Color(0x55, 0x1d, 0x4a), true)); - self::registerEffect(new Effect(Effect::REGENERATION, "%potion.regeneration", new Color(0xcd, 0x5c, 0xab))); + self::registerEffect(new RegenerationEffect(Effect::REGENERATION, "%potion.regeneration", new Color(0xcd, 0x5c, 0xab))); self::registerEffect(new Effect(Effect::RESISTANCE, "%potion.resistance", new Color(0x99, 0x45, 0x3a))); self::registerEffect(new Effect(Effect::FIRE_RESISTANCE, "%potion.fireResistance", new Color(0xe4, 0x9a, 0x3a))); self::registerEffect(new Effect(Effect::WATER_BREATHING, "%potion.waterBreathing", new Color(0x2e, 0x52, 0x99))); - self::registerEffect(new Effect(Effect::INVISIBILITY, "%potion.invisibility", new Color(0x7f, 0x83, 0x92))); + self::registerEffect(new InvisibilityEffect(Effect::INVISIBILITY, "%potion.invisibility", new Color(0x7f, 0x83, 0x92))); self::registerEffect(new Effect(Effect::BLINDNESS, "%potion.blindness", new Color(0x1f, 0x1f, 0x23), true)); self::registerEffect(new Effect(Effect::NIGHT_VISION, "%potion.nightVision", new Color(0x1f, 0x1f, 0xa1))); - self::registerEffect(new Effect(Effect::HUNGER, "%potion.hunger", new Color(0x58, 0x76, 0x53), true)); + self::registerEffect(new HungerEffect(Effect::HUNGER, "%potion.hunger", new Color(0x58, 0x76, 0x53), true)); self::registerEffect(new Effect(Effect::WEAKNESS, "%potion.weakness", new Color(0x48, 0x4d, 0x48), true)); - self::registerEffect(new Effect(Effect::POISON, "%potion.poison", new Color(0x4e, 0x93, 0x31), true)); - self::registerEffect(new Effect(Effect::WITHER, "%potion.wither", new Color(0x35, 0x2a, 0x27), true)); - self::registerEffect(new Effect(Effect::HEALTH_BOOST, "%potion.healthBoost", new Color(0xf8, 0x7d, 0x23))); - self::registerEffect(new Effect(Effect::ABSORPTION, "%potion.absorption", new Color(0x25, 0x52, 0xa5))); - self::registerEffect(new Effect(Effect::SATURATION, "%potion.saturation", new Color(0xf8, 0x24, 0x23), false, 1)); - self::registerEffect(new Effect(Effect::LEVITATION, "%potion.levitation", new Color(0xce, 0xff, 0xff))); - self::registerEffect(new Effect(Effect::FATAL_POISON, "%potion.poison", new Color(0x4e, 0x93, 0x31), true)); + self::registerEffect(new PoisonEffect(Effect::POISON, "%potion.poison", new Color(0x4e, 0x93, 0x31), true)); + self::registerEffect(new WitherEffect(Effect::WITHER, "%potion.wither", new Color(0x35, 0x2a, 0x27), true)); + self::registerEffect(new HealthBoostEffect(Effect::HEALTH_BOOST, "%potion.healthBoost", new Color(0xf8, 0x7d, 0x23))); + self::registerEffect(new AbsorptionEffect(Effect::ABSORPTION, "%potion.absorption", new Color(0x25, 0x52, 0xa5))); + self::registerEffect(new SaturationEffect(Effect::SATURATION, "%potion.saturation", new Color(0xf8, 0x24, 0x23), false)); + self::registerEffect(new LevitationEffect(Effect::LEVITATION, "%potion.levitation", new Color(0xce, 0xff, 0xff))); + self::registerEffect(new PoisonEffect(Effect::FATAL_POISON, "%potion.poison", new Color(0x4e, 0x93, 0x31), true, true, true)); self::registerEffect(new Effect(Effect::CONDUIT_POWER, "%potion.conduitPower", new Color(0x1d, 0xc2, 0xd1))); } @@ -130,8 +138,6 @@ class Effect{ protected $color; /** @var bool */ protected $bad; - /** @var int */ - protected $defaultDuration; /** @var bool */ protected $hasBubbles; @@ -140,15 +146,13 @@ class Effect{ * @param string $name Translation key used for effect name * @param Color $color * @param bool $isBad Whether the effect is harmful - * @param int $defaultDuration Duration in ticks the effect will last for by default if applied without a duration. * @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles) */ - public function __construct(int $id, string $name, Color $color, bool $isBad = false, int $defaultDuration = 300 * 20, bool $hasBubbles = true){ + public function __construct(int $id, string $name, Color $color, bool $isBad = false, bool $hasBubbles = true){ $this->id = $id; $this->name = $name; $this->color = $color; $this->bad = $isBad; - $this->defaultDuration = $defaultDuration; $this->hasBubbles = $hasBubbles; } @@ -186,20 +190,12 @@ class Effect{ return $this->bad; } - /** - * Returns whether the effect is by default an instant effect. - * @return bool - */ - public function isInstantEffect() : bool{ - return $this->defaultDuration <= 1; - } - /** * Returns the default duration this effect will apply for if a duration is not specified. * @return int */ public function getDefaultDuration() : int{ - return $this->defaultDuration; + return 600; } /** @@ -218,31 +214,6 @@ class Effect{ * @return bool */ public function canTick(EffectInstance $instance) : bool{ - switch($this->id){ - case Effect::POISON: - case Effect::FATAL_POISON: - if(($interval = (25 >> $instance->getAmplifier())) > 0){ - return ($instance->getDuration() % $interval) === 0; - } - return true; - case Effect::WITHER: - if(($interval = (50 >> $instance->getAmplifier())) > 0){ - return ($instance->getDuration() % $interval) === 0; - } - return true; - case Effect::REGENERATION: - if(($interval = (40 >> $instance->getAmplifier())) > 0){ - return ($instance->getDuration() % $interval) === 0; - } - return true; - case Effect::HUNGER: - return true; - case Effect::INSTANT_DAMAGE: - case Effect::INSTANT_HEALTH: - case Effect::SATURATION: - //If forced to last longer than 1 tick, these apply every tick. - return true; - } return false; } @@ -253,63 +224,9 @@ class Effect{ * @param EffectInstance $instance * @param float $potency * @param null|Entity $source - * @param null|Entity $sourceOwner */ - public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null, ?Entity $sourceOwner = null) : void{ - switch($this->id){ - /** @noinspection PhpMissingBreakStatementInspection */ - case Effect::POISON: - if($entity->getHealth() <= 1){ - break; - } - case Effect::FATAL_POISON: - $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); - $entity->attack($ev); - break; + public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{ - case Effect::WITHER: - $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); - $entity->attack($ev); - break; - - case Effect::REGENERATION: - if($entity->getHealth() < $entity->getMaxHealth()){ - $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC); - $entity->heal($ev); - } - break; - - case Effect::HUNGER: - if($entity instanceof Human){ - $entity->exhaust(0.025 * $instance->getEffectLevel(), PlayerExhaustEvent::CAUSE_POTION); - } - break; - case Effect::INSTANT_HEALTH: - //TODO: add particles (witch spell) - if($entity->getHealth() < $entity->getMaxHealth()){ - $entity->heal(new EntityRegainHealthEvent($entity, (4 << $instance->getAmplifier()) * $potency, EntityRegainHealthEvent::CAUSE_MAGIC)); - } - break; - case Effect::INSTANT_DAMAGE: - //TODO: add particles (witch spell) - $damage = (4 << $instance->getAmplifier()) * $potency; - if($source !== null and $sourceOwner !== null){ - $ev = new EntityDamageByChildEntityEvent($sourceOwner, $source, $entity, EntityDamageEvent::CAUSE_MAGIC, $damage); - }elseif($source !== null){ - $ev = new EntityDamageByEntityEvent($source, $entity, EntityDamageEvent::CAUSE_MAGIC, $damage); - }else{ - $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $damage); - } - $entity->attack($ev); - - break; - case Effect::SATURATION: - if($entity instanceof Human){ - $entity->addFood($instance->getEffectLevel()); - $entity->addSaturation($instance->getEffectLevel() * 2); - } - break; - } } /** @@ -319,30 +236,7 @@ class Effect{ * @param EffectInstance $instance */ public function add(Living $entity, EffectInstance $instance) : void{ - switch($this->id){ - case Effect::INVISIBILITY: - $entity->setInvisible(); - $entity->setNameTagVisible(false); - break; - case Effect::SPEED: - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel())); - break; - case Effect::SLOWNESS: - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true); - break; - case Effect::HEALTH_BOOST: - $entity->setMaxHealth($entity->getMaxHealth() + 4 * $instance->getEffectLevel()); - break; - case Effect::ABSORPTION: - $new = (4 * $instance->getEffectLevel()); - if($new > $entity->getAbsorption()){ - $entity->setAbsorption($new); - } - break; - } } /** @@ -352,26 +246,7 @@ class Effect{ * @param EffectInstance $instance */ public function remove(Living $entity, EffectInstance $instance) : void{ - switch($this->id){ - case Effect::INVISIBILITY: - $entity->setInvisible(false); - $entity->setNameTagVisible(true); - break; - case Effect::SPEED: - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel())); - break; - case Effect::SLOWNESS: - $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); - $attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel())); - break; - case Effect::HEALTH_BOOST: - $entity->setMaxHealth($entity->getMaxHealth() - 4 * $instance->getEffectLevel()); - break; - case Effect::ABSORPTION: - $entity->setAbsorption(0); - break; - } + } public function __clone(){ diff --git a/src/pocketmine/entity/effect/AbsorptionEffect.php b/src/pocketmine/entity/effect/AbsorptionEffect.php new file mode 100644 index 000000000..75aeff4e4 --- /dev/null +++ b/src/pocketmine/entity/effect/AbsorptionEffect.php @@ -0,0 +1,42 @@ +getEffectLevel()); + if($new > $entity->getAbsorption()){ + $entity->setAbsorption($new); + } + } + + public function remove(Living $entity, EffectInstance $instance) : void{ + $entity->setAbsorption(0); + } +} diff --git a/src/pocketmine/entity/effect/HealthBoostEffect.php b/src/pocketmine/entity/effect/HealthBoostEffect.php new file mode 100644 index 000000000..86f92924d --- /dev/null +++ b/src/pocketmine/entity/effect/HealthBoostEffect.php @@ -0,0 +1,39 @@ +setMaxHealth($entity->getMaxHealth() + 4 * $instance->getEffectLevel()); + } + + public function remove(Living $entity, EffectInstance $instance) : void{ + $entity->setMaxHealth($entity->getMaxHealth() - 4 * $instance->getEffectLevel()); + } +} diff --git a/src/pocketmine/entity/effect/HungerEffect.php b/src/pocketmine/entity/effect/HungerEffect.php new file mode 100644 index 000000000..c7f8c6692 --- /dev/null +++ b/src/pocketmine/entity/effect/HungerEffect.php @@ -0,0 +1,44 @@ +exhaust(0.025 * $instance->getEffectLevel(), PlayerExhaustEvent::CAUSE_POTION); + } + } +} diff --git a/src/pocketmine/entity/effect/InstantDamageEffect.php b/src/pocketmine/entity/effect/InstantDamageEffect.php new file mode 100644 index 000000000..ffd8e007a --- /dev/null +++ b/src/pocketmine/entity/effect/InstantDamageEffect.php @@ -0,0 +1,50 @@ +getAmplifier()) * $potency; + if($source !== null){ + $sourceOwner = $source->getOwningEntity(); + if($sourceOwner !== null){ + $ev = new EntityDamageByChildEntityEvent($sourceOwner, $source, $entity, EntityDamageEvent::CAUSE_MAGIC, $damage); + }else{ + $ev = new EntityDamageByEntityEvent($source, $entity, EntityDamageEvent::CAUSE_MAGIC, $damage); + } + }else{ + $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, $damage); + } + $entity->attack($ev); + } +} diff --git a/src/pocketmine/entity/effect/InstantEffect.php b/src/pocketmine/entity/effect/InstantEffect.php new file mode 100644 index 000000000..5ed863cb7 --- /dev/null +++ b/src/pocketmine/entity/effect/InstantEffect.php @@ -0,0 +1,38 @@ +getHealth() < $entity->getMaxHealth()){ + $entity->heal(new EntityRegainHealthEvent($entity, (4 << $instance->getAmplifier()) * $potency, EntityRegainHealthEvent::CAUSE_MAGIC)); + } + } + +} diff --git a/src/pocketmine/entity/effect/InvisibilityEffect.php b/src/pocketmine/entity/effect/InvisibilityEffect.php new file mode 100644 index 000000000..6cd552c47 --- /dev/null +++ b/src/pocketmine/entity/effect/InvisibilityEffect.php @@ -0,0 +1,41 @@ +setInvisible(); + $entity->setNameTagVisible(false); + } + + public function remove(Living $entity, EffectInstance $instance) : void{ + $entity->setInvisible(false); + $entity->setNameTagVisible(); + } +} diff --git a/src/pocketmine/entity/effect/LevitationEffect.php b/src/pocketmine/entity/effect/LevitationEffect.php new file mode 100644 index 000000000..b75b0bd0c --- /dev/null +++ b/src/pocketmine/entity/effect/LevitationEffect.php @@ -0,0 +1,51 @@ +addMotion(0, ($instance->getEffectLevel() / 20 - $entity->getMotion()->y) / 5, 0); + } + } + + public function add(Living $entity, EffectInstance $instance) : void{ + $entity->setHasGravity(false); + } + + public function remove(Living $entity, EffectInstance $instance) : void{ + $entity->setHasGravity(); + } +} diff --git a/src/pocketmine/entity/effect/PoisonEffect.php b/src/pocketmine/entity/effect/PoisonEffect.php new file mode 100644 index 000000000..1f2da37d5 --- /dev/null +++ b/src/pocketmine/entity/effect/PoisonEffect.php @@ -0,0 +1,56 @@ +fatal = $fatal; + } + + public function canTick(EffectInstance $instance) : bool{ + if(($interval = (25 >> $instance->getAmplifier())) > 0){ + return ($instance->getDuration() % $interval) === 0; + } + return true; + } + + public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{ + if($entity->getHealth() > 1 or $this->fatal){ + $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); + $entity->attack($ev); + } + } +} diff --git a/src/pocketmine/entity/effect/RegenerationEffect.php b/src/pocketmine/entity/effect/RegenerationEffect.php new file mode 100644 index 000000000..02d353ca7 --- /dev/null +++ b/src/pocketmine/entity/effect/RegenerationEffect.php @@ -0,0 +1,47 @@ +> $instance->getAmplifier())) > 0){ + return ($instance->getDuration() % $interval) === 0; + } + return true; + } + + public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{ + if($entity->getHealth() < $entity->getMaxHealth()){ + $ev = new EntityRegainHealthEvent($entity, 1, EntityRegainHealthEvent::CAUSE_MAGIC); + $entity->heal($ev); + } + } +} diff --git a/src/pocketmine/entity/effect/SaturationEffect.php b/src/pocketmine/entity/effect/SaturationEffect.php new file mode 100644 index 000000000..aea9ce762 --- /dev/null +++ b/src/pocketmine/entity/effect/SaturationEffect.php @@ -0,0 +1,39 @@ +addFood($instance->getEffectLevel()); + $entity->addSaturation($instance->getEffectLevel() * 2); + } + } +} diff --git a/src/pocketmine/entity/effect/SlownessEffect.php b/src/pocketmine/entity/effect/SlownessEffect.php new file mode 100644 index 000000000..59bfe4f8f --- /dev/null +++ b/src/pocketmine/entity/effect/SlownessEffect.php @@ -0,0 +1,42 @@ +getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() * (1 - 0.15 * $instance->getEffectLevel()), true); + } + + public function remove(Living $entity, EffectInstance $instance) : void{ + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 - 0.15 * $instance->getEffectLevel())); + } +} diff --git a/src/pocketmine/entity/effect/SpeedEffect.php b/src/pocketmine/entity/effect/SpeedEffect.php new file mode 100644 index 000000000..dbd1b4d21 --- /dev/null +++ b/src/pocketmine/entity/effect/SpeedEffect.php @@ -0,0 +1,42 @@ +getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() * (1 + 0.2 * $instance->getEffectLevel())); + } + + public function remove(Living $entity, EffectInstance $instance) : void{ + $attr = $entity->getAttributeMap()->getAttribute(Attribute::MOVEMENT_SPEED); + $attr->setValue($attr->getValue() / (1 + 0.2 * $instance->getEffectLevel())); + } +} diff --git a/src/pocketmine/entity/effect/WitherEffect.php b/src/pocketmine/entity/effect/WitherEffect.php new file mode 100644 index 000000000..89f53b1e3 --- /dev/null +++ b/src/pocketmine/entity/effect/WitherEffect.php @@ -0,0 +1,45 @@ +> $instance->getAmplifier())) > 0){ + return ($instance->getDuration() % $interval) === 0; + } + return true; + } + + public function applyEffect(Living $entity, EffectInstance $instance, float $potency = 1.0, ?Entity $source = null) : void{ + $ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_MAGIC, 1); + $entity->attack($ev); + } +} diff --git a/src/pocketmine/entity/projectile/SplashPotion.php b/src/pocketmine/entity/projectile/SplashPotion.php index e135eafc5..4484d7eef 100644 --- a/src/pocketmine/entity/projectile/SplashPotion.php +++ b/src/pocketmine/entity/projectile/SplashPotion.php @@ -25,6 +25,7 @@ namespace pocketmine\entity\projectile; use pocketmine\block\Block; use pocketmine\block\BlockFactory; +use pocketmine\entity\effect\InstantEffect; use pocketmine\entity\EffectInstance; use pocketmine\entity\Living; use pocketmine\event\entity\ProjectileHitBlockEvent; @@ -101,7 +102,7 @@ class SplashPotion extends Throwable{ foreach($this->getPotionEffects() as $effect){ //getPotionEffects() is used to get COPIES to avoid accidentally modifying the same effect instance already applied to another entity - if(!$effect->getType()->isInstantEffect()){ + if(!($effect->getType() instanceof InstantEffect)){ $newDuration = (int) round($effect->getDuration() * 0.75 * $distanceMultiplier); if($newDuration < 20){ continue; @@ -109,7 +110,7 @@ class SplashPotion extends Throwable{ $effect->setDuration($newDuration); $entity->addEffect($effect); }else{ - $effect->getType()->applyEffect($entity, $effect, $distanceMultiplier, $this, $this->getOwningEntity()); + $effect->getType()->applyEffect($entity, $effect, $distanceMultiplier, $this); } } }