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