public function attack($damage, EntityDamageEvent $source)
{
if (!$this->isAlive()) {
return;
}
if ($this->isCreative() and $source->getCause() !== EntityDamageEvent::CAUSE_MAGIC and $source->getCause() !== EntityDamageEvent::CAUSE_SUICIDE and $source->getCause() !== EntityDamageEvent::CAUSE_VOID) {
$source->setCancelled();
} elseif ($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL) {
$source->setCancelled();
}
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
} elseif ($this->getLastDamageCause() === $source and $this->spawned) {
$pk = new EntityEventPacket();
$pk->eid = 0;
$pk->event = EntityEventPacket::HURT_ANIMATION;
$this->dataPacket($pk);
if ($this->isSurvival()) {
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_DAMAGE);
}
}
}