    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.texturefx.TextureCompassFX;
    012import net.minecraft.entity.Entity;
    013import net.minecraft.entity.item.EntityItem;
    014import net.minecraft.entity.item.EntityItemFrame;
    015import net.minecraft.entity.player.EntityPlayer;
    016import net.minecraft.item.Item;
    017import net.minecraft.item.ItemStack;
    018import net.minecraft.util.Direction;
    019import net.minecraft.util.MathHelper;
    020import net.minecraft.world.storage.MapData;
    021import org.lwjgl.opengl.GL11;
    022
    023@SideOnly(Side.CLIENT)
    024public class RenderItemFrame extends Render
    025{
    026    private final RenderBlocks renderBlocksInstance = 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.renderBlocksInstance.overrideBlockBounds(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.renderBlocksInstance.setOverrideBlockTexture(185);
    058        this.renderBlocksInstance.renderBlockAsItem(var2, 0, 1.0F);
    059        this.renderBlocksInstance.clearOverrideBlockTexture();
    060        this.renderBlocksInstance.unlockBlockBounds();
    061        GL11.glPopMatrix();
    062        this.renderBlocksInstance.setOverrideBlockTexture(214);
    063        GL11.glPushMatrix();
    064        this.renderBlocksInstance.overrideBlockBounds(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.renderBlocksInstance.renderBlockAsItem(var2, 0, 1.0F);
    066        GL11.glPopMatrix();
    067        GL11.glPushMatrix();
    068        this.renderBlocksInstance.overrideBlockBounds(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.renderBlocksInstance.renderBlockAsItem(var2, 0, 1.0F);
    070        GL11.glPopMatrix();
    071        GL11.glPushMatrix();
    072        this.renderBlocksInstance.overrideBlockBounds(0.0D, (double)(0.5F - var5), (double)(0.5F - var5), (double)var3, (double)(0.5F + var5), (double)(var3 + 0.5F - var5));
    073        this.renderBlocksInstance.renderBlockAsItem(var2, 0, 1.0F);
    074        GL11.glPopMatrix();
    075        GL11.glPushMatrix();
    076        this.renderBlocksInstance.overrideBlockBounds(0.0D, (double)(0.5F - var5), (double)(0.5F + var5 - var3), (double)var3, (double)(0.5F + var5), (double)(0.5F + var5));
    077        this.renderBlocksInstance.renderBlockAsItem(var2, 0, 1.0F);
    078        GL11.glPopMatrix();
    079        this.renderBlocksInstance.unlockBlockBounds();
    080        this.renderBlocksInstance.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.getEntityItem().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.getEntityItem().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.getEntityItem(), 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.getEntityItem().getItem() == Item.compass)
    136                {
    137                    double var8 = TextureCompassFX.instance.field_76868_i;
    138                    double var9 = TextureCompassFX.instance.field_76866_j;
    139                    TextureCompassFX.instance.field_76868_i = 0.0D;
    140                    TextureCompassFX.instance.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.instance.field_76868_i = var8;
    143                    TextureCompassFX.instance.field_76866_j = var9;
    144                    this.renderManager.renderEngine.updateDynamicTexture(TextureCompassFX.instance, -1);
    145                }
    146
    147                RenderItem.field_82407_g = true;
    148                RenderManager.instance.renderEntityWithPosYaw(var3, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
    149                RenderItem.field_82407_g = false;
    150
    151                if (var3.getEntityItem().getItem() == Item.compass)
    152                {
    153                    TextureCompassFX.instance.onTick();
    154                    this.renderManager.renderEngine.updateDynamicTexture(TextureCompassFX.instance, -1);
    155                }
    156            }
    157
    158            GL11.glPopMatrix();
    159        }
    160    }
    161
    162    /**
    163     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    164     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    165     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    166     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    167     */
    168    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    169    {
    170        this.func_82404_a((EntityItemFrame)par1Entity, par2, par4, par6, par8, par9);
    171    }
    172}