lyonlancer5.pfsteel.client.render.RenderMagicCircle.java Source code

Java tutorial

Introduction

Here is the source code for lyonlancer5.pfsteel.client.render.RenderMagicCircle.java

Source

/* Copyright (c) 2015 Lance Selga <lyonecro55@gmail.com>
 * 
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See the COPYING file for more details.
 */
package lyonlancer5.pfsteel.client.render;

import lyonlancer5.pfsteel.entity.EntityMagicCircle;
import lyonlancer5.pfsteel.util.ModVersion;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

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

@SideOnly(Side.CLIENT)
public class RenderMagicCircle extends Render {
    private static final ResourceLocation circleTexture = new ResourceLocation(ModVersion.modid,
            "textures/models/circle.png");

    //These three floats control the hue!
    protected float colorR[] = { 255F, 0F, 0F, 255F, 255F, 0F, 255F, 255F };
    protected float colorG[] = { 0F, 0F, 255F, 255F, 0F, 255F, 128F, 255F };
    protected float colorB[] = { 0F, 255F, 0F, 0F, 255F, 255F, 0F, 255F };

    //reserved for later purposes - perhaps for full color control?
    /*protected float colorR2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
     21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
     41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
     61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
     81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,100,
     101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
     121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
     141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
     161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
     181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192 ,193 ,194 ,195 ,196 ,197 ,198 , 199, 200,
     201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
     221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
     241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255};
        
    protected float colorG2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
     21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
     41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
     61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
     81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,100,
     101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
     121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
     141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
     161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
     181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192 ,193 ,194 ,195 ,196 ,197 ,198 , 199, 200,
     201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
     221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
     241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255};
        
    protected float colorB2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
     21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
     41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
     61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
     81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,100,
     101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,
     121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
     141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
     161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
     181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192 ,193 ,194 ,195 ,196 ,197 ,198 , 199, 200,
     201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
     221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240,
     241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255};*/

    public RenderMagicCircle() {
    }

    @Override
    public void doRender(Entity entity, double x, double y, double z, float yaw, float pitch) {
        renderSpellCardCircle((EntityMagicCircle) entity, x, y, z, yaw, pitch);
    }

    public void renderSpellCardCircle(EntityMagicCircle circle, double x, double y, double z, float yaw,
            float pitch) {
        GL11.glPushMatrix();
        bindEntityTexture(circle);
        GL11.glTranslatef((float) x, (float) y, (float) z);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_COLOR);
        float size = circle.getCircleSize() * 6.0F;
        GL11.glScalef(size, size, size);
        Tessellator tessellator = Tessellator.instance;
        float umin = 0.0F;
        float umax = 1.0F;
        float vmin = 0.0F;
        float vmax = 1.0F;

        boolean rainbow = false;
        int color = circle.getCircleType();

        if (color >= 16) {
            float angle = MathHelper.sin(2F * (float) circle.getAnimationCount() / 180F * (float) Math.PI) * 40F;
            GL11.glRotatef(180F - renderManager.playerViewY + angle, 0.0F, 1.0F, 0.0F);
            GL11.glRotatef(-renderManager.playerViewX - angle, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(circle.getAnimationCount() * 5F, 0.0F, 0.0F, 1.0F);
            color %= 16;
        } else {
            GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F);
            GL11.glRotatef(circle.getAnimationCount() * 5F, 0.0F, 0.0F, 1.0F);
        }

        if (color == 9) {
            rainbow = true;
        } else {
            color %= 8;
        }

        tessellator.startDrawingQuads();

        if (rainbow) {
            float rainbowTime = circle.ticksExisted / 3.0F;
            tessellator.setColorRGBA_F(MathHelper.sin(rainbowTime), MathHelper.cos(rainbowTime),
                    -MathHelper.sin(rainbowTime) * 2F, 1.0F);
        } else {
            tessellator.setColorRGBA_F(colorR[color], colorG[color], colorB[color], 1.0F);
        }
        tessellator.setNormal(0.0F, 1.0F, 0.0F);
        tessellator.addVertexWithUV(-0.6F, -0.6F, 0.0D, umin, vmax);
        tessellator.addVertexWithUV(0.6F, -0.6F, 0.0D, umax, vmax);
        tessellator.addVertexWithUV(0.6F, 0.6F, 0.0D, umax, vmin);
        tessellator.addVertexWithUV(-0.6F, 0.6F, 0.0D, umin, vmin);
        tessellator.draw();
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glPopMatrix();
    }

    @Override
    protected ResourceLocation getEntityTexture(Entity entity) {
        return getEntityTexture((EntityMagicCircle) entity);
    }

    protected ResourceLocation getEntityTexture(EntityMagicCircle p_110775_1_) {
        return circleTexture;
    }
}