Search in sources :

Example 6 with NamedDamageSource

use of com.minecolonies.coremod.util.NamedDamageSource in project minecolonies by Minecolonies.

the class EntityAIVisitor method doFight.

/**
 * Does the fighting logic
 *
 * @return true if done
 */
private boolean doFight() {
    if (target == null || !target.isAlive() || (actionTimeoutCounter -= COMBAT_UPDATE_RATE) <= 0) {
        target = null;
        citizen.setLastHurtByMob(null);
        citizen.setTarget(null);
        return true;
    }
    if (citizen.isWorkerAtSiteWithMove(new BlockPos(target.position()), 2) && citizen.canSee(target)) {
        citizen.swing(Hand.MAIN_HAND);
        target.hurt(new NamedDamageSource("death.attack.entity.minecolonies.visitor", citizen), 10.0f);
    }
    return false;
}
Also used : NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with NamedDamageSource

use of com.minecolonies.coremod.util.NamedDamageSource in project minecolonies by Minecolonies.

the class EntityAICombatTraining method attack.

/**
 * Attack the training partner or block.
 *
 * @return the next state to go to.
 */
private IAIState attack() {
    if (trainingPartner == null) {
        return START_WORKING;
    }
    if (BlockPosUtil.getDistance2D(worker.blockPosition(), trainingPartner.blockPosition()) > MIN_DISTANCE_TO_TRAIN) {
        currentPathingTarget = trainingPartner.blockPosition();
        stateAfterPathing = KNIGHT_TRAIN_WITH_PARTNER;
        return GO_TO_TARGET;
    }
    if (currentAttackDelay <= 0) {
        worker.getCitizenExperienceHandler().addExperience(XP_BASE_RATE);
        worker.decreaseSaturationForAction();
        worker.lookAt(trainingPartner, (float) TURN_AROUND, (float) TURN_AROUND);
        WorkerUtil.faceBlock(trainingPartner.blockPosition().above(), worker);
        worker.stopUsingItem();
        if (worker.getRandom().nextBoolean()) {
            final int shieldSlot = InventoryUtils.findFirstSlotInItemHandlerWith(getInventory(), Items.SHIELD);
            if (shieldSlot != -1) {
                worker.playSound(SoundEvents.SHIELD_BLOCK, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom()));
                worker.getCitizenItemHandler().setHeldItem(Hand.OFF_HAND, shieldSlot);
                worker.startUsingItem(Hand.OFF_HAND);
                worker.getLookControl().setLookAt(trainingPartner, (float) TURN_AROUND, (float) TURN_AROUND);
            }
        } else {
            worker.swing(Hand.MAIN_HAND);
            worker.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom()));
            trainingPartner.hurt(new NamedDamageSource("death.attack.entity.minecolonies.training", worker), 0.0F);
            worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        }
        worker.getNavigation().moveAwayFromXYZ(trainingPartner.blockPosition(), 4.0, 1.0, true);
        targetCounter++;
        if (targetCounter > building.getBuildingLevel() * ACTIONS_PER_BUILDING_LEVEL) {
            building.resetPartner(worker);
            targetCounter = 0;
            return START_WORKING;
        }
        currentAttackDelay = RANGED_ATTACK_DELAY_BASE;
    } else {
        reduceAttackDelay();
        return KNIGHT_ATTACK_PROTECT;
    }
    return KNIGHT_ATTACK_PROTECT;
}
Also used : NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource)

Example 8 with NamedDamageSource

use of com.minecolonies.coremod.util.NamedDamageSource 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)

Example 9 with NamedDamageSource

use of com.minecolonies.coremod.util.NamedDamageSource in project minecolonies by Minecolonies.

the class EntityAIWorkChickenHerder method butcherAnimal.

@Override
protected void butcherAnimal(@Nullable final AnimalEntity animal) {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_HERDER_BUTCHERING));
    if (animal != null && !walkingToAnimal(animal) && !ItemStackUtils.isEmpty(worker.getMainHandItem())) {
        worker.swing(Hand.MAIN_HAND);
        if (worker.getRandom().nextInt(1 + (ONE_HUNDRED_PERCENT - getSecondarySkillLevel()) / 5) <= 1) {
            animal.hurt(new NamedDamageSource(worker.getName().getString(), worker), (float) getButcheringAttackDamage());
            worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        }
    }
}
Also used : NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent)

Example 10 with NamedDamageSource

use of com.minecolonies.coremod.util.NamedDamageSource in project minecolonies by Minecolonies.

the class RaiderMeleeAI method doAttack.

@Override
protected void doAttack(final LivingEntity target) {
    double damageToBeDealt = user.getAttribute(MOB_ATTACK_DAMAGE).getValue();
    target.hurt(new NamedDamageSource("death.attack." + ((TranslationTextComponent) user.getName()).getKey(), user), (float) damageToBeDealt);
    user.swing(Hand.MAIN_HAND);
    user.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, (float) 1.0D, (float) SoundUtils.getRandomPitch(user.getRandom()));
    target.setLastHurtByMob(user);
}
Also used : NamedDamageSource(com.minecolonies.coremod.util.NamedDamageSource)

Aggregations

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