content: package thebetweenlands.client.render.tile;
  
  import org.lwjgl.opengl.GL11;
  
  import net.minecraft.client.Minecraft;
  import net.minecraft.client.renderer.BufferBuilder;
  import net.minecraft.client.renderer.GlStateManager;
  import net.minecraft.client.renderer.GlStateManager.CullFace;
  import net.minecraft.client.renderer.Tessellator;
  import net.minecraft.client.renderer.texture.TextureAtlasSprite;
  import net.minecraft.client.renderer.texture.TextureMap;
  import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  import net.minecraft.util.ResourceLocation;
  import net.minecraftforge.fluids.FluidStack;
  import net.minecraftforge.fml.relauncher.Side;
  import net.minecraftforge.fml.relauncher.SideOnly;
  import thebetweenlands.client.render.model.tile.ModelSiltGlassJar;
  import thebetweenlands.common.tile.TileEntityFilteredSiltGlassJar;
  
  @SideOnly(Side.CLIENT)
  public class RenderFilteredSiltGlassJar extends TileEntitySpecialRenderer<TileEntityFilteredSiltGlassJar> {
  
  	public static final ResourceLocation TEXTURE = new ResourceLocation("thebetweenlands:textures/blocks/filtered_silt_glass_jar.png");
  	private final ModelSiltGlassJar model = new ModelSiltGlassJar();
  	
  	@Override
  	public void render(TileEntityFilteredSiltGlassJar tile, double x, double y, double z, float partialTick, int destroyStage, float alpha) {
  		if (tile != null) {
  			float fluidLevel = tile.tank.getFluidAmount();
  			if (fluidLevel > 0) {
  				FluidStack fluidStack = new FluidStack(tile.tank.getFluid(), 100);
  				float height = (0.6875F / tile.tank.getCapacity()) * tile.tank.getFluidAmount();
  
  				TextureAtlasSprite fluidStillSprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(fluidStack.getFluid().getStill().toString());
  				Tessellator tessellator = Tessellator.getInstance();
  				BufferBuilder buffer = tessellator.getBuffer();
  				int fluidColor = fluidStack.getFluid().getColor(fluidStack);
  
  				GlStateManager.disableLighting();
  				GlStateManager.pushMatrix();
  				GlStateManager.translate(x, y, z);
  				Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
  				setGLColorFromInt(fluidColor);
  				buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
  				float xMax, zMax, xMin, zMin, yMin = 0;
  				xMax = 1.5F;
  				zMax = 1.5F;
  				xMin = 0.5F;
  				zMin = 0.5F;
  				yMin = 0.0625F;
  
  				renderCuboid(buffer, xMax, xMin, yMin, height, zMin, zMax, fluidStillSprite);
  				tessellator.draw();
  				GlStateManager.popMatrix();
  				GlStateManager.enableLighting();
  			}
  		}
  
  		bindTexture(TEXTURE);
  		GlStateManager.pushMatrix();
  		GlStateManager.enableBlend();
  		GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
  		GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  		GlStateManager.translate((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
  		GlStateManager.scale(1F, -1F, -1F);
  		GlStateManager.enableCull();
  		GlStateManager.cullFace(CullFace.FRONT);
  		model.render();
  		GlStateManager.cullFace(CullFace.BACK);
  		model.render();
  		GlStateManager.popMatrix();
  	}
  	
  	private void setGLColorFromInt(int color) {
  		float red = (color >> 16 & 0xFF) / 255.0F;
  		float green = (color >> 8 & 0xFF) / 255.0F;
  		float blue = (color & 0xFF) / 255.0F;
  		GlStateManager.color(red, green, blue, 1.0F);
  	}
  
  	private void renderCuboid(BufferBuilder buffer, float xMax, float xMin, float yMin, float height, float zMin, float zMax, TextureAtlasSprite textureAtlasSprite) {
  
  		double uMin = (double) textureAtlasSprite.getMinU();
  		double uMax = (double) textureAtlasSprite.getMaxU();
  		double vMin = (double) textureAtlasSprite.getMinV();
  		double vMax = (double) textureAtlasSprite.getMaxV();
  
  		final double vHeight = vMax - vMin;
  
  		// top
  		addVertexWithUV(buffer, xMax, height, zMax, uMax, vMin);
  		addVertexWithUV(buffer, xMax, height, zMin, uMin, vMin);
  		addVertexWithUV(buffer, xMin, height, zMin, uMin, vMax);
  		addVertexWithUV(buffer, xMin, height, zMax, uMax, vMax);
  
  		// north
  		addVertexWithUV(buffer, xMax, yMin, zMin, uMax, vMin);
  		addVertexWithUV(buffer, xMin, yMin, zMin, uMin, vMin);
  		addVertexWithUV(buffer, xMin, height, zMin, uMin, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMax, height, zMin, uMax, vMin + (vHeight * height));
  
  		// south
  		addVertexWithUV(buffer, xMax, yMin, zMax, uMin, vMin);
  		addVertexWithUV(buffer, xMax, height, zMax, uMin, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMin, height, zMax, uMax, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMin, yMin, zMax, uMax, vMin);
  
  		// east
  		addVertexWithUV(buffer, xMax, yMin, zMin, uMin, vMin);
  		addVertexWithUV(buffer, xMax, height, zMin, uMin, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMax, height, zMax, uMax, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMax, yMin, zMax, uMax, vMin);
  
  		// west
  		addVertexWithUV(buffer, xMin, yMin, zMax, uMin, vMin);
  		addVertexWithUV(buffer, xMin, height, zMax, uMin, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMin, height, zMin, uMax, vMin + (vHeight * height));
  		addVertexWithUV(buffer, xMin, yMin, zMin, uMax, vMin);
  
  		// down
  		addVertexWithUV(buffer, xMax, yMin, zMin, uMax, vMin);
  		addVertexWithUV(buffer, xMax, yMin, zMax, uMin, vMin);
  		addVertexWithUV(buffer, xMin, yMin, zMax, uMin, vMax);
  		addVertexWithUV(buffer, xMin, yMin, zMin, uMax, vMax);
  
  	}
  
  	private void addVertexWithUV(BufferBuilder buffer, float x, float y, float z, double u, double v) {
  		buffer.pos(x / 2f, y, z / 2f).tex(u, v).endVertex();
  	}
  }