Search in sources :

Example 21 with DamageSource

use of net.minecraft.util.DamageSource in project BaseMetals by MinecraftModDevelopmentMods.

the class AquariumToolProperty method apply.

@Override
public void apply(ItemStack stack, EntityLivingBase ent) {
    if (hasEffect(stack, ent)) {
        if (ent.canBreatheUnderwater()) {
            final DamageSource extraDamage = DamageSource.GENERIC;
            ent.attackEntityFrom(extraDamage, 4f);
        }
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource)

Example 22 with DamageSource

use of net.minecraft.util.DamageSource in project BaseMetals by MinecraftModDevelopmentMods.

the class ColdIronToolProperty method apply.

@Override
public void apply(ItemStack stack, EntityLivingBase ent) {
    if (hasEffect(stack, ent)) {
        final DamageSource extraDamage = DamageSource.GENERIC;
        ent.attackEntityFrom(extraDamage, 3f);
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource)

Example 23 with DamageSource

use of net.minecraft.util.DamageSource in project minecolonies by Minecolonies.

the class EntityAIMeleeGuard method attackEntity.

private boolean attackEntity(@NotNull final EntityLivingBase entityToAttack, final float baseDamage) {
    double damgeToBeDealt = baseDamage;
    if (worker.getHealth() <= 2) {
        damgeToBeDealt *= 2;
    }
    damgeToBeDealt += ((AbstractBuildingGuards) getOwnBuilding()).getOffenceBonus();
    final ItemStack heldItem = worker.getHeldItem(EnumHand.MAIN_HAND);
    if (heldItem != null) {
        if (ItemStackUtils.doesItemServeAsWeapon(heldItem)) {
            if (heldItem.getItem() instanceof ItemSword) {
                damgeToBeDealt += ((ItemSword) heldItem.getItem()).getAttackDamage();
            } else {
                damgeToBeDealt += TinkersWeaponHelper.getDamage(heldItem);
            }
        }
        damgeToBeDealt += EnchantmentHelper.getModifierForCreature(heldItem, targetEntity.getCreatureAttribute());
    }
    targetEntity.attackEntityFrom(new DamageSource(worker.getName()), (float) damgeToBeDealt);
    targetEntity.setRevengeTarget(worker);
    final int fireAspectModifier = EnchantmentHelper.getFireAspectModifier(worker);
    if (fireAspectModifier > 0) {
        targetEntity.setFire(fireAspectModifier * FIRE_CHANCE_MULTIPLIER);
    }
    boolean killedEnemy = false;
    if (targetEntity.getHealth() <= 0.0F) {
        this.onKilledEntity(targetEntity);
        killedEnemy = true;
    }
    worker.faceEntity(entityToAttack, (float) TURN_AROUND, (float) TURN_AROUND);
    worker.getLookHelper().setLookPositionWithEntity(entityToAttack, (float) TURN_AROUND, (float) TURN_AROUND);
    final double xDiff = targetEntity.posX - worker.posX;
    final double zDiff = targetEntity.posZ - worker.posZ;
    final double goToX = xDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
    final double goToZ = zDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
    worker.move(MoverType.SELF, goToX, 0, goToZ);
    worker.swingArm(EnumHand.MAIN_HAND);
    worker.playSound(SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) getRandomPitch());
    worker.damageItemInHand(1);
    return killedEnemy;
}
Also used : ItemSword(net.minecraft.item.ItemSword) DamageSource(net.minecraft.util.DamageSource) ItemStack(net.minecraft.item.ItemStack)

Example 24 with DamageSource

use of net.minecraft.util.DamageSource in project minecolonies by Minecolonies.

the class AbstractEntityAIHerder method butcherAnimal.

/**
 * Butcher an animal.
 *
 * @param animal the {@link EntityAnimal} we are butchering
 */
private void butcherAnimal(@Nullable final EntityAnimal animal) {
    worker.setLatestStatus(new TextComponentTranslation(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_HERDER_BUTCHERING));
    if (animal != null && !walkingToAnimal(animal) && !ItemStackUtils.isEmpty(worker.getHeldItemMainhand())) {
        worker.swingArm(EnumHand.MAIN_HAND);
        animal.attackEntityFrom(new DamageSource(worker.getName()), (float) BUTCHERING_ATTACK_DAMAGE);
        worker.getHeldItemMainhand().damageItem(1, animal);
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) DamageSource(net.minecraft.util.DamageSource)

Example 25 with DamageSource

use of net.minecraft.util.DamageSource in project Minestuck by mraof.

the class ItemRandomWeapon method hitEntity.

@Override
public boolean hitEntity(ItemStack itemStack, EntityLivingBase target, EntityLivingBase player) {
    DamageSource source;
    if (player instanceof EntityPlayer) {
        source = DamageSource.causePlayerDamage((EntityPlayer) player);
    } else {
        source = DamageSource.causeMobDamage(player);
    }
    target.attackEntityFrom(source, (float) (player.getRNG().nextInt(6) + 1) * (player.getRNG().nextInt(6) + 1));
    return super.hitEntity(itemStack, target, player);
}
Also used : DamageSource(net.minecraft.util.DamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

DamageSource (net.minecraft.util.DamageSource)61 EntityLivingBase (net.minecraft.entity.EntityLivingBase)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)29 Entity (net.minecraft.entity.Entity)28 ItemStack (net.minecraft.item.ItemStack)15 BlockPos (net.minecraft.util.math.BlockPos)11 World (net.minecraft.world.World)10 IBlockState (net.minecraft.block.state.IBlockState)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Item (net.minecraft.item.Item)8 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)7 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)7 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 MobEffects (net.minecraft.init.MobEffects)6 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)6 EntityDamageSourceIndirect (net.minecraft.util.EntityDamageSourceIndirect)6 MathHelper (net.minecraft.util.math.MathHelper)6 Collection (java.util.Collection)5