Search in sources :

Example 1 with EntityHumanType

use of cn.nukkit.entity.EntityHumanType 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));
    }
}
Also used : Item(cn.nukkit.item.Item) Random(java.util.Random) EntityHumanType(cn.nukkit.entity.EntityHumanType) EntityDamageEvent(cn.nukkit.event.entity.EntityDamageEvent)

Aggregations

EntityHumanType (cn.nukkit.entity.EntityHumanType)1 EntityDamageEvent (cn.nukkit.event.entity.EntityDamageEvent)1 Item (cn.nukkit.item.Item)1 Random (java.util.Random)1