    001    package net.minecraft.client.renderer.tileentity;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.block.Block;
    006    import net.minecraft.client.renderer.RenderBlocks;
    007    import net.minecraft.client.renderer.Tessellator;
    008    import net.minecraft.client.renderer.entity.Render;
    009    import net.minecraft.client.renderer.entity.RenderItem;
    010    import net.minecraft.client.renderer.entity.RenderManager;
    011    import net.minecraft.client.renderer.texturefx.TextureCompassFX;
    012    import net.minecraft.entity.Entity;
    013    import net.minecraft.entity.item.EntityItem;
    014    import net.minecraft.entity.item.EntityItemFrame;
    015    import net.minecraft.entity.player.EntityPlayer;
    016    import net.minecraft.item.Item;
    017    import net.minecraft.item.ItemStack;
    018    import net.minecraft.util.Direction;
    019    import net.minecraft.util.MathHelper;
    020    import net.minecraft.world.storage.MapData;
    021    import org.lwjgl.opengl.GL11;
    022
    023    @SideOnly(Side.CLIENT)
    024    public class RenderItemFrame extends Render
    025    {
    026        private final RenderBlocks field_82405_a = new RenderBlocks();
    027
    028        public void func_82404_a(EntityItemFrame par1EntityItemFrame, double par2, double par4, double par6, float par8, float par9)
    029        {
    030            GL11.glPushMatrix();
    031            float var10 = (float)(par1EntityItemFrame.posX - par2) - 0.5F;
    032            float var11 = (float)(par1EntityItemFrame.posY - par4) - 0.5F;
    033            float var12 = (float)(par1EntityItemFrame.posZ - par6) - 0.5F;
    034            int var13 = par1EntityItemFrame.xPosition + Direction.offsetX[par1EntityItemFrame.hangingDirection];
    035            int var14 = par1EntityItemFrame.yPosition;
    036            int var15 = par1EntityItemFrame.zPosition + Direction.offsetZ[par1EntityItemFrame.hangingDirection];
    037            GL11.glTranslatef((float)var13 - var10, (float)var14 - var11, (float)var15 - var12);
    038            this.renderFrameItemAsBlock(par1EntityItemFrame);
    039            this.func_82402_b(par1EntityItemFrame);
    040            GL11.glPopMatrix();
    041        }
    042
    043        /**
    044         * Render the item frame's item as a block.
    045         */
    046        private void renderFrameItemAsBlock(EntityItemFrame par1EntityItemFrame)
    047        {
    048            GL11.glPushMatrix();
    049            GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.renderManager.renderEngine.getTexture("/terrain.png"));
    050            GL11.glRotatef(par1EntityItemFrame.rotationYaw, 0.0F, 1.0F, 0.0F);
    051            Block var2 = Block.planks;
    052            float var3 = 0.0625F;
    053            float var4 = 0.75F;
    054            float var5 = var4 / 2.0F;
    055            GL11.glPushMatrix();
    056            this.field_82405_a.func_83019_b(0.0D, (double)(0.5F - var5 + 0.0625F), (double)(0.5F - var5 + 0.0625F), (double)(var3 * 0.5F), (double)(0.5F + var5 - 0.0625F), (double)(0.5F + var5 - 0.0625F));
    057            this.field_82405_a.func_82774_a(185);
    058            this.field_82405_a.renderBlockAsItem(var2, 0, 1.0F);
    059            this.field_82405_a.clearOverrideBlockTexture();
    060            this.field_82405_a.func_83017_b();
    061            GL11.glPopMatrix();
    062            this.field_82405_a.func_82774_a(214);
    063            GL11.glPushMatrix();
    064            this.field_82405_a.func_83019_b(0.0D, (double)(0.5F - var5), (double)(0.5F - var5), (double)(var3 + 1.0E-4F), (double)(var3 + 0.5F - var5), (double)(0.5F + var5));
    065            this.field_82405_a.renderBlockAsItem(var2, 0, 1.0F);
    066            GL11.glPopMatrix();
    067            GL11.glPushMatrix();
    068            this.field_82405_a.func_83019_b(0.0D, (double)(0.5F + var5 - var3), (double)(0.5F - var5), (double)(var3 + 1.0E-4F), (double)(0.5F + var5), (double)(0.5F + var5));
    069            this.field_82405_a.renderBlockAsItem(var2, 0, 1.0F);
    070            GL11.glPopMatrix();
    071            GL11.glPushMatrix();
    072            this.field_82405_a.func_83019_b(0.0D, (double)(0.5F - var5), (double)(0.5F - var5), (double)var3, (double)(0.5F + var5), (double)(var3 + 0.5F - var5));
    073            this.field_82405_a.renderBlockAsItem(var2, 0, 1.0F);
    074            GL11.glPopMatrix();
    075            GL11.glPushMatrix();
    076            this.field_82405_a.func_83019_b(0.0D, (double)(0.5F - var5), (double)(0.5F + var5 - var3), (double)var3, (double)(0.5F + var5), (double)(0.5F + var5));
    077            this.field_82405_a.renderBlockAsItem(var2, 0, 1.0F);
    078            GL11.glPopMatrix();
    079            this.field_82405_a.func_83017_b();
    080            this.field_82405_a.clearOverrideBlockTexture();
    081            GL11.glPopMatrix();
    082        }
    083
    084        private void func_82402_b(EntityItemFrame par1EntityItemFrame)
    085        {
    086            ItemStack var2 = par1EntityItemFrame.getDisplayedItem();
    087
    088            if (var2 != null)
    089            {
    090                EntityItem var3 = new EntityItem(par1EntityItemFrame.worldObj, 0.0D, 0.0D, 0.0D, var2);
    091                var3.item.stackSize = 1;
    092                var3.hoverStart = 0.0F;
    093                GL11.glPushMatrix();
    094                GL11.glTranslatef(-0.453125F * (float)Direction.offsetX[par1EntityItemFrame.hangingDirection], -0.18F, -0.453125F * (float)Direction.offsetZ[par1EntityItemFrame.hangingDirection]);
    095                GL11.glRotatef(180.0F + par1EntityItemFrame.rotationYaw, 0.0F, 1.0F, 0.0F);
    096                GL11.glRotatef((float)(-90 * par1EntityItemFrame.getRotation()), 0.0F, 0.0F, 1.0F);
    097
    098                switch (par1EntityItemFrame.getRotation())
    099                {
    100                    case 1:
    101                        GL11.glTranslatef(-0.16F, -0.16F, 0.0F);
    102                        break;
    103                    case 2:
    104                        GL11.glTranslatef(0.0F, -0.32F, 0.0F);
    105                        break;
    106                    case 3:
    107                        GL11.glTranslatef(0.16F, -0.16F, 0.0F);
    108                }
    109
    110                if (var3.item.getItem() == Item.map)
    111                {
    112                    this.renderManager.renderEngine.bindTexture(this.renderManager.renderEngine.getTexture("/misc/mapbg.png"));
    113                    Tessellator var4 = Tessellator.instance;
    114                    GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
    115                    GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
    116                    GL11.glScalef(0.00390625F, 0.00390625F, 0.00390625F);
    117                    GL11.glTranslatef(-65.0F, -107.0F, -3.0F);
    118                    GL11.glNormal3f(0.0F, 0.0F, -1.0F);
    119                    var4.startDrawingQuads();
    120                    byte var5 = 7;
    121                    var4.addVertexWithUV((double)(0 - var5), (double)(128 + var5), 0.0D, 0.0D, 1.0D);
    122                    var4.addVertexWithUV((double)(128 + var5), (double)(128 + var5), 0.0D, 1.0D, 1.0D);
    123                    var4.addVertexWithUV((double)(128 + var5), (double)(0 - var5), 0.0D, 1.0D, 0.0D);
    124                    var4.addVertexWithUV((double)(0 - var5), (double)(0 - var5), 0.0D, 0.0D, 0.0D);
    125                    var4.draw();
    126                    MapData var6 = Item.map.getMapData(var3.item, par1EntityItemFrame.worldObj);
    127
    128                    if (var6 != null)
    129                    {
    130                        this.renderManager.itemRenderer.mapItemRenderer.renderMap((EntityPlayer)null, this.renderManager.renderEngine, var6);
    131                    }
    132                }
    133                else
    134                {
    135                    if (var3.item.getItem() == Item.compass)
    136                    {
    137                        double var8 = TextureCompassFX.field_82391_c.field_76868_i;
    138                        double var10 = TextureCompassFX.field_82391_c.field_76866_j;
    139                        TextureCompassFX.field_82391_c.field_76868_i = 0.0D;
    140                        TextureCompassFX.field_82391_c.field_76866_j = 0.0D;
    141                        TextureCompassFX.func_82390_a(par1EntityItemFrame.posX, par1EntityItemFrame.posZ, (double)MathHelper.wrapAngleTo180_float((float)(180 + par1EntityItemFrame.hangingDirection * 90)), false, true);
    142                        TextureCompassFX.field_82391_c.field_76868_i = var8;
    143                        TextureCompassFX.field_82391_c.field_76866_j = var10;
    144                        this.renderManager.renderEngine.func_82772_a(TextureCompassFX.field_82391_c, -1);
    145                    }
    146
    147                    float var9 = this.renderManager.playerViewY;
    148                    this.renderManager.playerViewY = 180.0F;
    149                    RenderItem.field_82407_g = true;
    150                    RenderManager.instance.renderEntityWithPosYaw(var3, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
    151                    RenderItem.field_82407_g = false;
    152                    this.renderManager.playerViewY = var9;
    153                    GL11.glEnable(GL11.GL_LIGHTING);
    154
    155                    if (var3.item.getItem() == Item.compass)
    156                    {
    157                        TextureCompassFX.field_82391_c.onTick();
    158                        this.renderManager.renderEngine.func_82772_a(TextureCompassFX.field_82391_c, -1);
    159                    }
    160                }
    161
    162                GL11.glPopMatrix();
    163            }
    164        }
    165
    166        /**
    167         * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    168         * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    169         * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    170         * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    171         */
    172        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    173        {
    174            this.func_82404_a((EntityItemFrame)par1Entity, par2, par4, par6, par8, par9);
    175        }
    176    }