34 private int $damagerEntityId;
44 array $modifiers = [],
45 private float $knockBack = Living::DEFAULT_KNOCKBACK_FORCE,
46 private float $verticalKnockBackLimit = Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT
48 $this->damagerEntityId = $damager->getId();
49 parent::__construct(
$entity, $cause, $damage, $modifiers);
50 $this->addAttackerModifiers($damager);
53 protected function addAttackerModifiers(
Entity $damager) : void{
54 if($damager instanceof
Living){
55 $effects = $damager->getEffects();
56 if(($strength = $effects->get(VanillaEffects::STRENGTH())) !==
null){
57 $this->setModifier($this->getBaseDamage() * 0.3 * $strength->getEffectLevel(), self::MODIFIER_STRENGTH);
60 if(($weakness = $effects->get(VanillaEffects::WEAKNESS())) !==
null && $this->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK){
61 $this->setModifier(-($this->getBaseDamage() * 0.2 * $weakness->getEffectLevel()), self::MODIFIER_WEAKNESS);
70 return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->damagerEntityId);
79 return $this->knockBack;
88 $this->knockBack = $knockBack;
98 return $this->verticalKnockBackLimit;
106 $this->verticalKnockBackLimit = $verticalKnockBackLimit;
__construct(Entity $damager, Entity $entity, int $cause, float $damage, array $modifiers=[], private float $knockBack=Living::DEFAULT_KNOCKBACK_FORCE, private float $verticalKnockBackLimit=Living::DEFAULT_KNOCKBACK_VERTICAL_LIMIT)