com.pahimar.ee3.client.renderer.item.ItemAlchemyTableRenderer.java Source code

Java tutorial

Introduction

Here is the source code for com.pahimar.ee3.client.renderer.item.ItemAlchemyTableRenderer.java

Source

/**
 * 
 */
package com.pahimar.ee3.client.renderer.item;

import org.lwjgl.opengl.GL11;

import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;

import com.pahimar.ee3.client.model.ModelAlchemyTable;
import com.pahimar.ee3.lib.Textures;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/**
 * Equivalent-Exchange-3
 * 
 * ItemAlchemyTableRenderer
 * 
 * @author pahimar
 * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
 * 
 */
@SideOnly(Side.CLIENT)
public class ItemAlchemyTableRenderer implements IItemRenderer {

    private ModelAlchemyTable modelAlchemyTable;

    public ItemAlchemyTableRenderer() {

        modelAlchemyTable = new ModelAlchemyTable();
    }

    /*
     * (non-Javadoc)
     * @see
     * net.minecraftforge.client.IItemRenderer#handleRenderType(net.minecraft
     * .item.ItemStack, net.minecraftforge.client.IItemRenderer.ItemRenderType)
     */
    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {

        return true;
    }

    /*
     * (non-Javadoc)
     * @see net.minecraftforge.client.IItemRenderer#shouldUseRenderHelper(net.
     * minecraftforge.client.IItemRenderer.ItemRenderType,
     * net.minecraft.item.ItemStack,
     * net.minecraftforge.client.IItemRenderer.ItemRendererHelper)
     */
    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {

        return true;
    }

    /*
     * (non-Javadoc)
     * @see
     * net.minecraftforge.client.IItemRenderer#renderItem(net.minecraftforge
     * .client.IItemRenderer.ItemRenderType, net.minecraft.item.ItemStack,
     * java.lang.Object[])
     */
    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {

        switch (type) {
        case ENTITY: {
            renderAlchemyTable(-0.5F, 0.0F, 0.5F, 1.0F);
            return;
        }
        case EQUIPPED: {
            renderAlchemyTable(0.0F, 0.0F, 1.0F, 1.0F);
            return;
        }
        case EQUIPPED_FIRST_PERSON: {
            renderAlchemyTable(0.0F, 0.0F, 1.0F, 1.0F);
            return;
        }
        case INVENTORY: {
            renderAlchemyTable(0.0F, -0.1F, 1.0F, 1.0F);
            return;
        }
        default:
            return;
        }
    }

    private void renderAlchemyTable(float x, float y, float z, float scale) {

        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_LIGHTING);

        // Scale, Translate, Rotate
        GL11.glScalef(scale, scale, scale);
        GL11.glTranslatef(x, y, z);
        GL11.glRotatef(-90F, 1F, 0, 0);

        // Bind texture
        FMLClientHandler.instance().getClient().renderEngine.bindTexture(Textures.MODEL_ALCHEMY_TABLE);

        // Render
        modelAlchemyTable.render();

        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glPopMatrix();
    }
}