package com.zivilon.cinder_loe.client.render.projectile;

import com.zivilon.cinder_loe.entity.projectile.EntityWarDart;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.ItemRenderer;

public class RenderWarDart extends Render {

    protected ResourceLocation getEntityTexture(Entity entity) {
        return TextureMap.locationItemsTexture;
    }

    @Override
    public void doRender(Entity entity, double d, double d1, double d2, float f, float f1) {
        EntityWarDart dart = (EntityWarDart)entity;
        GL11.glPushMatrix();
        GL11.glTranslatef((float)d, (float)d1, (float)d2);
        GL11.glRotatef(dart.prevRotationYaw + (dart.rotationYaw - dart.prevRotationYaw) * f1 - 90.0F, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(dart.prevRotationPitch + (dart.rotationPitch - dart.prevRotationPitch) * f1, 0.0F, 0.0F, 1.0F);
        GL11.glEnable(32826);
        GL11.glRotatef(-135.0F, 0.0F, 0.0F, 1.0F);
        GL11.glTranslatef(0.0F, -1.0F, 0.0F);
        float scale = 0.6F;
        GL11.glScalef(scale, scale, scale);
        GL11.glTranslatef(0.0F, 0.8F, 0.0F);

        if (dart.item != null) {
            IIcon icon = dart.getDartIcon();
            if (icon != null) {
                Tessellator tessellator = Tessellator.instance;
                float minU = icon.getMinU();
                float maxU = icon.getMaxU();
                float minV = icon.getMinV();
                float maxV = icon.getMaxV();
                int width = icon.getIconWidth();
                int height = icon.getIconHeight();
                bindTexture(getEntityTexture((Entity)dart));
                ItemRenderer.renderItemIn2D(tessellator, maxU, minV, minU, maxV, width, height, 0.0625F);
            }
        }

        GL11.glDisable(32826);
        GL11.glPopMatrix();
    }
}
