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