001package net.minecraft.client.renderer.tileentity;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import java.util.Calendar;
006import net.minecraft.block.Block;
007import net.minecraft.block.BlockChest;
008import net.minecraft.client.model.ModelChest;
009import net.minecraft.client.model.ModelLargeChest;
010import net.minecraft.tileentity.TileEntity;
011import net.minecraft.tileentity.TileEntityChest;
012import org.lwjgl.opengl.GL11;
013import org.lwjgl.opengl.GL12;
014
015@SideOnly(Side.CLIENT)
016public class TileEntityChestRenderer extends TileEntitySpecialRenderer
017{
018    /** The normal small chest model. */
019    private ModelChest chestModel = new ModelChest();
020
021    /** The large double chest model. */
022    private ModelChest largeChestModel = new ModelLargeChest();
023    private boolean field_92061_d;
024
025    public TileEntityChestRenderer()
026    {
027        Calendar var1 = Calendar.getInstance();
028
029        if (var1.get(2) + 1 == 12 && var1.get(5) >= 24 && var1.get(5) <= 26)
030        {
031            this.field_92061_d = true;
032        }
033    }
034
035    /**
036     * Renders the TileEntity for the chest at a position.
037     */
038    public void renderTileEntityChestAt(TileEntityChest par1TileEntityChest, double par2, double par4, double par6, float par8)
039    {
040        int var9;
041
042        if (!par1TileEntityChest.func_70309_m())
043        {
044            var9 = 0;
045        }
046        else
047        {
048            Block var10 = par1TileEntityChest.getBlockType();
049            var9 = par1TileEntityChest.getBlockMetadata();
050
051            if (var10 != null && var9 == 0)
052            {
053                ((BlockChest)var10).unifyAdjacentChests(par1TileEntityChest.getWorldObj(), par1TileEntityChest.xCoord, par1TileEntityChest.yCoord, par1TileEntityChest.zCoord);
054                var9 = par1TileEntityChest.getBlockMetadata();
055            }
056
057            par1TileEntityChest.checkForAdjacentChests();
058        }
059
060        if (par1TileEntityChest.adjacentChestZNeg == null && par1TileEntityChest.adjacentChestXNeg == null)
061        {
062            ModelChest var14;
063
064            if (par1TileEntityChest.adjacentChestXPos == null && par1TileEntityChest.adjacentChestZPosition == null)
065            {
066                var14 = this.chestModel;
067
068                if (this.field_92061_d)
069                {
070                    this.bindTextureByName("/item/xmaschest.png");
071                }
072                else
073                {
074                    this.bindTextureByName("/item/chest.png");
075                }
076            }
077            else
078            {
079                var14 = this.largeChestModel;
080
081                if (this.field_92061_d)
082                {
083                    this.bindTextureByName("/item/largexmaschest.png");
084                }
085                else
086                {
087                    this.bindTextureByName("/item/largechest.png");
088                }
089            }
090
091            GL11.glPushMatrix();
092            GL11.glEnable(GL12.GL_RESCALE_NORMAL);
093            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
094            GL11.glTranslatef((float)par2, (float)par4 + 1.0F, (float)par6 + 1.0F);
095            GL11.glScalef(1.0F, -1.0F, -1.0F);
096            GL11.glTranslatef(0.5F, 0.5F, 0.5F);
097            short var11 = 0;
098
099            if (var9 == 2)
100            {
101                var11 = 180;
102            }
103
104            if (var9 == 3)
105            {
106                var11 = 0;
107            }
108
109            if (var9 == 4)
110            {
111                var11 = 90;
112            }
113
114            if (var9 == 5)
115            {
116                var11 = -90;
117            }
118
119            if (var9 == 2 && par1TileEntityChest.adjacentChestXPos != null)
120            {
121                GL11.glTranslatef(1.0F, 0.0F, 0.0F);
122            }
123
124            if (var9 == 5 && par1TileEntityChest.adjacentChestZPosition != null)
125            {
126                GL11.glTranslatef(0.0F, 0.0F, -1.0F);
127            }
128
129            GL11.glRotatef((float)var11, 0.0F, 1.0F, 0.0F);
130            GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
131            float var12 = par1TileEntityChest.prevLidAngle + (par1TileEntityChest.lidAngle - par1TileEntityChest.prevLidAngle) * par8;
132            float var13;
133
134            if (par1TileEntityChest.adjacentChestZNeg != null)
135            {
136                var13 = par1TileEntityChest.adjacentChestZNeg.prevLidAngle + (par1TileEntityChest.adjacentChestZNeg.lidAngle - par1TileEntityChest.adjacentChestZNeg.prevLidAngle) * par8;
137
138                if (var13 > var12)
139                {
140                    var12 = var13;
141                }
142            }
143
144            if (par1TileEntityChest.adjacentChestXNeg != null)
145            {
146                var13 = par1TileEntityChest.adjacentChestXNeg.prevLidAngle + (par1TileEntityChest.adjacentChestXNeg.lidAngle - par1TileEntityChest.adjacentChestXNeg.prevLidAngle) * par8;
147
148                if (var13 > var12)
149                {
150                    var12 = var13;
151                }
152            }
153
154            var12 = 1.0F - var12;
155            var12 = 1.0F - var12 * var12 * var12;
156            var14.chestLid.rotateAngleX = -(var12 * (float)Math.PI / 2.0F);
157            var14.renderAll();
158            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
159            GL11.glPopMatrix();
160            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
161        }
162    }
163
164    public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8)
165    {
166        this.renderTileEntityChestAt((TileEntityChest)par1TileEntity, par2, par4, par6, par8);
167    }
168}