cn.nukkit.entity.EntityHumanType Java Examples

The following examples show how to use cn.nukkit.entity.EntityHumanType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnchantmentThorns.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void doPostAttack(Entity attacker, Entity entity) {
    if (!(entity instanceof EntityHumanType)) {
        return;
    }

    EntityHumanType human = (EntityHumanType) entity;

    int thornsLevel = 0;

    for (Item armor : human.getInventory().getArmorContents()) {
        Enchantment thorns = armor.getEnchantment(Enchantment.ID_THORNS);
        if (thorns != null) {
            thornsLevel = Math.max(thorns.getLevel(), thornsLevel);
        }
    }

    ThreadLocalRandom random = ThreadLocalRandom.current();

    if (shouldHit(random, thornsLevel)) {
        attacker.attack(new EntityDamageByEntityEvent(entity, attacker, EntityDamageEvent.DamageCause.ENTITY_ATTACK, getDamage(random, level), 0f));
    }
}
 
Example #2
Source File: EnchantmentThorns.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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));
    }
}
 
Example #3
Source File: PlayerInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public PlayerInventory(EntityHumanType player) {
    super(player, InventoryType.PLAYER);
    this.hotbar = new int[this.getHotbarSize()];

    for (int i = 0; i < this.hotbar.length; i++) {
        this.hotbar[i] = i;
    }

}
 
Example #4
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public PlayerInventory(EntityHumanType player) {
    super(player, InventoryType.PLAYER);
    this.hotbar = new int[this.getHotbarSize()];

    for (int i = 0; i < this.hotbar.length; i++) {
        this.hotbar[i] = i;
    }

}
 
Example #5
Source File: EnchantmentThorns.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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));
    }
}
 
Example #6
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public PlayerInventory(EntityHumanType player) {
    super(player, InventoryType.PLAYER);
    this.hotbar = new int[this.getHotbarSize()];

    for (int i = 0; i < this.hotbar.length; i++) {
        this.hotbar[i] = i;
    }

}
 
Example #7
Source File: PlayerEnderChestInventory.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public PlayerEnderChestInventory(EntityHumanType player) {
    super(player, InventoryType.ENDER_CHEST);
}
 
Example #8
Source File: PlayerOffhandInventory.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public PlayerOffhandInventory(EntityHumanType holder) {
	super(holder, InventoryType.OFFHAND);
}
 
Example #9
Source File: PlayerEnderChestInventory.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerEnderChestInventory(EntityHumanType player) {
    super(player, InventoryType.ENDER_CHEST);
}
 
Example #10
Source File: PlayerOffhandInventory.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerOffhandInventory(EntityHumanType holder) {
    super(holder, InventoryType.OFFHAND);
}
 
Example #11
Source File: PlayerEnderChestInventory.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public PlayerEnderChestInventory(EntityHumanType player) {
    super(player, InventoryType.ENDER_CHEST);
}