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