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