com.jmanpenilla.carbonmod.client.render.item.RenderCompressionChamberItem.java Source code

Java tutorial

Introduction

Here is the source code for com.jmanpenilla.carbonmod.client.render.item.RenderCompressionChamberItem.java

Source

package com.jmanpenilla.carbonmod.client.render.item;

import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

import com.jmanpenilla.carbonmod.block.ModBlocks;
import com.jmanpenilla.carbonmod.client.render.tileentity.RenderCompressionChamber;
import com.jmanpenilla.carbonmod.lib.Reference;

import cpw.mods.fml.client.FMLClientHandler;

/**
 * CarbonMod
 * 
 * @author jmanpenilla
 * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
 * 
 */

public class RenderCompressionChamberItem implements IItemRenderer {
    public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.MOD_ID,
            "textures/model/tileentity/" + ModBlocks.compressionChamberTextureName + ".png");

    //It is used, but I hate warnings :D
    private static void renderCompressionChamber(float x, float y, float z, float scale) {
        GL11.glPushMatrix();

        // Disable Lighting Calculations
        GL11.glDisable(GL11.GL_LIGHTING);

        GL11.glTranslatef(x, y, z);

        FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);

        GL11.glScalef(scale, scale, scale);
        GL11.glRotatef(180f, 0f, 0f, 1f);

        RenderCompressionChamber.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

        // Re-enable Lighting Calculations
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glPopMatrix();
    }

    @Override
    public boolean handleRenderType(ItemStack item, ItemRenderType type) {
        return true;
    }

    @Override
    public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        switch (type) {
        case ENTITY: {
            renderCompressionChamber(0.5f, 2.5f, 0.5f, 2.0f);
            return;
        }

        case EQUIPPED: {
            renderCompressionChamber(1.0f, 0.9f, 1.0f, 0.8f);
            return;
        }

        case INVENTORY: {
            renderCompressionChamber(1.0f, 2.0f, 1.0f, 1.0f);
            return;
        }

        case EQUIPPED_FIRST_PERSON: {
            renderCompressionChamber(180.0F, 60.0F, 0.5F, 90.0F);
            return;
        }

        default:
            return;

        }
    }
}