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