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