package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.model.ModelBase;
import client.renderer.model.ModelBoat;
import common.entity.item.EntityBoat;
import common.util.ExtMath;


public class RenderBoat extends Render<EntityBoat>
{
    private static final String boatTextures = "textures/object/boat.png";

    /** instance of ModelBoat for rendering */
    protected ModelBase modelBoat = new ModelBoat();

    public RenderBoat(RenderManager renderManagerIn)
    {
        super(renderManagerIn);
//        this.shadowSize = 0.5F;
    }

    /**
     * Renders the desired {@code T} type Entity.
     */
    public void doRender(EntityBoat entity, double x, double y, double z, float partialTicks)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x, (float)y + 0.25F, (float)z);
        GL11.glRotatef(180.0F - (entity.prevYaw + (entity.rotYaw - entity.prevYaw) * partialTicks), 0.0F, 1.0F, 0.0F);
        float f = (float)entity.getTimeSinceHit() - partialTicks;
        float f1 = (float)entity.getDamageTaken() - partialTicks;

        if (f1 < 0.0F)
        {
            f1 = 0.0F;
        }

        if (f > 0.0F)
        {
            GL11.glRotatef(ExtMath.sin(f) * f * f1 / 10.0F * (float)entity.getForwardDirection(), 1.0F, 0.0F, 0.0F);
        }

        float f2 = 0.75F;
        GL11.glScalef(f2, f2, f2);
        GL11.glScalef(1.0F / f2, 1.0F / f2, 1.0F / f2);
        this.bindEntityTexture(entity);
        GL11.glScalef(-1.0F, -1.0F, 1.0F);
        this.modelBoat.render(entity, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected String getEntityTexture(EntityBoat entity)
    {
        return boatTextures;
    }
}
