package net.blay09.mods.cookingforblockheads.client.render;

import com.mojang.blaze3d.matrix.MatrixStack;
import net.blay09.mods.cookingforblockheads.tile.SinkTileEntity;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;

public class SinkRenderer extends TileEntityRenderer<SinkTileEntity> {

    public SinkRenderer(TileEntityRendererDispatcher dispatcher) {
        super(dispatcher);
    }

    @Override
    public void render(SinkTileEntity tileEntity, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int combinedLight, int combinedOverlay) {
        if (!tileEntity.hasWorld()) {
            return;
        }

        RenderHelper.disableStandardItemLighting();
        // TODO GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        // TODO GlStateManager.enableBlend();
        // TODO GlStateManager.disableCull();

        if (tileEntity.getWaterAmount() > 0) {
            // TODO GlStateManager.enableBlend();
            matrixStack.push();
            matrixStack.translate(0, 0.5f, 0);
            float filledPercentage = tileEntity.getWaterAmount() / (float) tileEntity.getWaterCapacity();
            matrixStack.scale(1f, filledPercentage, 1f);
            matrixStack.translate(0f, -0.51f, 0f);
            // TODO bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
            // TODO Minecraft.getInstance().getItemRenderer().renderModel(ModModels.sinkLiquid, Fluids.WATER.getAttributes().getColor());
            matrixStack.pop();
        }

        RenderHelper.enableStandardItemLighting();
    }

}

@@ -1,8 +1,9 @@
+%0A
 package 
@@ -101,16 +101,78 @@
 xStack;%0A
+import net.blay09.mods.cookingforblockheads.client.ModModels;%0A
 import n
@@ -228,16 +228,117 @@
 Entity;%0A
+import net.minecraft.client.Minecraft;%0Aimport net.minecraft.client.renderer.BlockRendererDispatcher;%0A
 import n
@@ -428,22 +428,20 @@
 r.Render
-Hel
+Ty
 pe
-r
 ;%0Aimport
@@ -579,16 +579,110 @@
 patcher;
+%0Aimport net.minecraft.world.World;%0Aimport net.minecraftforge.client.model.data.EmptyModelData;
 %0A%0Apublic
@@ -1037,13 +1037,22 @@
     
-if (!
+World world = 
 tile
@@ -1062,18 +1062,45 @@
 ity.
-has
+get
 World()
+;%0A        if (world == null
 ) %7B%0A
@@ -1142,235 +1142,99 @@
     
+Block
 Render
-Helper.disableStandardItemLighting();%0A        // TODO GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);%0A        // TODO GlStateManager.enableBlend();%0A        // TODO GlStateManager.disableCull
+erDispatcher dispatcher = Minecraft.getInstance().getBlockRendererDispatcher
 ();%0A
-%0A
     
@@ -1238,19 +1238,33 @@
        i
-f (
+nt waterAmount = 
 tileEnti
@@ -1286,15 +1286,9 @@
 nt()
- %3E 0) %7B
+;
 %0A   
@@ -1296,81 +1296,84 @@
     
-    // TODO GlStateManager.enableBlend();%0A            matrixStack.push();
+int capacity = tileEntity.getWaterCapacity();%0A        if (waterAmount %3E 0) %7B
 %0A   
@@ -1397,28 +1397,13 @@
 ack.
-translate(0, 0.5f, 0
+push(
 );%0A 
@@ -1438,31 +1438,17 @@
 ntage = 
-tileEntity.getW
+w
 aterAmou
@@ -1449,18 +1449,16 @@
 erAmount
-()
  / (floa
@@ -1464,37 +1464,16 @@
 at) 
-tileEntity.getWaterC
+c
 apacity
-()
 ;%0A  
@@ -1498,17 +1498,35 @@
 ack.
-scale(1
+translate(0
 f,
+ 0.5f - 0.5f *
  fil
@@ -1540,17 +1540,17 @@
 entage, 
-1
+0
 f);%0A    
@@ -1573,157 +1573,77 @@
 ack.
-translate(0f, -0.51f, 0f);%0A            // TODO bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);%0A            // TODO Minecraft.getInstance().getItem
+scale(1f, filledPercentage, 1f);%0A            dispatcher.getBlockModel
 Rend
@@ -1661,16 +1661,23 @@
 erModel(
+world, 
 ModModel
@@ -1694,142 +1694,199 @@
 id, 
-Fluids.WATER.getAttributes().getColor());%0A            matrixStack.pop();%0A        %7D%0A%0A        RenderHelper.enableStandardItemLighting();
+tileEntity.getBlockState(), tileEntity.getPos(), matrixStack, buffer.getBuffer(RenderType.solid()), false, world.rand, 0, 0, EmptyModelData.INSTANCE);%0A            matrixStack.pop();%0A        %7D
 %0A   

Fix sink rendering