Search in sources :

Example 36 with EntityLiving

use of net.minecraft.entity.EntityLiving in project MineFactoryReloaded by powercrystals.

the class ItemSafariNet method spawnCreature.

private static Entity spawnCreature(World world, int mobId, double x, double y, double z) {
    if (!EntityList.entityEggs.containsKey(Integer.valueOf(mobId))) {
        return null;
    } else {
        Entity e = EntityList.createEntityByID(mobId, world);
        if (e != null) {
            e.setLocationAndAngles(x, y, z, world.rand.nextFloat() * 360.0F, 0.0F);
            ((EntityLiving) e).initCreature();
            world.spawnEntityInWorld(e);
            ((EntityLiving) e).playLivingSound();
        }
        return e;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving)

Example 37 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ICBM-Classic by BuiltBrokenModding.

the class EntityFragments method onUpdate.

/** Called to update the entity's position/logic. */
@Override
public void onUpdate() {
    super.onUpdate();
    if (this.isAnvil) {
        ArrayList entities = new ArrayList(this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox));
        Iterator var5 = entities.iterator();
        while (var5.hasNext()) {
            Entity entity = (Entity) var5.next();
            entity.attackEntityFrom(DamageSource.anvil, 15);
        }
    }
    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
        float var1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.prevRotationYaw = this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
        this.prevRotationPitch = this.rotationPitch = (float) (Math.atan2(this.motionY, var1) * 180.0D / Math.PI);
    }
    Block var15 = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
    if (var15 != Blocks.air) {
        var15.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile);
        AxisAlignedBB var2 = var15.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile);
        if (var2 != null && var2.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
            this.inGround = true;
        }
    }
    if (this.arrowShake > 0) {
        --this.arrowShake;
    }
    if (this.inGround) {
        var15 = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
        int var18 = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
        if (var15 == this.inTile && var18 == this.inData) {
            if (this.isExplosive) {
                explode();
            } else {
                if (this.isAnvil && this.worldObj.rand.nextFloat() > 0.5f) {
                    this.worldObj.playAuxSFX(1022, (int) this.posX, (int) this.posY, (int) this.posZ, 0);
                }
                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;
        Vec3 var16 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
        Vec3 var17 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        MovingObjectPosition movingObjPos = this.worldObj.rayTraceBlocks(var16, var17, false);
        var16 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
        var17 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
        if (movingObjPos != null) {
            var17 = Vec3.createVectorHelper(movingObjPos.hitVec.xCoord, movingObjPos.hitVec.yCoord, movingObjPos.hitVec.zCoord);
        }
        Entity var4 = null;
        List var5 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
        double var6 = 0.0D;
        int var8;
        float var10;
        for (var8 = 0; var8 < var5.size(); ++var8) {
            Entity var9 = (Entity) var5.get(var8);
            if (var9.canBeCollidedWith() && (this.ticksInAir >= 5)) {
                var10 = 0.3F;
                AxisAlignedBB var11 = var9.boundingBox.expand(var10, var10, var10);
                MovingObjectPosition var12 = var11.calculateIntercept(var16, var17);
                if (var12 != null) {
                    double var13 = var16.distanceTo(var12.hitVec);
                    if (var13 < var6 || var6 == 0.0D) {
                        var4 = var9;
                        var6 = var13;
                    }
                }
            }
        }
        if (var4 != null) {
            movingObjPos = new MovingObjectPosition(var4);
        }
        float speed;
        if (movingObjPos != null) {
            if (movingObjPos.entityHit != null) {
                speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
                int damage = (int) Math.ceil(speed * this.damage);
                if (this.arrowCritical) {
                    damage += this.rand.nextInt(damage / 2 + 2);
                }
                DamageSource damageSource = (new EntityDamageSourceIndirect("arrow", this, this)).setProjectile();
                if (this.isBurning()) {
                    movingObjPos.entityHit.setFire(5);
                }
                if (movingObjPos.entityHit.attackEntityFrom(damageSource, damage)) {
                    if (movingObjPos.entityHit instanceof EntityLiving) {
                        EntityLiving var24 = (EntityLiving) movingObjPos.entityHit;
                        if (!this.worldObj.isRemote) {
                            var24.setArrowCountInEntity(var24.getArrowCountInEntity() + 1);
                        }
                        if (this.knowBackStrength > 0) {
                            float var21 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
                            if (var21 > 0.0F) {
                                movingObjPos.entityHit.addVelocity(this.motionX * this.knowBackStrength * 0.6000000238418579D / var21, 0.1D, this.motionZ * this.knowBackStrength * 0.6000000238418579D / var21);
                            }
                        }
                    }
                    this.worldObj.playSoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
                    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 {
                this.xTile = movingObjPos.blockX;
                this.yTile = movingObjPos.blockY;
                this.zTile = movingObjPos.blockZ;
                this.inTile = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
                this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
                this.motionX = ((float) (movingObjPos.hitVec.xCoord - this.posX));
                this.motionY = ((float) (movingObjPos.hitVec.yCoord - this.posY));
                this.motionZ = ((float) (movingObjPos.hitVec.zCoord - this.posZ));
                speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
                this.posX -= this.motionX / speed * 0.05000000074505806D;
                this.posY -= this.motionY / speed * 0.05000000074505806D;
                this.posZ -= this.motionZ / speed * 0.05000000074505806D;
                this.worldObj.playSoundAtEntity(this, "random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
                this.inGround = true;
                this.arrowShake = 7;
                this.arrowCritical = false;
            }
        }
        if (this.arrowCritical) {
            for (var8 = 0; var8 < 4; ++var8) {
                this.worldObj.spawnParticle("crit", this.posX + this.motionX * var8 / 4.0D, this.posY + this.motionY * var8 / 4.0D, this.posZ + this.motionZ * var8 / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
            }
        }
        this.posX += this.motionX;
        this.posY += this.motionY;
        this.posZ += this.motionZ;
        speed = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
        this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
        for (this.rotationPitch = (float) (Math.atan2(this.motionY, speed) * 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 var23 = 0.99F;
        var10 = 0.05F;
        if (this.isInWater()) {
            for (int var25 = 0; var25 < 4; ++var25) {
                float var24 = 0.25F;
                this.worldObj.spawnParticle("bubble", this.posX - this.motionX * var24, this.posY - this.motionY * var24, this.posZ - this.motionZ * var24, this.motionX, this.motionY, this.motionZ);
            }
            var23 = 0.8F;
        }
        this.motionX *= var23;
        this.motionY *= var23;
        this.motionZ *= var23;
        this.motionY -= var10;
        this.setPosition(this.posX, this.posY, this.posZ);
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Block(net.minecraft.block.Block) List(java.util.List) ArrayList(java.util.ArrayList)

Example 38 with EntityLiving

use of net.minecraft.entity.EntityLiving in project ICBM-Classic by BuiltBrokenModding.

the class BlastEndothermic method doPostExplode.

@Override
public void doPostExplode() {
    super.doPostExplode();
    if (!this.world().isRemote) {
        if (this.canFocusBeam(this.world(), position) && this.thread.isComplete) {
            /*
                 * Freeze all nearby entities.
                 */
            List<EntityLiving> livingEntities = world().getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox(position.x() - getRadius(), position.y() - getRadius(), position.z() - getRadius(), position.x() + getRadius(), position.y() + getRadius(), position.z() + getRadius()));
            if (livingEntities != null && !livingEntities.isEmpty()) {
                Iterator<EntityLiving> it = livingEntities.iterator();
                while (it.hasNext()) {
                    EntityLiving entity = it.next();
                    if (entity != null && entity.isEntityAlive()) {
                        entity.addPotionEffect(new CustomPotionEffect(PoisonFrostBite.INSTANCE.getId(), 60 * 20, 1, null));
                        entity.addPotionEffect(new PotionEffect(Potion.confusion.id, 10 * 20, 2));
                        entity.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 120 * 20, 2));
                        entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 120 * 20, 4));
                    }
                }
            }
            for (Pos targetPosition : this.thread.results) {
                double distanceFromCenter = position.distance(targetPosition);
                if (distanceFromCenter > this.getRadius()) {
                    continue;
                }
                /*
                     * Reduce the chance of setting blocks on fire based on distance from center.
                     */
                double chance = this.getRadius() - (Math.random() * distanceFromCenter);
                if (chance > distanceFromCenter * 0.55) {
                    /*
                         * Place down ice blocks.
                         */
                    Block blockID = this.world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                    if (blockID.blockMaterial == Material.water) {
                        this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.ice, 0, 3);
                    } else if (blockID == Blocks.fire || blockID == Blocks.flowing_lava || blockID == Blocks.lava) {
                        this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.snow, 0, 3);
                    } else {
                        Block blockBellow = world().getBlock(targetPosition.xi(), targetPosition.yi() - 1, targetPosition.zi());
                        if ((blockID.isReplaceable(world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi())) && blockBellow.getMaterial().isSolid() && blockBellow.isSideSolid(world(), targetPosition.xi(), targetPosition.yi() - 1, targetPosition.zi(), ForgeDirection.UP)) {
                            if (MathUtility.rand.nextBoolean()) {
                                this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.ice, 0, 3);
                            } else {
                                this.world().setBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), Blocks.snow, 0, 3);
                            }
                        }
                    }
                }
            }
            this.world().playSoundEffect(position.x() + 0.5D, position.y() + 0.5D, position.z() + 0.5D, ICBMClassic.PREFIX + "redmatter", 6.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 1F);
        }
        if (!world().getGameRules().getGameRuleBooleanValue("doDaylightCycle")) {
            this.world().setWorldTime(1200);
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) CustomPotionEffect(icbm.classic.content.potion.CustomPotionEffect) PotionEffect(net.minecraft.potion.PotionEffect) Pos(com.builtbroken.mc.imp.transform.vector.Pos) Block(net.minecraft.block.Block) CustomPotionEffect(icbm.classic.content.potion.CustomPotionEffect)

Example 39 with EntityLiving

use of net.minecraft.entity.EntityLiving in project Pearcel-Mod by MiningMark48.

the class ItemGlowingPearcel method onItemUseFinish.

@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
    double x = entityLiving.posX;
    double y = entityLiving.posY;
    double z = entityLiving.posZ;
    int range = ConfigurationHandler.glowingPearcelRange;
    List<EntityLiving> items = entityLiving.world.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
    for (EntityLiving e : items) {
        e.addPotionEffect(new PotionEffect(MobEffects.GLOWING, 1500, 0));
    }
    if (entityLiving instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) entityLiving;
        entityplayer.getFoodStats().addStats(this, stack);
        worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_PLAYER_BURP, SoundCategory.PLAYERS, 0.5F, worldIn.rand.nextFloat() * 0.1F + 0.9F);
        this.onFoodEaten(stack, worldIn, entityplayer);
        entityplayer.addStat(StatList.getObjectUseStats(this));
        entityplayer.addPotionEffect(new PotionEffect(MobEffects.NIGHT_VISION, 1500, 0));
        if (!entityplayer.isCreative()) {
            --stack.stackSize;
        }
    }
    return stack;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLiving(net.minecraft.entity.EntityLiving) PotionEffect(net.minecraft.potion.PotionEffect) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 40 with EntityLiving

use of net.minecraft.entity.EntityLiving in project Pearcel-Mod by MiningMark48.

the class ItemLivingMagnet method doUpdate.

private void doUpdate(ItemStack stack, World world, Entity entity) {
    int range = ConfigurationHandler.pearcelMagnetRange;
    float pullSpeed = ConfigurationHandler.pearcelMagnetPullSpeed;
    if (!stack.hasTagCompound()) {
        stack.setTagCompound(new NBTTagCompound());
        stack.getTagCompound().setBoolean("enabled", false);
        stack.getTagCompound().setString("mode", "Attracts");
    }
    if (entity instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) entity;
        if (stack.getTagCompound().getBoolean("enabled") && hasEnoughEnergy(stack, ConfigurationHandler.rfPerTick_livingMagnet, player)) {
            double x = player.posX;
            double y = player.posY;
            double z = player.posZ;
            List<EntityLiving> entities = entity.world.getEntitiesWithinAABB(EntityLiving.class, new AxisAlignedBB(x - range, y - range, z - range, x + range, y + range, z + range));
            for (EntityLiving e : entities) {
                if (!player.isSneaking()) {
                    if (stack.getTagCompound().getString("mode").equalsIgnoreCase("attracts")) {
                        //Attracts
                        e.addVelocity((x - e.posX) * pullSpeed, (y - e.posY) * pullSpeed, (z - e.posZ) * pullSpeed);
                    } else {
                        //Repels
                        e.addVelocity((e.posX - x) * pullSpeed, (e.posY - y) * pullSpeed, (e.posZ - z) * pullSpeed);
                    }
                    if (ConfigurationHandler.pearcelMagnetParticles) {
                        world.spawnParticle(EnumParticleTypes.SPELL_INSTANT, e.posX, e.posY + 0.3, e.posZ, 0.0D, 0.0D, 0.0D);
                    }
                }
                useEnergy(stack, ConfigurationHandler.rfPerTick_livingMagnet, false, player);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLiving(net.minecraft.entity.EntityLiving) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

EntityLiving (net.minecraft.entity.EntityLiving)45 Entity (net.minecraft.entity.Entity)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 ItemStack (net.minecraft.item.ItemStack)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 World (net.minecraft.world.World)6 Block (net.minecraft.block.Block)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 PotionEffect (net.minecraft.potion.PotionEffect)4 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 EntityCreature (net.minecraft.entity.EntityCreature)3 BlockPos (net.minecraft.util.math.BlockPos)3 Pos (com.builtbroken.mc.imp.transform.vector.Pos)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityItem (net.minecraft.entity.item.EntityItem)2 EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)2 EntityMob (net.minecraft.entity.monster.EntityMob)2