Search in sources :

Example 41 with DamageSource

use of net.minecraft.util.DamageSource in project BetterWithAddons by DaedalusGame.

the class ItemGreatarrowLightning method hitEntity.

@Override
public void hitEntity(EntityGreatarrow arrow, Entity entity) {
    if (!(entity instanceof EntityLivingBase))
        return;
    if (!entity.world.isRemote) {
        EntityLivingBase living = (EntityLivingBase) entity;
        if (isDragon(living)) {
            DamageSource damagesource = EntityUtil.causeLightningArrowDamage(arrow.shootingEntity);
            int hurtSave = entity.hurtResistantTime;
            entity.hurtResistantTime = 0;
            if (!entity.attackEntityFrom(damagesource, EXTRA_LIGHTNING_DAMAGE)) {
                entity.hurtResistantTime = hurtSave;
            }
        }
        // electrify for a bit
        living.addPotionEffect(new PotionEffect(ModPotions.electrified, 20 * 5, 2, false, false));
        makeLightningField(arrow.world, arrow.getPositionVector(), 1.0f);
        makeFireworks(arrow.world, arrow.getPositionVector(), fireworksEntity);
        arrow.setDead();
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 42 with DamageSource

use of net.minecraft.util.DamageSource in project MorePlanets by SteveKunG.

the class EntityArrowMP method onUpdate.

@Override
public void onUpdate() {
    this.onEntityUpdate();
    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
        float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.prevRotationYaw = this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
        this.prevRotationPitch = this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f) * 180.0D / Math.PI);
    }
    BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
    IBlockState iblockstate = this.world.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    if (iblockstate.getMaterial() != Material.AIR) {
        AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
        if (axisalignedbb != null && axisalignedbb.offset(blockpos).contains(new Vec3d(this.posX, this.posY, this.posZ))) {
            this.inGround = true;
        }
    }
    if (this.arrowShake > 0) {
        --this.arrowShake;
    }
    if (this.inGround) {
        int meta = block.getMetaFromState(iblockstate);
        if (block == this.inTile && meta == this.inData) {
            ++this.ticksInGround;
            if (this.ticksInGround >= 1200) {
                this.setDead();
            }
        } else {
            this.inGround = false;
            this.motionX *= this.rand.nextFloat() * 0.2F;
            this.motionY *= this.rand.nextFloat() * 0.2F;
            this.motionZ *= this.rand.nextFloat() * 0.2F;
            this.ticksInGround = 0;
            this.ticksInAir = 0;
        }
    } else {
        ++this.ticksInAir;
        Vec3d vec31 = new Vec3d(this.posX, this.posY, this.posZ);
        Vec3d vec3 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        RayTraceResult movingobjectposition = this.world.rayTraceBlocks(vec31, vec3, false, true, false);
        vec31 = new Vec3d(this.posX, this.posY, this.posZ);
        vec3 = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (movingobjectposition != null) {
            vec3 = new Vec3d(movingobjectposition.hitVec.x, movingobjectposition.hitVec.y, movingobjectposition.hitVec.z);
        }
        Entity entity = null;
        List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(this.motionX, this.motionY, this.motionZ).grow(1.0D, 1.0D, 1.0D));
        double d0 = 0.0D;
        for (int i = 0; i < list.size(); ++i) {
            Entity entity1 = list.get(i);
            if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
                float f1 = 0.3F;
                AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().grow(f1, f1, f1);
                RayTraceResult movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
                if (movingobjectposition1 != null) {
                    double d1 = vec31.squareDistanceTo(movingobjectposition1.hitVec);
                    if (d1 < d0 || d0 == 0.0D) {
                        entity = entity1;
                        d0 = d1;
                    }
                }
            }
        }
        if (entity != null) {
            movingobjectposition = new RayTraceResult(entity);
        }
        if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer) {
            EntityPlayer entityplayer = (EntityPlayer) movingobjectposition.entityHit;
            if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
                movingobjectposition = null;
            }
        }
        if (movingobjectposition != null) {
            if (movingobjectposition.entityHit != null) {
                float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
                int l = MathHelper.ceil(f2 * this.damage);
                if (this.getIsCritical()) {
                    l += this.rand.nextInt(l / 2 + 2);
                }
                DamageSource damagesource;
                if (this.shootingEntity == null) {
                    damagesource = this.getDamageSource()[0];
                } else {
                    damagesource = this.getDamageSource()[1];
                }
                if (this.isBurning() && !(movingobjectposition.entityHit instanceof EntityEnderman)) {
                    movingobjectposition.entityHit.setFire(5);
                }
                if (movingobjectposition.entityHit.attackEntityFrom(damagesource, l)) {
                    if (movingobjectposition.entityHit instanceof EntityLivingBase) {
                        EntityLivingBase entitylivingbase = (EntityLivingBase) movingobjectposition.entityHit;
                        this.addEffect(entitylivingbase);
                        if (!this.world.isRemote) {
                            entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
                        }
                        if (this.knockbackStrength > 0) {
                            float f7 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
                            if (f7 > 0.0F) {
                                movingobjectposition.entityHit.addVelocity(this.motionX * this.knockbackStrength * 0.6000000238418579D / f7, 0.1D, this.motionZ * this.knockbackStrength * 0.6000000238418579D / f7);
                            }
                        }
                        if (this.shootingEntity instanceof EntityLivingBase) {
                            EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
                            EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase) this.shootingEntity, entitylivingbase);
                        }
                        if (this.shootingEntity != null && movingobjectposition.entityHit != this.shootingEntity && movingobjectposition.entityHit instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP) {
                            ((EntityPlayerMP) this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
                        }
                    }
                    this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
                    if (!(movingobjectposition.entityHit instanceof EntityEnderman)) {
                        this.setDead();
                    }
                } else {
                    this.motionX *= -0.10000000149011612D;
                    this.motionY *= -0.10000000149011612D;
                    this.motionZ *= -0.10000000149011612D;
                    this.rotationYaw += 180.0F;
                    this.prevRotationYaw += 180.0F;
                    this.ticksInAir = 0;
                }
            } else {
                BlockPos blockpos1 = movingobjectposition.getBlockPos();
                this.xTile = blockpos1.getX();
                this.yTile = blockpos1.getY();
                this.zTile = blockpos1.getZ();
                IBlockState iblockstate1 = this.world.getBlockState(blockpos1);
                this.inTile = iblockstate1.getBlock();
                this.inData = this.inTile.getMetaFromState(iblockstate1);
                this.motionX = (float) (movingobjectposition.hitVec.x - this.posX);
                this.motionY = (float) (movingobjectposition.hitVec.y - this.posY);
                this.motionZ = (float) (movingobjectposition.hitVec.z - this.posZ);
                float f5 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
                this.posX -= this.motionX / f5 * 0.05000000074505806D;
                this.posY -= this.motionY / f5 * 0.05000000074505806D;
                this.posZ -= this.motionZ / f5 * 0.05000000074505806D;
                this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
                this.inGround = true;
                this.arrowShake = 7;
                this.setIsCritical(false);
                if (iblockstate1.getMaterial() != Material.AIR) {
                    this.inTile.onEntityCollidedWithBlock(this.world, blockpos1, iblockstate1, this);
                }
            }
        }
        if (this.getIsCritical()) {
            for (int k = 0; k < 4; ++k) {
                this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * k / 4.0D, this.posY + this.motionY * k / 4.0D, this.posZ + this.motionZ * k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ, new int[0]);
            }
        }
        this.posX += this.motionX;
        this.posY += this.motionY;
        this.posZ += this.motionZ;
        float f3 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float) (MathHelper.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
        for (this.rotationPitch = (float) (MathHelper.atan2(this.motionY, f3) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F) {
        }
        while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
            this.prevRotationPitch += 360.0F;
        }
        while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
            this.prevRotationYaw -= 360.0F;
        }
        while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
            this.prevRotationYaw += 360.0F;
        }
        this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
        this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
        float f4 = 0.99F;
        float motionGravity = TransformerHooks.getArrowGravity(this);
        if (this.isInWater()) {
            for (int i1 = 0; i1 < 4; ++i1) {
                float f8 = 0.25F;
                this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * f8, this.posY - this.motionY * f8, this.posZ - this.motionZ * f8, this.motionX, this.motionY, this.motionZ, new int[0]);
            }
            f4 = 0.6F;
        }
        if (this.isWet()) {
            this.extinguish();
        }
        this.doMotion(f4, f3, motionGravity);
        this.setPosition(this.posX, this.posY, this.posZ);
        this.doBlockCollisions();
    }
}
Also used : Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) DamageSource(net.minecraft.util.DamageSource) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketChangeGameState(net.minecraft.network.play.server.SPacketChangeGameState) EntityEnderman(net.minecraft.entity.monster.EntityEnderman)

Example 43 with DamageSource

use of net.minecraft.util.DamageSource in project ConvenientAdditions by Necr0.

the class PotionThorns method onDamageTaken.

@SubscribeEvent
public void onDamageTaken(LivingAttackEvent event) {
    EntityLivingBase attacked = event.getEntityLiving();
    PotionEffect effect = attacked.getActivePotionEffect(this);
    DamageSource source = event.getSource();
    if (effect == null || source.getEntity() == null || !(source.getEntity() instanceof EntityLivingBase) || source.getDamageType().equals("thorns") || source.isDamageAbsolute() || source.isMagicDamage() || source.isFireDamage() || source.isExplosion() || source.isProjectile() || source.isUnblockable())
        return;
    EntityLivingBase attacker = (EntityLivingBase) source.getEntity();
    attacker.attackEntityFrom(DamageSource.causeThornsDamage(attacked), event.getAmount() * 0.2f * (effect.getAmplifier() + 1));
}
Also used : DamageSource(net.minecraft.util.DamageSource) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 44 with DamageSource

use of net.minecraft.util.DamageSource in project TecTech by Technus.

the class MainLoader method load.

public void load() {
    ProgressManager.ProgressBar progressBarLoad = ProgressManager.push("TecTech Loader", 6);
    progressBarLoad.step("Elemental Things");
    new ElementalLoader().run();
    TecTech.Logger.info("Elemental Init Done");
    progressBarLoad.step("Thaumcraft Compatibility");
    if (hasThaumcraft) {
        essentiaContainerCompat = new EssentiaCompatEnabled();
        essentiaContainerCompat.run();
    } else {
        essentiaContainerCompat = new EssentiaCompat();
    }
    TecTech.Logger.info("Thaumcraft Compatibility Done");
    progressBarLoad.step("Regular Things");
    new ThingsLoader().run();
    TecTech.Logger.info("Block/Item Init Done");
    progressBarLoad.step("Machine Things");
    new MachineLoader().run();
    TecTech.Logger.info("Machine Init Done");
    progressBarLoad.step("Register entities");
    new EntityLoader().run();
    TecTech.Logger.info("Entities registered");
    progressBarLoad.step("Add damage types");
    microwaving = new DamageSource("microwaving").setDamageBypassesArmor();
    elementalPollution = new DamageSource("elementalPollution").setDamageBypassesArmor();
    TecTech.Logger.info("Damage types addition Done");
    ProgressManager.pop(progressBarLoad);
}
Also used : EssentiaCompatEnabled(com.github.technus.tectech.compatibility.thaumcraft.EssentiaCompatEnabled) DamageSource(net.minecraft.util.DamageSource) ProgressManager(cpw.mods.fml.common.ProgressManager) EssentiaCompat(com.github.technus.tectech.compatibility.thaumcraft.EssentiaCompat)

Example 45 with DamageSource

use of net.minecraft.util.DamageSource in project Bewitchment by Um-Mitternacht.

the class ArrowDeflectionBrew method onHurt.

@Override
public void onHurt(LivingHurtEvent event, DamageSource source, EntityLivingBase affected, int amplifier) {
    amplifier++;
    affected.world.getEntitiesWithinAABB(EntityArrow.class, affected.getEntityBoundingBox().expand(amplifier / 3, 1, amplifier / 3).expand(-amplifier / 3, -1, -amplifier / 3)).parallelStream().filter(a -> a.shootingEntity != affected).filter(a -> !isInGround(a)).forEach(a -> {
        if (!affected.world.isRemote && a.pickupStatus == EntityArrow.PickupStatus.ALLOWED) {
            ItemStack arrow;
            try {
                arrow = (ItemStack) arrowstack.invoke(a);
                EntityItem ei = new EntityItem(affected.world, a.posX, a.posY, a.posZ, arrow);
                affected.world.spawnEntity(ei);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                e.printStackTrace();
            }
        }
        a.setDead();
    });
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) World(net.minecraft.world.World) IBrew(com.bewitchment.api.cauldron.brew.IBrew) ReflectionHelper(net.minecraftforge.fml.relauncher.ReflectionHelper) BlockPos(net.minecraft.util.math.BlockPos) Field(java.lang.reflect.Field) DamageSource(net.minecraft.util.DamageSource) LivingHurtEvent(net.minecraftforge.event.entity.living.LivingHurtEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityArrow(net.minecraft.entity.projectile.EntityArrow) ItemStack(net.minecraft.item.ItemStack) IBrewHurt(com.bewitchment.api.cauldron.brew.special.IBrewHurt) Minecraft(net.minecraft.client.Minecraft) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Side(net.minecraftforge.fml.relauncher.Side) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Method(java.lang.reflect.Method) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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