    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.nio.FloatBuffer;
    006    import java.nio.IntBuffer;
    007    import org.lwjgl.opengl.GL11;
    008    import org.lwjgl.util.glu.GLU;
    009
    010    @SideOnly(Side.CLIENT)
    011    public class ActiveRenderInfo
    012    {
    013        /** The calculated view object X coordinate */
    014        public static float objectX = 0.0F;
    015
    016        /** The calculated view object Y coordinate */
    017        public static float objectY = 0.0F;
    018
    019        /** The calculated view object Z coordinate */
    020        public static float objectZ = 0.0F;
    021
    022        /** The current GL viewport */
    023        private static IntBuffer viewport = GLAllocation.createDirectIntBuffer(16);
    024
    025        /** The current GL modelview matrix */
    026        private static FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);
    027
    028        /** The current GL projection matrix */
    029        private static FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);
    030
    031        /** The computed view object coordinates */
    032        private static FloatBuffer objectCoords = GLAllocation.createDirectFloatBuffer(3);
    033
    034        /** The X component of the entity's yaw rotation */
    035        public static float rotationX;
    036
    037        /** The combined X and Z components of the entity's pitch rotation */
    038        public static float rotationXZ;
    039
    040        /** The Z component of the entity's yaw rotation */
    041        public static float rotationZ;
    042
    043        /**
    044         * The Y component (scaled along the Z axis) of the entity's pitch rotation
    045         */
    046        public static float rotationYZ;
    047
    048        /**
    049         * The Y component (scaled along the X axis) of the entity's pitch rotation
    050         */
    051        public static float rotationXY;
    052
    053        /**
    054         * Updates the current render info and camera location based on entity look angles and 1st/3rd person view mode
    055         */
    056        public static void updateRenderInfo(EntityPlayer par0EntityPlayer, boolean par1)
    057        {
    058            GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
    059            GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
    060            GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
    061            float var2 = (float)((viewport.get(0) + viewport.get(2)) / 2);
    062            float var3 = (float)((viewport.get(1) + viewport.get(3)) / 2);
    063            GLU.gluUnProject(var2, var3, 0.0F, modelview, projection, viewport, objectCoords);
    064            objectX = objectCoords.get(0);
    065            objectY = objectCoords.get(1);
    066            objectZ = objectCoords.get(2);
    067            int var4 = par1 ? 1 : 0;
    068            float var5 = par0EntityPlayer.rotationPitch;
    069            float var6 = par0EntityPlayer.rotationYaw;
    070            rotationX = MathHelper.cos(var6 * (float)Math.PI / 180.0F) * (float)(1 - var4 * 2);
    071            rotationZ = MathHelper.sin(var6 * (float)Math.PI / 180.0F) * (float)(1 - var4 * 2);
    072            rotationYZ = -rotationZ * MathHelper.sin(var5 * (float)Math.PI / 180.0F) * (float)(1 - var4 * 2);
    073            rotationXY = rotationX * MathHelper.sin(var5 * (float)Math.PI / 180.0F) * (float)(1 - var4 * 2);
    074            rotationXZ = MathHelper.cos(var5 * (float)Math.PI / 180.0F);
    075        }
    076
    077        /**
    078         * Returns a vector representing the projection along the given entity's view for the given distance
    079         */
    080        public static Vec3 projectViewFromEntity(EntityLiving par0EntityLiving, double par1)
    081        {
    082            double var3 = par0EntityLiving.prevPosX + (par0EntityLiving.posX - par0EntityLiving.prevPosX) * par1;
    083            double var5 = par0EntityLiving.prevPosY + (par0EntityLiving.posY - par0EntityLiving.prevPosY) * par1 + (double)par0EntityLiving.getEyeHeight();
    084            double var7 = par0EntityLiving.prevPosZ + (par0EntityLiving.posZ - par0EntityLiving.prevPosZ) * par1;
    085            double var9 = var3 + (double)(objectX * 1.0F);
    086            double var11 = var5 + (double)(objectY * 1.0F);
    087            double var13 = var7 + (double)(objectZ * 1.0F);
    088            return par0EntityLiving.worldObj.getWorldVec3Pool().getVecFromPool(var9, var11, var13);
    089        }
    090
    091        /**
    092         * Returns the block ID at the current camera location (either air or fluid), taking into account the height of
    093         * fluid blocks
    094         */
    095        public static int getBlockIdAtEntityViewpoint(World par0World, EntityLiving par1EntityLiving, float par2)
    096        {
    097            Vec3 var3 = projectViewFromEntity(par1EntityLiving, (double)par2);
    098            ChunkPosition var4 = new ChunkPosition(var3);
    099            int var5 = par0World.getBlockId(var4.x, var4.y, var4.z);
    100
    101            if (var5 != 0 && Block.blocksList[var5].blockMaterial.isLiquid())
    102            {
    103                float var6 = BlockFluid.getFluidHeightPercent(par0World.getBlockMetadata(var4.x, var4.y, var4.z)) - 0.11111111F;
    104                float var7 = (float)(var4.y + 1) - var6;
    105
    106                if (var3.yCoord >= (double)var7)
    107                {
    108                    var5 = par0World.getBlockId(var4.x, var4.y + 1, var4.z);
    109                }
    110            }
    111
    112            return var5;
    113        }
    114    }