use of cn.nukkit.event.entity.EntityDamageEvent in project Nukkit by Nukkit.
the class EnchantmentThorns method doPostAttack.
@Override
public void doPostAttack(Entity attacker, Entity entity) {
if (!(entity instanceof EntityHumanType)) {
return;
}
EntityHumanType human = (EntityHumanType) entity;
int thornsDamage = 0;
Random rnd = new Random();
for (Item armor : human.getInventory().getArmorContents()) {
Enchantment thorns = armor.getEnchantment(Enchantment.ID_THORNS);
if (thorns != null && thorns.getLevel() > 0) {
int chance = thorns.getLevel() * 15;
if (chance > 90) {
chance = 90;
}
if (rnd.nextInt(100) + 1 <= chance) {
thornsDamage += rnd.nextInt(4) + 1;
}
}
}
if (thornsDamage > 0) {
attacker.attack(new EntityDamageEvent(attacker, DamageCause.MAGIC, rnd.nextInt(4) + 1));
}
}
Aggregations