Search in sources :

Example 56 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));
        double d0 = 0.0D;
        for (Entity entity1 : list) {
            if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity || this.ticksInAir >= 5)) {
                AxisAlignedBB axisalignedbb1 = entity1.getEntityBoundingBox().grow(0.3D);
                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.onEntityCollision(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 57 with DamageSource

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

the class EntityAIBarbarianAttackMelee method attack.

/**
 * AI for an Entity to attack the target
 *
 * @param target The target to attack
 */
private void attack(final EntityLivingBase target) {
    if (target != null) {
        double damageToBeDealt = BarbarianSpawnUtils.ATTACK_DAMAGE;
        if (entity instanceof EntityChiefBarbarian) {
            damageToBeDealt += 1.0;
        }
        if (entity.getDistance(target) <= MIN_DISTANCE_FOR_ATTACK && lastAttack <= 0 && entity.canEntityBeSeen(target)) {
            target.attackEntityFrom(new DamageSource(entity.getName()), (float) damageToBeDealt);
            entity.swingArm(EnumHand.MAIN_HAND);
            entity.playSound(SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, (float) 1.0D, (float) getRandomPitch());
            target.setRevengeTarget(entity);
            lastAttack = CYCLES_TO_WAIT;
        }
        if (lastAttack > 0) {
            lastAttack -= 1;
        }
        entity.faceEntity(target, (float) HALF_ROTATION, (float) HALF_ROTATION);
        entity.getLookHelper().setLookPositionWithEntity(target, (float) HALF_ROTATION, (float) HALF_ROTATION);
        entity.getNavigator().tryMoveToEntityLiving(target, ATTACK_SPEED);
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource)

Example 58 with DamageSource

use of net.minecraft.util.DamageSource in project ImmersiveEngineering by BluSunrize.

the class ThermalFoundationHelper method init.

@Override
public void init() {
    // TE Compat for smelter recipes. Not worth a separate module.
    OreDictionary.registerOre("crystalSlag", new ItemStack(IEContent.itemMaterial, 1, 7));
    ChemthrowerHandler.registerEffect("coal", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 0));
    ChemthrowerHandler.registerFlammable("coal");
    ChemthrowerHandler.registerEffect("crude_oil", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(IEPotions.flammable, 140, 0), new PotionEffect(MobEffects.BLINDNESS, 80, 1)));
    ChemthrowerHandler.registerFlammable("crude_oil");
    ChemthrowerHandler.registerEffect("refined_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 100, 1));
    ChemthrowerHandler.registerFlammable("refined_oil");
    ChemthrowerHandler.registerEffect("resin", new ChemthrowerEffect_Potion(null, 0, IEPotions.sticky, 100, 1));
    ChemthrowerHandler.registerEffect("tree_oil", new ChemthrowerEffect_Potion(null, 0, IEPotions.flammable, 120, 0));
    ChemthrowerHandler.registerFlammable("tree_oil");
    ChemthrowerHandler.registerEffect("redstone", new ChemthrowerEffect_Potion(null, 0, IEPotions.conductive, 100, 1));
    ChemthrowerHandler.registerEffect("glowstone", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.GLOWING, 120, 0), new PotionEffect(MobEffects.SPEED, 120, 0), new PotionEffect(MobEffects.JUMP_BOOST, 120, 0)));
    ChemthrowerHandler.registerEffect("ender", new ChemthrowerEffect_RandomTeleport(null, 0, 1));
    try {
        Class c_DamageHelper = Class.forName("cofh.lib.util.helpers.DamageHelper");
        DamageSource pyrotheum = (DamageSource) c_DamageHelper.getDeclaredField("pyrotheum").get(null);
        Field f_explodeCreepers = Class.forName("cofh.thermalfoundation.fluid.BlockFluidPyrotheum").getDeclaredField("effect");
        f_explodeCreepers.setAccessible(true);
        if ((boolean) f_explodeCreepers.get(null))
            ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3) {

                @Override
                public void applyToEntity(EntityLivingBase target, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
                    super.applyToEntity(target, shooter, thrower, fluid);
                    if (target instanceof EntityCreeper) {
                        target.getEntityWorld().createExplosion(target, target.posX, target.posY, target.posZ, 6.0F, target.getEntityWorld().getGameRules().getBoolean("mobGriefing"));
                        target.setDead();
                    }
                }
            });
        else
            ChemthrowerHandler.registerEffect("pyrotheum", new ChemthrowerEffect_Damage(pyrotheum, 3));
        DamageSource cryotheum = (DamageSource) c_DamageHelper.getDeclaredField("cryotheum").get(null);
        ChemthrowerHandler.registerEffect("cryotheum", new ChemthrowerEffect_Potion(cryotheum, 2, MobEffects.SLOWNESS, 50, 3));
    } catch (Exception e) {
    }
    ChemthrowerHandler.registerEffect("aerotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.INVISIBILITY, 60, 0), new PotionEffect(MobEffects.WATER_BREATHING, 300, 0)));
    ChemthrowerHandler.registerEffect("petrotheum", new ChemthrowerEffect_Potion(null, 0, new PotionEffect(MobEffects.HASTE, 300, 2), new PotionEffect(MobEffects.NIGHT_VISION, 300, 0), new PotionEffect(MobEffects.RESISTANCE, 300, 1)) {

        @Override
        public void applyToBlock(World world, RayTraceResult mop, @Nullable EntityPlayer shooter, ItemStack thrower, Fluid fluid) {
            IBlockState state = world.getBlockState(mop.getBlockPos());
            if (state.getBlock() == Blocks.STONE || state.getBlock() == Blocks.COBBLESTONE || state.getBlock() == Blocks.STONEBRICK || state.getBlock() == Blocks.MOSSY_COBBLESTONE)
                world.setBlockState(mop.getBlockPos(), Blocks.GRAVEL.getDefaultState());
        }
    });
    ChemthrowerHandler.registerEffect("mana", new ChemthrowerEffect_RandomTeleport(null, 0, .01f));
    final Item itemPhyto = Item.REGISTRY.getObject(new ResourceLocation("thermalfoundation:fertilizer"));
    if (itemPhyto != null)
        BelljarHandler.registerItemFertilizer(new ItemFertilizerHandler() {

            @Override
            public boolean isValid(@Nullable ItemStack fertilizer) {
                return !fertilizer.isEmpty() && fertilizer.getItem() == itemPhyto;
            }

            @Override
            public float getGrowthMultiplier(ItemStack fertilizer, ItemStack seed, ItemStack soil, TileEntity tile) {
                return BelljarHandler.solidFertilizerModifier * (1.5f + (.25f * fertilizer.getMetadata()));
            }
        });
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) DamageSource(net.minecraft.util.DamageSource) ChemthrowerEffect_Damage(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage) PotionEffect(net.minecraft.potion.PotionEffect) Fluid(net.minecraftforge.fluids.Fluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion) ChemthrowerEffect_RandomTeleport(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_RandomTeleport) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) Item(net.minecraft.item.Item) EntityCreeper(net.minecraft.entity.monster.EntityCreeper) ItemFertilizerHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.ItemFertilizerHandler) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 59 with DamageSource

use of net.minecraft.util.DamageSource in project ImmersiveEngineering by BluSunrize.

the class ThaumcraftHelper method init.

@Override
public void init() {
    FMLInterModComms.sendMessage("thaumcraft", "harvestStackedCrop", new ItemStack(IEContent.blockCrop, 5));
    Potion potion_ward = Potion.getPotionFromResourceLocation("thaumcraft:warpward");
    if (potion_ward != null)
        ChemthrowerHandler.registerEffect("purifying_fluid", new ChemthrowerEffect_Potion(null, 0, potion_ward, 100, 0));
    try {
        Class c_DamageSourceThaumcraft = Class.forName("thaumcraft.api.damagesource.DamageSourceThaumcraft");
        if (c_DamageSourceThaumcraft != null) {
            DamageSource dmg_dissolve = (DamageSource) c_DamageSourceThaumcraft.getField("dissolve").get(null);
            ChemthrowerHandler.registerEffect("liquid_death", new ChemthrowerEffect_Damage(dmg_dissolve, 4));
        }
    } catch (Exception e) {
    }
    try {
        Class c_TileSmelter = Class.forName("thaumcraft.common.tiles.essentia.TileSmelter");
        if (c_TileSmelter != null)
            ExternalHeaterHandler.registerHeatableAdapter(c_TileSmelter, new AlchemyFurnaceAdapter(c_TileSmelter));
    } catch (Exception e) {
    }
}
Also used : DamageSource(net.minecraft.util.DamageSource) ChemthrowerEffect_Damage(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion) Potion(net.minecraft.potion.Potion) ItemStack(net.minecraft.item.ItemStack) ChemthrowerEffect_Potion(blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)

Example 60 with DamageSource

use of net.minecraft.util.DamageSource in project Wizardry by TeamWizardry.

the class ModuleEffectSonic method damageEntity.

private void damageEntity(EntityLivingBase target, Entity caster, float damage) {
    int invTime = target.hurtResistantTime;
    target.hurtResistantTime = 0;
    if (caster instanceof EntityLivingBase) {
        ((EntityLivingBase) caster).setLastAttackedEntity(target);
        if (caster instanceof EntityPlayer)
            target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) caster).setMagicDamage(), damage);
        else
            target.attackEntityFrom(new DamageSource("generic").setMagicDamage(), damage);
    } else
        target.attackEntityFrom(new DamageSource("generic").setMagicDamage(), damage);
    target.hurtResistantTime = invTime;
}
Also used : DamageSource(net.minecraft.util.DamageSource) EntityLivingBase(net.minecraft.entity.EntityLivingBase) 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