001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005 import net.minecraft.client.Minecraft;
006 import net.minecraftforge.client.ForgeHooksClient;
007
008 import org.lwjgl.opengl.GL11;
009
010 @SideOnly(Side.CLIENT)
011 public class TileEntityRendererPiston extends TileEntitySpecialRenderer
012 {
013 /** instance of RenderBlocks used to draw the piston base and extension. */
014 private RenderBlocks blockRenderer;
015
016 public void renderPiston(TileEntityPiston par1TileEntityPiston, double par2, double par4, double par6, float par8)
017 {
018 Block var9 = Block.blocksList[par1TileEntityPiston.getStoredBlockID()];
019
020 if (var9 != null && par1TileEntityPiston.getProgress(par8) < 1.0F)
021 {
022 Tessellator var10 = Tessellator.instance;
023 this.bindTextureByName("/terrain.png");
024 RenderHelper.disableStandardItemLighting();
025 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
026 GL11.glEnable(GL11.GL_BLEND);
027 GL11.glDisable(GL11.GL_CULL_FACE);
028
029 if (Minecraft.isAmbientOcclusionEnabled())
030 {
031 GL11.glShadeModel(GL11.GL_SMOOTH);
032 }
033 else
034 {
035 GL11.glShadeModel(GL11.GL_FLAT);
036 }
037
038 ForgeHooksClient.beforeBlockRender(var9, blockRenderer);
039 var10.startDrawingQuads();
040 var10.setTranslation((double)((float)par2 - (float)par1TileEntityPiston.xCoord + par1TileEntityPiston.getOffsetX(par8)), (double)((float)par4 - (float)par1TileEntityPiston.yCoord + par1TileEntityPiston.getOffsetY(par8)), (double)((float)par6 - (float)par1TileEntityPiston.zCoord + par1TileEntityPiston.getOffsetZ(par8)));
041 var10.setColorOpaque(1, 1, 1);
042
043 if (var9 == Block.pistonExtension && par1TileEntityPiston.getProgress(par8) < 0.5F)
044 {
045 this.blockRenderer.renderPistonExtensionAllFaces(var9, par1TileEntityPiston.xCoord, par1TileEntityPiston.yCoord, par1TileEntityPiston.zCoord, false);
046 }
047 else if (par1TileEntityPiston.shouldRenderHead() && !par1TileEntityPiston.isExtending())
048 {
049 Block.pistonExtension.setHeadTexture(((BlockPistonBase)var9).getPistonExtensionTexture());
050 this.blockRenderer.renderPistonExtensionAllFaces(Block.pistonExtension, par1TileEntityPiston.xCoord, par1TileEntityPiston.yCoord, par1TileEntityPiston.zCoord, par1TileEntityPiston.getProgress(par8) < 0.5F);
051 Block.pistonExtension.clearHeadTexture();
052 var10.setTranslation((double)((float)par2 - (float)par1TileEntityPiston.xCoord), (double)((float)par4 - (float)par1TileEntityPiston.yCoord), (double)((float)par6 - (float)par1TileEntityPiston.zCoord));
053 this.blockRenderer.renderPistonBaseAllFaces(var9, par1TileEntityPiston.xCoord, par1TileEntityPiston.yCoord, par1TileEntityPiston.zCoord);
054 }
055 else
056 {
057 this.blockRenderer.renderBlockAllFaces(var9, par1TileEntityPiston.xCoord, par1TileEntityPiston.yCoord, par1TileEntityPiston.zCoord);
058 }
059
060 var10.setTranslation(0.0D, 0.0D, 0.0D);
061 var10.draw();
062 ForgeHooksClient.afterBlockRender(var9, blockRenderer);
063 RenderHelper.enableStandardItemLighting();
064 }
065 }
066
067 /**
068 * Called when the ingame world being rendered changes (e.g. on world -> nether travel) due to using one renderer
069 * per tile entity type, rather than instance
070 */
071 public void onWorldChange(World par1World)
072 {
073 this.blockRenderer = new RenderBlocks(par1World);
074 }
075
076 public void renderTileEntityAt(TileEntity par1TileEntity, double par2, double par4, double par6, float par8)
077 {
078 this.renderPiston((TileEntityPiston)par1TileEntity, par2, par4, par6, par8);
079 }
080 }