001 package net.minecraft.src;
002
003 import java.util.Random;
004
005 public class TileEntityEnchantmentTable extends TileEntity
006 {
007 /** Used by the render to make the book 'bounce' */
008 public int tickCount;
009
010 /** Value used for determining how the page flip should look. */
011 public float pageFlip;
012
013 /** The last tick's pageFlip value. */
014 public float pageFlipPrev;
015 public float field_70373_d;
016 public float field_70374_e;
017
018 /** The amount that the book is open. */
019 public float bookSpread;
020
021 /** The amount that the book is open. */
022 public float bookSpreadPrev;
023 public float bookRotation2;
024 public float bookRotationPrev;
025 public float bookRotation;
026 private static Random rand = new Random();
027
028 /**
029 * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
030 * ticks and creates a new spawn inside its implementation.
031 */
032 public void updateEntity()
033 {
034 super.updateEntity();
035 this.bookSpreadPrev = this.bookSpread;
036 this.bookRotationPrev = this.bookRotation2;
037 EntityPlayer var1 = this.worldObj.getClosestPlayer((double)((float)this.xCoord + 0.5F), (double)((float)this.yCoord + 0.5F), (double)((float)this.zCoord + 0.5F), 3.0D);
038
039 if (var1 != null)
040 {
041 double var2 = var1.posX - (double)((float)this.xCoord + 0.5F);
042 double var4 = var1.posZ - (double)((float)this.zCoord + 0.5F);
043 this.bookRotation = (float)Math.atan2(var4, var2);
044 this.bookSpread += 0.1F;
045
046 if (this.bookSpread < 0.5F || rand.nextInt(40) == 0)
047 {
048 float var6 = this.field_70373_d;
049
050 do
051 {
052 this.field_70373_d += (float)(rand.nextInt(4) - rand.nextInt(4));
053 }
054 while (var6 == this.field_70373_d);
055 }
056 }
057 else
058 {
059 this.bookRotation += 0.02F;
060 this.bookSpread -= 0.1F;
061 }
062
063 while (this.bookRotation2 >= (float)Math.PI)
064 {
065 this.bookRotation2 -= ((float)Math.PI * 2F);
066 }
067
068 while (this.bookRotation2 < -(float)Math.PI)
069 {
070 this.bookRotation2 += ((float)Math.PI * 2F);
071 }
072
073 while (this.bookRotation >= (float)Math.PI)
074 {
075 this.bookRotation -= ((float)Math.PI * 2F);
076 }
077
078 while (this.bookRotation < -(float)Math.PI)
079 {
080 this.bookRotation += ((float)Math.PI * 2F);
081 }
082
083 float var7;
084
085 for (var7 = this.bookRotation - this.bookRotation2; var7 >= (float)Math.PI; var7 -= ((float)Math.PI * 2F))
086 {
087 ;
088 }
089
090 while (var7 < -(float)Math.PI)
091 {
092 var7 += ((float)Math.PI * 2F);
093 }
094
095 this.bookRotation2 += var7 * 0.4F;
096
097 if (this.bookSpread < 0.0F)
098 {
099 this.bookSpread = 0.0F;
100 }
101
102 if (this.bookSpread > 1.0F)
103 {
104 this.bookSpread = 1.0F;
105 }
106
107 ++this.tickCount;
108 this.pageFlipPrev = this.pageFlip;
109 float var3 = (this.field_70373_d - this.pageFlip) * 0.4F;
110 float var8 = 0.2F;
111
112 if (var3 < -var8)
113 {
114 var3 = -var8;
115 }
116
117 if (var3 > var8)
118 {
119 var3 = var8;
120 }
121
122 this.field_70374_e += (var3 - this.field_70374_e) * 0.9F;
123 this.pageFlip += this.field_70374_e;
124 }
125 }