com.ethylamine.fsynthesis.client.renderer.item.TungstenChestItemRenderer.java Source code

Java tutorial

Introduction

Here is the source code for com.ethylamine.fsynthesis.client.renderer.item.TungstenChestItemRenderer.java

Source

package com.ethylamine.fsynthesis.client.renderer.item;

/*
 * Copyright (c) 2014 Robin Glover
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, see <http://www.gnu.org/licenses>.
 */

import com.ethylamine.fsynthesis.client.renderer.tileentity.TungstenChestTESR;
import com.google.common.base.Objects;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelChest;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.IItemRenderer;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.lwjgl.opengl.GL11;

@SideOnly(Side.CLIENT)
public class TungstenChestItemRenderer implements IItemRenderer {
    private static final ImmutableTriple<Float, Float, Float> ENTITY_OFFSET = ImmutableTriple.of(0.0f, -1.0f, 0.0f);
    private static final ImmutableTriple<Float, Float, Float> EQUIPPED_OFFSET = ImmutableTriple.of(1.0f, 1.0f,
            1.0f);
    private static final ImmutableTriple<Float, Float, Float> FIRST_PERSON_OFFSET = ImmutableTriple.of(1.0f, 1.0f,
            1.0f);
    private static final ImmutableTriple<Float, Float, Float> INVENTORY_OFFSET = ImmutableTriple.of(0.0f, 0.09f,
            0.0f);

    private static final ImmutableTriple<Float, Float, Float> SCALE = ImmutableTriple.of(1.0f, 1.0F, 1.0F);

    private final ModelChest vanillaChest;

    public TungstenChestItemRenderer() {
        vanillaChest = new ModelChest();
    }

    @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(IItemRenderer.ItemRenderType type, ItemStack item, Object... data) {
        switch (type) {
        case ENTITY:
            renderPlotoniumChest(ENTITY_OFFSET);
            break;
        case EQUIPPED:
            renderPlotoniumChest(EQUIPPED_OFFSET);
            break;
        case EQUIPPED_FIRST_PERSON:
            renderPlotoniumChest(FIRST_PERSON_OFFSET);
            break;
        case INVENTORY:
            renderPlotoniumChest(INVENTORY_OFFSET);
            break;
        default:
        }
    }

    private void renderPlotoniumChest(ImmutableTriple<Float, Float, Float> offset) {
        GL11.glPushMatrix();

        GL11.glScalef(SCALE.left, SCALE.middle, SCALE.right);
        GL11.glTranslatef(offset.left, offset.middle, offset.right);
        GL11.glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
        GL11.glRotatef(90.0f, 0.0f, -1.0f, 0.0f);

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

        vanillaChest.renderAll();

        GL11.glPopMatrix();
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("model", vanillaChest).toString();
    }
}