    001    package net.minecraft.client.renderer;
    002
    003    import cpw.mods.fml.relauncher.Side;
    004    import cpw.mods.fml.relauncher.SideOnly;
    005    import java.nio.FloatBuffer;
    006    import net.minecraft.util.Vec3;
    007    import org.lwjgl.opengl.GL11;
    008
    009    @SideOnly(Side.CLIENT)
    010    public class RenderHelper
    011    {
    012        /** Float buffer used to set OpenGL material colors */
    013        private static FloatBuffer colorBuffer = GLAllocation.createDirectFloatBuffer(16);
    014        private static final Vec3 field_82884_b = Vec3.createVectorHelper(0.20000000298023224D, 1.0D, -0.699999988079071D).normalize();
    015        private static final Vec3 field_82885_c = Vec3.createVectorHelper(-0.20000000298023224D, 1.0D, 0.699999988079071D).normalize();
    016
    017        /**
    018         * Disables the OpenGL lighting properties enabled by enableStandardItemLighting
    019         */
    020        public static void disableStandardItemLighting()
    021        {
    022            GL11.glDisable(GL11.GL_LIGHTING);
    023            GL11.glDisable(GL11.GL_LIGHT0);
    024            GL11.glDisable(GL11.GL_LIGHT1);
    025            GL11.glDisable(GL11.GL_COLOR_MATERIAL);
    026        }
    027
    028        /**
    029         * Sets the OpenGL lighting properties to the values used when rendering blocks as items
    030         */
    031        public static void enableStandardItemLighting()
    032        {
    033            GL11.glEnable(GL11.GL_LIGHTING);
    034            GL11.glEnable(GL11.GL_LIGHT0);
    035            GL11.glEnable(GL11.GL_LIGHT1);
    036            GL11.glEnable(GL11.GL_COLOR_MATERIAL);
    037            GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
    038            float var0 = 0.4F;
    039            float var1 = 0.6F;
    040            float var2 = 0.0F;
    041            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, setColorBuffer(field_82884_b.xCoord, field_82884_b.yCoord, field_82884_b.zCoord, 0.0D));
    042            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, setColorBuffer(var1, var1, var1, 1.0F));
    043            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
    044            GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, setColorBuffer(var2, var2, var2, 1.0F));
    045            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, setColorBuffer(field_82885_c.xCoord, field_82885_c.yCoord, field_82885_c.zCoord, 0.0D));
    046            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, setColorBuffer(var1, var1, var1, 1.0F));
    047            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
    048            GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, setColorBuffer(var2, var2, var2, 1.0F));
    049            GL11.glShadeModel(GL11.GL_FLAT);
    050            GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, setColorBuffer(var0, var0, var0, 1.0F));
    051        }
    052
    053        /**
    054         * Update and return colorBuffer with the RGBA values passed as arguments
    055         */
    056        private static FloatBuffer setColorBuffer(double par0, double par2, double par4, double par6)
    057        {
    058            return setColorBuffer((float)par0, (float)par2, (float)par4, (float)par6);
    059        }
    060
    061        /**
    062         * Update and return colorBuffer with the RGBA values passed as arguments
    063         */
    064        private static FloatBuffer setColorBuffer(float par0, float par1, float par2, float par3)
    065        {
    066            colorBuffer.clear();
    067            colorBuffer.put(par0).put(par1).put(par2).put(par3);
    068            colorBuffer.flip();
    069            return colorBuffer;
    070        }
    071
    072        /**
    073         * Sets OpenGL lighting for rendering blocks as items inside GUI screens (such as containers).
    074         */
    075        public static void enableGUIStandardItemLighting()
    076        {
    077            GL11.glPushMatrix();
    078            GL11.glRotatef(-30.0F, 0.0F, 1.0F, 0.0F);
    079            GL11.glRotatef(165.0F, 1.0F, 0.0F, 0.0F);
    080            enableStandardItemLighting();
    081            GL11.glPopMatrix();
    082        }
    083    }