001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    
006    public class EntityEnderEye extends Entity
007    {
008        public int field_70226_a = 0;
009    
010        /** 'x' location the eye should float towards. */
011        private double targetX;
012    
013        /** 'y' location the eye should float towards. */
014        private double targetY;
015    
016        /** 'z' location the eye should float towards. */
017        private double targetZ;
018        private int despawnTimer;
019        private boolean shatterOrDrop;
020    
021        public EntityEnderEye(World par1World)
022        {
023            super(par1World);
024            this.setSize(0.25F, 0.25F);
025        }
026    
027        protected void entityInit() {}
028    
029        @SideOnly(Side.CLIENT)
030    
031        /**
032         * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
033         * length * 64 * renderDistanceWeight Args: distance
034         */
035        public boolean isInRangeToRenderDist(double par1)
036        {
037            double var3 = this.boundingBox.getAverageEdgeLength() * 4.0D;
038            var3 *= 64.0D;
039            return par1 < var3 * var3;
040        }
041    
042        public EntityEnderEye(World par1World, double par2, double par4, double par6)
043        {
044            super(par1World);
045            this.despawnTimer = 0;
046            this.setSize(0.25F, 0.25F);
047            this.setPosition(par2, par4, par6);
048            this.yOffset = 0.0F;
049        }
050    
051        /**
052         * The location the eye should float/move towards. Currently used for moving towards the nearest stronghold. Args:
053         * strongholdX, strongholdY, strongholdZ
054         */
055        public void moveTowards(double par1, int par3, double par4)
056        {
057            double var6 = par1 - this.posX;
058            double var8 = par4 - this.posZ;
059            float var10 = MathHelper.sqrt_double(var6 * var6 + var8 * var8);
060    
061            if (var10 > 12.0F)
062            {
063                this.targetX = this.posX + var6 / (double)var10 * 12.0D;
064                this.targetZ = this.posZ + var8 / (double)var10 * 12.0D;
065                this.targetY = this.posY + 8.0D;
066            }
067            else
068            {
069                this.targetX = par1;
070                this.targetY = (double)par3;
071                this.targetZ = par4;
072            }
073    
074            this.despawnTimer = 0;
075            this.shatterOrDrop = this.rand.nextInt(5) > 0;
076        }
077    
078        @SideOnly(Side.CLIENT)
079    
080        /**
081         * Sets the velocity to the args. Args: x, y, z
082         */
083        public void setVelocity(double par1, double par3, double par5)
084        {
085            this.motionX = par1;
086            this.motionY = par3;
087            this.motionZ = par5;
088    
089            if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
090            {
091                float var7 = MathHelper.sqrt_double(par1 * par1 + par5 * par5);
092                this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(par1, par5) * 180.0D / Math.PI);
093                this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(par3, (double)var7) * 180.0D / Math.PI);
094            }
095        }
096    
097        /**
098         * Called to update the entity's position/logic.
099         */
100        public void onUpdate()
101        {
102            this.lastTickPosX = this.posX;
103            this.lastTickPosY = this.posY;
104            this.lastTickPosZ = this.posZ;
105            super.onUpdate();
106            this.posX += this.motionX;
107            this.posY += this.motionY;
108            this.posZ += this.motionZ;
109            float var1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
110            this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
111    
112            for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)var1) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
113            {
114                ;
115            }
116    
117            while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
118            {
119                this.prevRotationPitch += 360.0F;
120            }
121    
122            while (this.rotationYaw - this.prevRotationYaw < -180.0F)
123            {
124                this.prevRotationYaw -= 360.0F;
125            }
126    
127            while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
128            {
129                this.prevRotationYaw += 360.0F;
130            }
131    
132            this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
133            this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
134    
135            if (!this.worldObj.isRemote)
136            {
137                double var2 = this.targetX - this.posX;
138                double var4 = this.targetZ - this.posZ;
139                float var6 = (float)Math.sqrt(var2 * var2 + var4 * var4);
140                float var7 = (float)Math.atan2(var4, var2);
141                double var8 = (double)var1 + (double)(var6 - var1) * 0.0025D;
142    
143                if (var6 < 1.0F)
144                {
145                    var8 *= 0.8D;
146                    this.motionY *= 0.8D;
147                }
148    
149                this.motionX = Math.cos((double)var7) * var8;
150                this.motionZ = Math.sin((double)var7) * var8;
151    
152                if (this.posY < this.targetY)
153                {
154                    this.motionY += (1.0D - this.motionY) * 0.014999999664723873D;
155                }
156                else
157                {
158                    this.motionY += (-1.0D - this.motionY) * 0.014999999664723873D;
159                }
160            }
161    
162            float var10 = 0.25F;
163    
164            if (this.isInWater())
165            {
166                for (int var3 = 0; var3 < 4; ++var3)
167                {
168                    this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double)var10, this.posY - this.motionY * (double)var10, this.posZ - this.motionZ * (double)var10, this.motionX, this.motionY, this.motionZ);
169                }
170            }
171            else
172            {
173                this.worldObj.spawnParticle("portal", this.posX - this.motionX * (double)var10 + this.rand.nextDouble() * 0.6D - 0.3D, this.posY - this.motionY * (double)var10 - 0.5D, this.posZ - this.motionZ * (double)var10 + this.rand.nextDouble() * 0.6D - 0.3D, this.motionX, this.motionY, this.motionZ);
174            }
175    
176            if (!this.worldObj.isRemote)
177            {
178                this.setPosition(this.posX, this.posY, this.posZ);
179                ++this.despawnTimer;
180    
181                if (this.despawnTimer > 80 && !this.worldObj.isRemote)
182                {
183                    this.setDead();
184    
185                    if (this.shatterOrDrop)
186                    {
187                        this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(Item.eyeOfEnder)));
188                    }
189                    else
190                    {
191                        this.worldObj.playAuxSFX(2003, (int)Math.round(this.posX), (int)Math.round(this.posY), (int)Math.round(this.posZ), 0);
192                    }
193                }
194            }
195        }
196    
197        /**
198         * (abstract) Protected helper method to write subclass entity data to NBT.
199         */
200        public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
201    
202        /**
203         * (abstract) Protected helper method to read subclass entity data from NBT.
204         */
205        public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
206    
207        @SideOnly(Side.CLIENT)
208        public float getShadowSize()
209        {
210            return 0.0F;
211        }
212    
213        /**
214         * Gets how bright this entity is.
215         */
216        public float getBrightness(float par1)
217        {
218            return 1.0F;
219        }
220    
221        @SideOnly(Side.CLIENT)
222        public int getBrightnessForRender(float par1)
223        {
224            return 15728880;
225        }
226    
227        /**
228         * If returns false, the item will not inflict any damage against entities.
229         */
230        public boolean canAttackWithItem()
231        {
232            return false;
233        }
234    }