Search in sources :

Example 46 with DamageSource

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

the class MMDToolEffects method extraEffectsOnAttack.

/**
 * @param material
 *            The material
 * @param itemStack
 *            The item
 * @param target
 *            The target
 * @param attacker
 *            The attacker
 */
public static void extraEffectsOnAttack(final MMDMaterial material, final ItemStack itemStack, final EntityLivingBase target, final EntityLivingBase attacker) {
    final String materialName = material.getName();
    if (materialName.equals(MaterialNames.COLDIRON)) {
        if (target.isImmuneToFire()) {
            final DamageSource extraDamage = DamageSource.GENERIC;
            target.attackEntityFrom(extraDamage, 3f);
        }
    } else if (materialName.equals(MaterialNames.ADAMANTINE)) {
        if (target.getMaxHealth() > 20f) {
            final DamageSource extraDamage = DamageSource.GENERIC;
            target.attackEntityFrom(extraDamage, 4f);
        }
    } else if (materialName.equals(MaterialNames.MITHRIL)) {
        if (target.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD) {
            final PotionEffect wither = new PotionEffect(MobEffects.WITHER, 60, 3);
            final PotionEffect blind = new PotionEffect(MobEffects.BLINDNESS, 60, 1);
            target.addPotionEffect(wither);
            target.addPotionEffect(blind);
        }
    } else if ((materialName.equals(MaterialNames.AQUARIUM)) && (target.canBreatheUnderwater())) {
        final DamageSource extraDamage = DamageSource.GENERIC;
        target.attackEntityFrom(extraDamage, 4f);
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) PotionEffect(net.minecraft.potion.PotionEffect)

Example 47 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class EntityEmeraldChunk method onImpact.

@Override
protected void onImpact(MovingObjectPosition movObjPos) {
    if (movObjPos.entityHit != null) {
        boolean isEnemy = movObjPos.entityHit instanceof EntityClayMan && this.target instanceof EntityClayMan && !((EntityClayMan) movObjPos.entityHit).getClayTeam().equals(((EntityClayMan) this.target).getClayTeam());
        DamageSource dmgSrc = DamageSource.causeThrownDamage(this, this.getThrower());
        if (this.getThrower() == null) {
            dmgSrc = DamageSource.causeThrownDamage(this, this);
        }
        dmgSrc.setDamageBypassesArmor();
        if (movObjPos.entityHit == this.target || isEnemy) {
            float attackDmg = 3.0F + this.rand.nextFloat();
            if (movObjPos.entityHit.isWet()) {
                attackDmg *= 2.0F;
            }
            if (movObjPos.entityHit.attackEntityFrom(dmgSrc, attackDmg)) {
                if (this.getThrower() instanceof EntityClayMan) {
                    ((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
                }
                if (movObjPos.entityHit instanceof EntityClayMan) {
                    EntityClayMan iChun = (EntityClayMan) movObjPos.entityHit;
                    movObjPos.entityHit.playSound("ambient.weather.thunder", 1.0F, 8.0F);
                    SoldierEffectInst effect = iChun.addEffect(SoldierEffects.getEffect(SoldierEffects.EFF_THUNDER));
                    if (effect != null && this.origin != null) {
                        effect.getNbtTag().setDouble("originX", this.origin.getValue0());
                        effect.getNbtTag().setDouble("originY", this.origin.getValue1());
                        effect.getNbtTag().setDouble("originZ", this.origin.getValue2());
                    }
                    iChun.updateUpgradeEffectRenders();
                }
            }
        } else {
            return;
        }
    }
    if (!this.worldObj.isRemote) {
        if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
            ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.snow);
            this.setDead();
        }
        this.dataWatcher.updateObject(DW_DEAD, (byte) (this.isDead ? 1 : 0));
    }
}
Also used : EntityClayMan(de.sanandrew.mods.claysoldiers.entity.EntityClayMan) DamageSource(net.minecraft.util.DamageSource) SoldierEffectInst(de.sanandrew.mods.claysoldiers.util.soldier.effect.SoldierEffectInst)

Example 48 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class EntityGravelChunk method onImpact.

@Override
protected void onImpact(MovingObjectPosition movObjPos) {
    if (movObjPos.entityHit != null) {
        float attackDmg = 2.0F + this.rand.nextFloat() * 2.0F;
        boolean isEnemy = movObjPos.entityHit instanceof EntityClayMan && this.target instanceof EntityClayMan && ((EntityClayMan) movObjPos.entityHit).getClayTeam().equals(((EntityClayMan) this.target).getClayTeam());
        DamageSource dmgSrc = DamageSource.causeThrownDamage(this, this.getThrower());
        if (this.getThrower() == null) {
            dmgSrc = DamageSource.causeThrownDamage(this, this);
        }
        if ((movObjPos.entityHit == this.target || isEnemy) && movObjPos.entityHit.attackEntityFrom(dmgSrc, attackDmg)) {
            if (this.getThrower() instanceof EntityClayMan) {
                ((EntityClayMan) this.getThrower()).onProjectileHit(this, movObjPos);
            }
        } else {
            return;
        }
    }
    if (!this.worldObj.isRemote) {
        if (movObjPos.typeOfHit != MovingObjectType.BLOCK || this.getBlockCollisionBox(this.worldObj, movObjPos.blockX, movObjPos.blockY, movObjPos.blockZ) != null) {
            ParticlePacketSender.sendDiggingFx(this.posX, this.posY, this.posZ, this.dimension, Blocks.gravel);
            this.setDead();
        }
        this.dataWatcher.updateObject(DW_DEAD, (byte) (this.isDead ? 1 : 0));
    }
}
Also used : EntityClayMan(de.sanandrew.mods.claysoldiers.entity.EntityClayMan) DamageSource(net.minecraft.util.DamageSource)

Example 49 with DamageSource

use of net.minecraft.util.DamageSource in project ClaySoldiersMod by SanAndreasP.

the class EntityClayProjectile method doCollisionCheck.

private void doCollisionCheck() {
    Vec3d posVec = new Vec3d(this.posX, this.posY, this.posZ);
    Vec3d futurePosVec = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
    RayTraceResult hitObj = this.world.rayTraceBlocks(posVec, futurePosVec, false, true, false);
    posVec = new Vec3d(this.posX, this.posY, this.posZ);
    futurePosVec = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
    if (hitObj != null) {
        futurePosVec = new Vec3d(hitObj.hitVec.x, hitObj.hitVec.y, hitObj.hitVec.z);
    }
    Entity entity = null;
    AxisAlignedBB checkBB = this.getEntityBoundingBox().offset(this.motionX, this.motionY, this.motionZ).grow(1.0D, 1.0D, 1.0D);
    List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, checkBB);
    double minDist = 0.0D;
    float collisionRange;
    for (Entity collidedEntity : list) {
        if (collidedEntity.canBeCollidedWith() && collidedEntity != this.shooterCache) {
            collisionRange = 0.1F;
            AxisAlignedBB collisionAABB = collidedEntity.getEntityBoundingBox().grow(collisionRange, collisionRange, collisionRange);
            RayTraceResult interceptObj = collisionAABB.calculateIntercept(posVec, futurePosVec);
            if (interceptObj != null) {
                double vecDistance = posVec.distanceTo(interceptObj.hitVec);
                if (collidedEntity == this.targetCache && (vecDistance < minDist || minDist == 0.0D)) {
                    entity = collidedEntity;
                    minDist = vecDistance;
                }
            }
        }
    }
    if (entity != null) {
        hitObj = new RayTraceResult(entity);
    }
    if (hitObj != null && hitObj.entityHit != null && hitObj.entityHit instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) hitObj.entityHit;
        if (player.capabilities.disableDamage) {
            hitObj = null;
        }
    }
    if (hitObj != null) {
        if (hitObj.entityHit != null) {
            MutableFloat dmg = new MutableFloat(this.getDamage(hitObj.entityHit));
            DamageSource damagesource = this.getProjDamageSource(hitObj.entityHit);
            if (this.isBurning() && !(hitObj.entityHit instanceof EntityEnderman)) {
                hitObj.entityHit.setFire(5);
            }
            if (this.shooterCache instanceof EntityClaySoldier) {
                EntityClaySoldier soldier = (EntityClaySoldier) this.shooterCache;
                final Entity target = hitObj.entityHit;
                soldier.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK, upg -> upg.getUpgrade().onAttack(soldier, upg, target, damagesource, dmg));
            }
            boolean preHitVelocityChanged = hitObj.entityHit.velocityChanged;
            boolean preHitAirBorne = hitObj.entityHit.isAirBorne;
            double preHitMotionX = hitObj.entityHit.motionX;
            double preHitMotionY = hitObj.entityHit.motionY;
            double preHitMotionZ = hitObj.entityHit.motionZ;
            if (this.onPreHit(hitObj.entityHit, damagesource, dmg) && hitObj.entityHit.attackEntityFrom(damagesource, dmg.floatValue())) {
                if (this.shooterCache instanceof EntityClaySoldier) {
                    EntityClaySoldier soldier = (EntityClaySoldier) this.shooterCache;
                    final Entity target = hitObj.entityHit;
                    soldier.callUpgradeFunc(EnumUpgFunctions.ON_ATTACK_SUCCESS, upg -> upg.getUpgrade().onAttackSuccess(soldier, upg, target));
                }
                hitObj.entityHit.velocityChanged = preHitVelocityChanged;
                hitObj.entityHit.isAirBorne = preHitAirBorne;
                hitObj.entityHit.motionX = preHitMotionX;
                hitObj.entityHit.motionY = preHitMotionY;
                hitObj.entityHit.motionZ = preHitMotionZ;
                this.onPostHit(hitObj.entityHit, damagesource);
                if (hitObj.entityHit instanceof EntityLivingBase) {
                    EntityLivingBase living = (EntityLivingBase) hitObj.entityHit;
                    if (!this.world.isRemote) {
                        living.setArrowCountInEntity(living.getArrowCountInEntity() + 1);
                    }
                    double deltaX = this.posX - living.posX;
                    double deltaZ = this.posZ - living.posZ;
                    while (deltaX * deltaX + deltaZ * deltaZ < 0.0001D) {
                        deltaZ = (Math.random() - Math.random()) * 0.01D;
                        deltaX = (Math.random() - Math.random()) * 0.01D;
                    }
                    this.knockBackEntity(living, deltaX, deltaZ);
                    if (this.shooterCache instanceof EntityLivingBase) {
                        EnchantmentHelper.applyThornEnchantments(living, this.shooterCache);
                        EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase) this.shooterCache, living);
                    }
                }
            }
        } else {
            this.onBlockHit(hitObj.getBlockPos());
        }
        this.processHit(hitObj);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityClaySoldier(de.sanandrew.mods.claysoldiers.entity.soldier.EntityClaySoldier) Vec3d(net.minecraft.util.math.Vec3d) MutableFloat(org.apache.commons.lang3.mutable.MutableFloat) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityEnderman(net.minecraft.entity.monster.EntityEnderman)

Example 50 with DamageSource

use of net.minecraft.util.DamageSource in project BloodMagic by WayofTime.

the class StatTrackerHandler method entityHurt.

// Tracks: Fall Protect, Arrow Protect, Physical Protect, Grave Digger, Sprint Attack, Critical Strike, Nocturnal Prowess
@SubscribeEvent
public static void entityHurt(LivingHurtEvent event) {
    DamageSource source = event.getSource();
    Entity sourceEntity = event.getSource().getTrueSource();
    EntityLivingBase attackedEntity = event.getEntityLiving();
    if (attackedEntity instanceof EntityPlayer) {
        EntityPlayer attackedPlayer = (EntityPlayer) attackedEntity;
        // Living Armor Handling
        if (LivingArmour.hasFullSet(attackedPlayer)) {
            float amount = Math.min(Utils.getModifiedDamage(attackedPlayer, event.getSource(), event.getAmount()), attackedPlayer.getHealth());
            ItemStack chestStack = attackedPlayer.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
            if (armour != null) {
                if (sourceEntity != null && !source.isMagicDamage() && !source.isProjectile())
                    StatTrackerPhysicalProtect.incrementCounter(armour, amount);
                if (source.equals(DamageSource.FALL))
                    StatTrackerFallProtect.incrementCounter(armour, amount);
                if (source.isProjectile())
                    StatTrackerArrowProtect.incrementCounter(armour, amount);
            }
        } else {
            ItemStack chestStack = attackedPlayer.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
            if (chestStack.getItem() instanceof ItemSentientArmour) {
                ItemSentientArmour armour = (ItemSentientArmour) chestStack.getItem();
                armour.onPlayerAttacked(chestStack, source, attackedPlayer);
            }
        }
    }
    if (sourceEntity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) sourceEntity;
        // Living Armor Handling
        if (LivingArmour.hasFullSet(player)) {
            ItemStack chestStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
            LivingArmour armour = ItemLivingArmour.getLivingArmour(chestStack);
            if (armour != null) {
                ItemStack mainWeapon = player.getItemStackFromSlot(EntityEquipmentSlot.MAINHAND);
                event.setAmount((float) (event.getAmount() + lastPlayerSwingStrength * armour.getAdditionalDamageOnHit(event.getAmount(), player, attackedEntity, mainWeapon)));
                float amount = Math.min(Utils.getModifiedDamage(attackedEntity, event.getSource(), event.getAmount()), attackedEntity.getHealth());
                if (!source.isProjectile()) {
                    StatTrackerMeleeDamage.incrementCounter(armour, amount);
                    if (player.getEntityWorld().getLight(player.getPosition()) <= 9)
                        StatTrackerNightSight.incrementCounter(armour, amount);
                    if (mainWeapon.getItem() instanceof ItemSpade)
                        StatTrackerGraveDigger.incrementCounter(armour, amount);
                    if (player.isSprinting())
                        StatTrackerSprintAttack.incrementCounter(armour, amount);
                    boolean isCritical = lastPlayerSwingStrength > 0.9 && player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(MobEffects.BLINDNESS) && !player.isRiding() && !player.isSprinting();
                    if (isCritical)
                        StatTrackerCriticalStrike.incrementCounter(armour, amount);
                    double kb = armour.getKnockbackOnHit(player, attackedEntity, mainWeapon);
                    if (kb > 0)
                        attackedEntity.knockBack(player, (float) kb * 0.5F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F)));
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) DamageSource(net.minecraft.util.DamageSource) ItemLivingArmour(WayofTime.bloodmagic.item.armour.ItemLivingArmour) LivingArmour(WayofTime.bloodmagic.livingArmour.LivingArmour) ItemSpade(net.minecraft.item.ItemSpade) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ItemSentientArmour(WayofTime.bloodmagic.item.armour.ItemSentientArmour) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

DamageSource (net.minecraft.util.DamageSource)54 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 EntityLivingBase (net.minecraft.entity.EntityLivingBase)24 Entity (net.minecraft.entity.Entity)23 ItemStack (net.minecraft.item.ItemStack)19 BlockPos (net.minecraft.util.math.BlockPos)10 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 EntityMinecart (net.minecraft.entity.item.EntityMinecart)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)8 Item (net.minecraft.item.Item)8 World (net.minecraft.world.World)8 IBlockState (net.minecraft.block.state.IBlockState)7 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)7 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)7 PotionEffect (net.minecraft.potion.PotionEffect)6 MathHelper (net.minecraft.util.math.MathHelper)6 Collection (java.util.Collection)5 Map (java.util.Map)5