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