public function attack($damage, EntityDamageEvent $source)
{
if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
$lastCause = $this->getLastDamageCause();
if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
$source->setCancelled();
}
}
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
}
if ($source instanceof EntityDamageByEntityEvent) {
$e = $source->getDamager();
if ($source instanceof EntityDamageByChildEntityEvent) {
$e = $source->getChild();
}
if ($e->isOnFire() > 0) {
$this->setOnFire(2 * $this->server->getDifficulty());
}
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack());
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION;
// Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
$this->attackTime = 10;
//0.5 seconds cooldown
}