001package net.minecraft.client.renderer.entity;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.renderer.OpenGlHelper;
006import net.minecraft.client.renderer.Tessellator;
007import net.minecraft.entity.Entity;
008import net.minecraft.entity.item.EntityPainting;
009import net.minecraft.util.EnumArt;
010import net.minecraft.util.MathHelper;
011import org.lwjgl.opengl.GL11;
012import org.lwjgl.opengl.GL12;
013
014@SideOnly(Side.CLIENT)
015public class RenderPainting extends Render
016{
017    public void renderThePainting(EntityPainting par1EntityPainting, double par2, double par4, double par6, float par8, float par9)
018    {
019        GL11.glPushMatrix();
020        GL11.glTranslatef((float)par2, (float)par4, (float)par6);
021        GL11.glRotatef(par8, 0.0F, 1.0F, 0.0F);
022        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
023        this.loadTexture("/art/kz.png");
024        EnumArt enumart = par1EntityPainting.art;
025        float f2 = 0.0625F;
026        GL11.glScalef(f2, f2, f2);
027        this.func_77010_a(par1EntityPainting, enumart.sizeX, enumart.sizeY, enumart.offsetX, enumart.offsetY);
028        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
029        GL11.glPopMatrix();
030    }
031
032    private void func_77010_a(EntityPainting par1EntityPainting, int par2, int par3, int par4, int par5)
033    {
034        float f = (float)(-par2) / 2.0F;
035        float f1 = (float)(-par3) / 2.0F;
036        float f2 = 0.5F;
037        float f3 = 0.75F;
038        float f4 = 0.8125F;
039        float f5 = 0.0F;
040        float f6 = 0.0625F;
041        float f7 = 0.75F;
042        float f8 = 0.8125F;
043        float f9 = 0.001953125F;
044        float f10 = 0.001953125F;
045        float f11 = 0.7519531F;
046        float f12 = 0.7519531F;
047        float f13 = 0.0F;
048        float f14 = 0.0625F;
049
050        for (int i1 = 0; i1 < par2 / 16; ++i1)
051        {
052            for (int j1 = 0; j1 < par3 / 16; ++j1)
053            {
054                float f15 = f + (float)((i1 + 1) * 16);
055                float f16 = f + (float)(i1 * 16);
056                float f17 = f1 + (float)((j1 + 1) * 16);
057                float f18 = f1 + (float)(j1 * 16);
058                this.func_77008_a(par1EntityPainting, (f15 + f16) / 2.0F, (f17 + f18) / 2.0F);
059                float f19 = (float)(par4 + par2 - i1 * 16) / 256.0F;
060                float f20 = (float)(par4 + par2 - (i1 + 1) * 16) / 256.0F;
061                float f21 = (float)(par5 + par3 - j1 * 16) / 256.0F;
062                float f22 = (float)(par5 + par3 - (j1 + 1) * 16) / 256.0F;
063                Tessellator tessellator = Tessellator.instance;
064                tessellator.startDrawingQuads();
065                tessellator.setNormal(0.0F, 0.0F, -1.0F);
066                tessellator.addVertexWithUV((double)f15, (double)f18, (double)(-f2), (double)f20, (double)f21);
067                tessellator.addVertexWithUV((double)f16, (double)f18, (double)(-f2), (double)f19, (double)f21);
068                tessellator.addVertexWithUV((double)f16, (double)f17, (double)(-f2), (double)f19, (double)f22);
069                tessellator.addVertexWithUV((double)f15, (double)f17, (double)(-f2), (double)f20, (double)f22);
070                tessellator.setNormal(0.0F, 0.0F, 1.0F);
071                tessellator.addVertexWithUV((double)f15, (double)f17, (double)f2, (double)f3, (double)f5);
072                tessellator.addVertexWithUV((double)f16, (double)f17, (double)f2, (double)f4, (double)f5);
073                tessellator.addVertexWithUV((double)f16, (double)f18, (double)f2, (double)f4, (double)f6);
074                tessellator.addVertexWithUV((double)f15, (double)f18, (double)f2, (double)f3, (double)f6);
075                tessellator.setNormal(0.0F, 1.0F, 0.0F);
076                tessellator.addVertexWithUV((double)f15, (double)f17, (double)(-f2), (double)f7, (double)f9);
077                tessellator.addVertexWithUV((double)f16, (double)f17, (double)(-f2), (double)f8, (double)f9);
078                tessellator.addVertexWithUV((double)f16, (double)f17, (double)f2, (double)f8, (double)f10);
079                tessellator.addVertexWithUV((double)f15, (double)f17, (double)f2, (double)f7, (double)f10);
080                tessellator.setNormal(0.0F, -1.0F, 0.0F);
081                tessellator.addVertexWithUV((double)f15, (double)f18, (double)f2, (double)f7, (double)f9);
082                tessellator.addVertexWithUV((double)f16, (double)f18, (double)f2, (double)f8, (double)f9);
083                tessellator.addVertexWithUV((double)f16, (double)f18, (double)(-f2), (double)f8, (double)f10);
084                tessellator.addVertexWithUV((double)f15, (double)f18, (double)(-f2), (double)f7, (double)f10);
085                tessellator.setNormal(-1.0F, 0.0F, 0.0F);
086                tessellator.addVertexWithUV((double)f15, (double)f17, (double)f2, (double)f12, (double)f13);
087                tessellator.addVertexWithUV((double)f15, (double)f18, (double)f2, (double)f12, (double)f14);
088                tessellator.addVertexWithUV((double)f15, (double)f18, (double)(-f2), (double)f11, (double)f14);
089                tessellator.addVertexWithUV((double)f15, (double)f17, (double)(-f2), (double)f11, (double)f13);
090                tessellator.setNormal(1.0F, 0.0F, 0.0F);
091                tessellator.addVertexWithUV((double)f16, (double)f17, (double)(-f2), (double)f12, (double)f13);
092                tessellator.addVertexWithUV((double)f16, (double)f18, (double)(-f2), (double)f12, (double)f14);
093                tessellator.addVertexWithUV((double)f16, (double)f18, (double)f2, (double)f11, (double)f14);
094                tessellator.addVertexWithUV((double)f16, (double)f17, (double)f2, (double)f11, (double)f13);
095                tessellator.draw();
096            }
097        }
098    }
099
100    private void func_77008_a(EntityPainting par1EntityPainting, float par2, float par3)
101    {
102        int i = MathHelper.floor_double(par1EntityPainting.posX);
103        int j = MathHelper.floor_double(par1EntityPainting.posY + (double)(par3 / 16.0F));
104        int k = MathHelper.floor_double(par1EntityPainting.posZ);
105
106        if (par1EntityPainting.hangingDirection == 2)
107        {
108            i = MathHelper.floor_double(par1EntityPainting.posX + (double)(par2 / 16.0F));
109        }
110
111        if (par1EntityPainting.hangingDirection == 1)
112        {
113            k = MathHelper.floor_double(par1EntityPainting.posZ - (double)(par2 / 16.0F));
114        }
115
116        if (par1EntityPainting.hangingDirection == 0)
117        {
118            i = MathHelper.floor_double(par1EntityPainting.posX - (double)(par2 / 16.0F));
119        }
120
121        if (par1EntityPainting.hangingDirection == 3)
122        {
123            k = MathHelper.floor_double(par1EntityPainting.posZ + (double)(par2 / 16.0F));
124        }
125
126        int l = this.renderManager.worldObj.getLightBrightnessForSkyBlocks(i, j, k, 0);
127        int i1 = l % 65536;
128        int j1 = l / 65536;
129        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)i1, (float)j1);
130        GL11.glColor3f(1.0F, 1.0F, 1.0F);
131    }
132
133    /**
134     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
135     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
136     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
137     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
138     */
139    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
140    {
141        this.renderThePainting((EntityPainting)par1Entity, par2, par4, par6, par8, par9);
142    }
143}