nedhyett.elementalcraft.block.energy.light.RenderArchangelLightWorld.java Source code

Java tutorial

Introduction

Here is the source code for nedhyett.elementalcraft.block.energy.light.RenderArchangelLightWorld.java

Source

/*******************************************************************************
 * ElementalCraft
 * Copyright (c) 2014 Ned Hyett and Jacob
 *
 * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License.
 *
 * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0
 ******************************************************************************/
package nedhyett.elementalcraft.block.energy.light;

import nedhyett.elementalcraft.core.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;

/**
 * @author Ned Hyett
 */
public class RenderArchangelLightWorld extends TileEntitySpecialRenderer {

    private static final ResourceLocation texture = Utils.getResource("textures/blocks/archangel_light.png");
    private static final ModelArchangelLight model = new ModelArchangelLight();

    @Override
    public void renderTileEntityAt(TileEntity t, double x, double y, double z, float var8) {
        if (t == null | !(t instanceof TileArchangelLight)) {
            return;
        }
        int meta = t.getWorldObj().getBlockMetadata(t.xCoord, t.yCoord, t.zCoord);
        TileArchangelLight ts = (TileArchangelLight) t;
        GL11.glPushMatrix();
        GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
        GL11.glPushMatrix();
        GL11.glRotatef(180F, 0, 0, 1);
        if (meta == 5) {
            GL11.glRotatef(-90F, 0, 0, 1);
            GL11.glTranslated(-1, -1, 0);
        }
        if (meta == 3) {
            GL11.glRotatef(-90, 90, 0, 1);
            GL11.glTranslatef(0, -1, 1);
        }
        if (meta == 4) {
            GL11.glRotatef(90, -90, 0, 1);
            GL11.glRotatef(90, 0, 0, 1);
            GL11.glTranslatef(0, -1, 1);
        }
        if (meta == 2) {
            GL11.glRotatef(90, 90, 0, 1);
            GL11.glTranslatef(0, -1, -1);
        }
        if (meta == 0) {
            GL11.glRotatef(180, 0, 0, 1);
            GL11.glTranslatef(0, -2, 0);
        }
        Minecraft.getMinecraft().renderEngine.bindTexture(texture);
        glEnable(32826);
        Utils.adjustLighting(t.getWorldObj(), t.xCoord, t.yCoord, t.zCoord,
                t.getWorldObj().getBlock(t.xCoord, t.yCoord, t.zCoord));
        model.render(null, 0, 0, -0.1F, 0, 0, 0.0625F);
        glDisable(32826);
        GL11.glPopMatrix();
        GL11.glPopMatrix();
    }

}