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