lyonlancer5.pfsteel.client.render.projectile.RenderBullet.java Source code

Java tutorial

Introduction

Here is the source code for lyonlancer5.pfsteel.client.render.projectile.RenderBullet.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.projectile;

import lyonlancer5.pfsteel.entity.projectile.EntityBullet;
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.ResourceLocation;

import org.lwjgl.opengl.GL11;

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

@SideOnly(Side.CLIENT)
public class RenderBullet extends Render {

    private static final ResourceLocation tex = new ResourceLocation(ModVersion.modid, "textures/models/shot.png");

    public void renderBullet(EntityBullet entityarrow, double d, double d1, double d2, float f, float f1) {
        bindEntityTexture(entityarrow);
        GL11.glPushMatrix();
        GL11.glTranslatef((float) d, (float) d1, (float) d2);
        Tessellator tessellator = Tessellator.instance;
        float f2 = 0.0F;
        float f3 = 0.3125F;
        float f10 = 0.05625F;
        GL11.glEnable(32826);
        GL11.glScalef(0.07F, 0.07F, 0.07F);
        GL11.glNormal3f(f10, 0.0F, 0.0F);
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV(0.0D, -1.0D, -1.0D, f2, f2);
        tessellator.addVertexWithUV(0.0D, -1.0D, 1.0D, f3, f2);
        tessellator.addVertexWithUV(0.0D, 1.0D, 1.0D, f3, f3);
        tessellator.addVertexWithUV(0.0D, 1.0D, -1.0D, f2, f3);
        tessellator.draw();
        GL11.glNormal3f(-f10, 0.0F, 0.0F);
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV(0.0D, 1.0D, -1.0D, f2, f2);
        tessellator.addVertexWithUV(0.0D, 1.0D, 1.0D, f3, f2);
        tessellator.addVertexWithUV(0.0D, -1.0D, 1.0D, f3, f3);
        tessellator.addVertexWithUV(0.0D, -1.0D, -1.0D, f2, f3);
        tessellator.draw();
        for (int j = 0; j < 4; j++) {
            GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
            GL11.glNormal3f(0.0F, 0.0F, f10);
            tessellator.startDrawingQuads();
            tessellator.addVertexWithUV(-1.0D, -1.0D, 0.0D, f2, f2);
            tessellator.addVertexWithUV(1.0D, -1.0D, 0.0D, f3, f2);
            tessellator.addVertexWithUV(1.0D, 1.0D, 0.0D, f3, f3);
            tessellator.addVertexWithUV(-1.0D, 1.0D, 0.0D, f2, f3);
            tessellator.draw();
        }
        GL11.glDisable(32826);
        GL11.glPopMatrix();
    }

    @Override
    public void doRender(Entity entity, double d, double d1, double d2, float f, float f1) {
        renderBullet((EntityBullet) entity, d, d1, d2, f, f1);
    }

    /**   
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityBullet p_110775_1_) {
        return tex;
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity p_110775_1_) {
        return this.getEntityTexture((EntityBullet) p_110775_1_);
    }
}