001package net.minecraft.client.renderer.texture; 002 003import cpw.mods.fml.relauncher.Side; 004import cpw.mods.fml.relauncher.SideOnly; 005import net.minecraft.client.Minecraft; 006import net.minecraft.util.ChunkCoordinates; 007import net.minecraft.world.World; 008 009@SideOnly(Side.CLIENT) 010public class TextureCompass extends TextureStitched 011{ 012 public static TextureCompass compassTexture; 013 014 /** Current compass heading in radians */ 015 public double currentAngle; 016 017 /** Speed and direction of compass rotation */ 018 public double angleDelta; 019 020 public TextureCompass() 021 { 022 super("compass"); 023 compassTexture = this; 024 } 025 026 public void updateAnimation() 027 { 028 Minecraft minecraft = Minecraft.getMinecraft(); 029 030 if (minecraft.theWorld != null && minecraft.thePlayer != null) 031 { 032 this.updateCompass(minecraft.theWorld, minecraft.thePlayer.posX, minecraft.thePlayer.posZ, (double)minecraft.thePlayer.rotationYaw, false, false); 033 } 034 else 035 { 036 this.updateCompass((World)null, 0.0D, 0.0D, 0.0D, true, false); 037 } 038 } 039 040 /** 041 * Updates the compass based on the given x,z coords and camera direction 042 */ 043 public void updateCompass(World par1World, double par2, double par4, double par6, boolean par8, boolean par9) 044 { 045 double d3 = 0.0D; 046 047 if (par1World != null && !par8) 048 { 049 ChunkCoordinates chunkcoordinates = par1World.getSpawnPoint(); 050 double d4 = (double)chunkcoordinates.posX - par2; 051 double d5 = (double)chunkcoordinates.posZ - par4; 052 par6 %= 360.0D; 053 d3 = -((par6 - 90.0D) * Math.PI / 180.0D - Math.atan2(d5, d4)); 054 055 if (!par1World.provider.isSurfaceWorld()) 056 { 057 d3 = Math.random() * Math.PI * 2.0D; 058 } 059 } 060 061 if (par9) 062 { 063 this.currentAngle = d3; 064 } 065 else 066 { 067 double d6; 068 069 for (d6 = d3 - this.currentAngle; d6 < -Math.PI; d6 += (Math.PI * 2D)) 070 { 071 ; 072 } 073 074 while (d6 >= Math.PI) 075 { 076 d6 -= (Math.PI * 2D); 077 } 078 079 if (d6 < -1.0D) 080 { 081 d6 = -1.0D; 082 } 083 084 if (d6 > 1.0D) 085 { 086 d6 = 1.0D; 087 } 088 089 this.angleDelta += d6 * 0.1D; 090 this.angleDelta *= 0.8D; 091 this.currentAngle += this.angleDelta; 092 } 093 094 int i; 095 096 for (i = (int)((this.currentAngle / (Math.PI * 2D) + 1.0D) * (double)this.textureList.size()) % this.textureList.size(); i < 0; i = (i + this.textureList.size()) % this.textureList.size()) 097 { 098 ; 099 } 100 101 if (i != this.frameCounter) 102 { 103 this.frameCounter = i; 104 this.textureSheet.copyFrom(this.originX, this.originY, (Texture)this.textureList.get(this.frameCounter), this.rotated); 105 } 106 } 107}