com.builtbroken.atomic.content.machines.processing.extractor.render.RenderItemExtractor.java Source code

Java tutorial

Introduction

Here is the source code for com.builtbroken.atomic.content.machines.processing.extractor.render.RenderItemExtractor.java

Source

package com.builtbroken.atomic.content.machines.processing.extractor.render;

import com.builtbroken.atomic.AtomicScience;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11;

/**
 * @see <a href="https://github.com/BuiltBrokenModding/VoltzEngine/blob/development/license.md">License</a> for what you can and can't do with the code.
 * Created by Dark(DarkGuardsman, Robert) on 5/23/2018.
 */
public class RenderItemExtractor implements IItemRenderer {
    IModelCustom model_base;
    IModelCustom model_drum;

    ResourceLocation texture = new ResourceLocation(AtomicScience.DOMAIN,
            AtomicScience.MODEL_TEXTURE_DIRECTORY + "machines/chemical_extractor.png");

    public RenderItemExtractor() {
        model_base = AdvancedModelLoader.loadModel(new ResourceLocation(AtomicScience.DOMAIN,
                AtomicScience.MODEL_DIRECTORY + "machines/chemical_extractor_base.obj"));
        model_drum = AdvancedModelLoader.loadModel(new ResourceLocation(AtomicScience.DOMAIN,
                AtomicScience.MODEL_DIRECTORY + "machines/chemical_extractor_drum.obj"));
    }

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

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

    @Override
    public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
        GL11.glPushMatrix();
        GL11.glScaled(0.0625f, 0.0625f, 0.0625f);
        if (type.equals(ItemRenderType.INVENTORY)) {
            GL11.glTranslatef(-0.5f, -0.8f, -0.5f);
            GL11.glRotatef(180f, 0, 1, 0);
        } else if (type.equals(ItemRenderType.EQUIPPED_FIRST_PERSON)) {
            GL11.glRotatef(45f, 0, 1, 0);
            GL11.glTranslatef(1f, 12f, 9f);
        } else if (type.equals(ItemRenderType.EQUIPPED)) {
            GL11.glTranslatef(8f, 10f, 8f);
        }
        FMLClientHandler.instance().getClient().renderEngine.bindTexture(texture);
        model_base.renderAll();
        model_drum.renderAll();
        GL11.glPopMatrix();
    }
}