cn.nukkit.event.entity.EntityDamageByEntityEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.event.entity;
import cn.nukkit.entity.Entity;
import cn.nukkit.potion.Effect;
import java.util.Map;
/**
* @author MagicDroidX (Nukkit Project)
*/
public class EntityDamageByEntityEvent extends EntityDamageEvent {
private final Entity damager;
private float knockBack;
public EntityDamageByEntityEvent(Entity damager, Entity entity, DamageCause cause, float damage) {
this(damager, entity, cause, damage, 0.3f);
}
public EntityDamageByEntityEvent(Entity damager, Entity entity, DamageCause cause, Map modifiers) {
this(damager, entity, cause, modifiers, 0.3f);
}
public EntityDamageByEntityEvent(Entity damager, Entity entity, DamageCause cause, float damage, float knockBack) {
super(entity, cause, damage);
this.damager = damager;
this.knockBack = knockBack;
this.addAttackerModifiers(damager);
}
public EntityDamageByEntityEvent(Entity damager, Entity entity, DamageCause cause, Map modifiers, float knockBack) {
super(entity, cause, modifiers);
this.damager = damager;
this.knockBack = knockBack;
this.addAttackerModifiers(damager);
}
protected void addAttackerModifiers(Entity damager) {
if (damager.hasEffect(Effect.STRENGTH)) {
this.setDamage((float) (this.getDamage(DamageModifier.BASE) * 0.3 * (damager.getEffect(Effect.STRENGTH).getAmplifier() + 1)), DamageModifier.STRENGTH);
}
if (damager.hasEffect(Effect.WEAKNESS)) {
this.setDamage(-(float) (this.getDamage(DamageModifier.BASE) * 0.2 * (damager.getEffect(Effect.WEAKNESS).getAmplifier() + 1)), DamageModifier.WEAKNESS);
}
}
public Entity getDamager() {
return damager;
}
public float getKnockBack() {
return knockBack;
}
public void setKnockBack(float knockBack) {
this.knockBack = knockBack;
}
}