package client.renderer.entity;

import org.lwjgl.opengl.GL11;

import client.renderer.GlState;
import client.renderer.texture.TextureMap;
import common.entity.Entity;
import common.item.Item;
import common.item.ItemStack;


public class RenderItemEntity<T extends Entity> extends Render<T>
{
    protected final Item item;
    private final RenderItem itemRenderer;

    public RenderItemEntity(RenderManager renderManagerIn, Item itemIn, RenderItem renderItemIn)
    {
        super(renderManagerIn);
        this.item = itemIn;
        this.itemRenderer = renderItemIn;
    }
    
    public void doRender(T entity, double x, double y, double z, float partialTicks)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x, (float)y, (float)z);
        GlState.enableRescaleNormal();
        GL11.glScalef(0.5F, 0.5F, 0.5F);
        GL11.glRotatef(-this.manager.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(this.manager.playerViewX, 1.0F, 0.0F, 0.0F);
        this.bindTexture(TextureMap.BLOCKS);
        this.itemRenderer.renderItemAsGround(this.getStack(entity));
        GlState.disableRescaleNormal();
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }

    public ItemStack getStack(T entityIn)
    {
        return new ItemStack(this.item);
    }
    
    protected String getEntityTexture(Entity entity)
    {
        return TextureMap.BLOCKS;
    }
}
