Search in sources :

Example 1 with IThreatTableEntity

use of com.minecolonies.api.entity.combat.threat.IThreatTableEntity in project minecolonies by ldtteam.

the class KnightCombatAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    if (user.distanceTo(target) > 1) {
        moveInAttackPosition(target);
    }
    user.swing(Hand.MAIN_HAND);
    user.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(user.getRandom()));
    final double damageToBeDealt = getAttackDamage();
    final DamageSource source = new NamedDamageSource(user.getName().getString(), user);
    if (MineColonies.getConfig().getServer().pvp_mode.get() && target instanceof PlayerEntity) {
        source.bypassArmor();
    }
    final int fireLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FIRE_ASPECT, user.getItemInHand(Hand.MAIN_HAND));
    if (fireLevel > 0) {
        target.setSecondsOnFire(fireLevel * 80);
    }
    if (user.level.getGameTime() - lastAoeUseTime > KNOCKBACK_COOLDOWN) {
        doAoeAttack(source, damageToBeDealt);
    }
    target.hurt(source, (float) damageToBeDealt);
    target.setLastHurtByMob(user);
    if (target instanceof MobEntity && user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(KNIGHT_TAUNT) > 0) {
        ((MobEntity) target).setTarget(user);
        if (target instanceof IThreatTableEntity) {
            ((IThreatTableEntity) target).getThreatTable().addThreat(user, 5);
        }
    }
    user.stopUsingItem();
    user.decreaseSaturationForContinuousAction();
    user.getCitizenData().setVisibleStatus(KNIGHT_COMBAT);
    user.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
}
Also used : NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource) NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource) DamageSource(net.minecraft.util.DamageSource) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with IThreatTableEntity

use of com.minecolonies.api.entity.combat.threat.IThreatTableEntity in project minecolonies by Minecolonies.

the class KnightCombatAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    if (user.distanceTo(target) > 1) {
        moveInAttackPosition(target);
    }
    user.swing(Hand.MAIN_HAND);
    user.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(user.getRandom()));
    final double damageToBeDealt = getAttackDamage();
    final DamageSource source = new NamedDamageSource(user.getName().getString(), user);
    if (MineColonies.getConfig().getServer().pvp_mode.get() && target instanceof PlayerEntity) {
        source.bypassArmor();
    }
    final int fireLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FIRE_ASPECT, user.getItemInHand(Hand.MAIN_HAND));
    if (fireLevel > 0) {
        target.setSecondsOnFire(fireLevel * 80);
    }
    if (user.level.getGameTime() - lastAoeUseTime > KNOCKBACK_COOLDOWN) {
        doAoeAttack(source, damageToBeDealt);
    }
    target.hurt(source, (float) damageToBeDealt);
    target.setLastHurtByMob(user);
    if (target instanceof MobEntity && user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(KNIGHT_TAUNT) > 0) {
        ((MobEntity) target).setTarget(user);
        if (target instanceof IThreatTableEntity) {
            ((IThreatTableEntity) target).getThreatTable().addThreat(user, 5);
        }
    }
    user.stopUsingItem();
    user.decreaseSaturationForContinuousAction();
    user.getCitizenData().setVisibleStatus(KNIGHT_COMBAT);
    user.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
}
Also used : NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource) NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource) DamageSource(net.minecraft.util.DamageSource) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IThreatTableEntity (com.minecolonies.api.entity.combat.threat.IThreatTableEntity)2 NamedDamageSource (com.minecolonies.coremod.util.NamedDamageSource)2 MobEntity (net.minecraft.entity.MobEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 DamageSource (net.minecraft.util.DamageSource)2