use of io.xol.chunkstories.api.events.entity.EntityDamageEvent in project chunkstories-core by Hugobros3.
the class EntityLivingImplementation method damage.
@Override
public float damage(DamageCause cause, HitBox osef, float damage) {
if (damageCooldown > System.currentTimeMillis())
return 0f;
EntityDamageEvent event = new EntityDamageEvent(this, cause, damage);
this.getWorld().getGameLogic().getPluginsManager().fireEvent(event);
if (!event.isCancelled()) {
entityHealthComponent.damage(event.getDamageDealt());
lastDamageCause = cause;
damageCooldown = System.currentTimeMillis() + cause.getCooldownInMs();
float damageDealt = event.getDamageDealt();
// Applies knockback
if (cause instanceof Entity) {
Entity attacker = (Entity) cause;
Vector3d attackKnockback = this.getLocation().sub(attacker.getLocation().add(0d, 0d, 0d));
attackKnockback.y = (0d);
attackKnockback.normalize();
float knockback = (float) Math.max(1f, Math.pow(damageDealt, 0.5f));
attackKnockback.mul(knockback / 50d);
attackKnockback.y = (knockback / 50d);
/*
attackKnockback.scale(damageDealt / 500d);
attackKnockback.scale(1.0 / (1.0 + 5 * this.getVelocityComponent().getVelocity().length()));*/
// .scale(1/60d).scale(damageDealt / 10f);
this.getVelocityComponent().addVelocity(attackKnockback);
}
return damageDealt;
}
return 0f;
}
Aggregations