<commit_before>package com.teaminfinity.elementalinvocations.render.player;

import com.infinityraider.infinitylib.render.RenderUtilBase;
import com.infinityraider.infinitylib.utility.RayTraceHelper;
import com.teaminfinity.elementalinvocations.magic.spell.BeamHandler;
import com.teaminfinity.elementalinvocations.magic.spell.MagicBeam;
import com.teaminfinity.elementalinvocations.reference.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;

import java.util.Optional;

@SideOnly(Side.CLIENT)
public class RenderBeam extends RenderUtilBase {
    private static final RenderBeam INSTANCE = new RenderBeam();

    public static final ResourceLocation BEAM_TEXTURE = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/entities/beam.png");
    public static final ResourceLocation ORB_TEXTURE = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/entities/beam_orb.png");

    public static RenderBeam getInstance() {
        return INSTANCE;
    }

    private RenderBeam() {}

    @SubscribeEvent
    @SuppressWarnings("unused")
    public void renderPlayerCharges(RenderPlayerEvent.Post event) {
        Optional<MagicBeam> optional = BeamHandler.getInstance().getMagicBeam(event.getEntityPlayer());
        if(!optional.isPresent()) {
            return;
        }

        MagicBeam beam = optional.get();

        double thickness = 1.0/16;

        int red = beam.getRed();
        int green = beam.getGreen();
        int blue = beam.getBlue();
        int alpha = 127;

        double range = beam.getRange();
        EntityPlayer player = event.getEntityPlayer();
        RayTraceResult hit = RayTraceHelper.getTargetEntityOrBlock(player, range);
        Vec3d target;
        if(hit == null) {
            target = player.getPositionEyes(event.getPartialRenderTick()).add(player.getLook(event.getPartialRenderTick()).scale(range));
        } else {
            target = hit.hitVec;
        }

        double pX = player.prevPosX + event.getPartialRenderTick()*(player.posX - player.prevPosX);
        double pY = player.prevPosY + event.getPartialRenderTick()*(player.posY - player.prevPosY);
        double pZ = player.prevPosZ + event.getPartialRenderTick()*(player.posZ - player.prevPosZ);

        double yaw = player.prevRenderYawOffset + event.getPartialRenderTick()*(player.renderYawOffset - player.prevRenderYawOffset);
        double cos = Math.cos(Math.toRadians(yaw));
        double sin = Math.sin(Math.toRadians(yaw));

        double dx = 0;
        double dz = 0.5;

        double x1 = dx*cos - dz*sin;
        double y1 = 0.65*player.height;
        double z1 = dx*sin + dz*cos;

        double x2 = target.xCoord - pX;
        double y2 = target.yCoord - pY;
        double z2 = target.zCoord - pZ;

        GlStateManager.pushMatrix();
        GlStateManager.pushAttrib();

        GlStateManager.enableBlend();
        GlStateManager.disableLighting();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.alphaFunc(GL11.GL_GREATER, 0.05F);

        GlStateManager.translate(event.getX(), event.getY(), event.getZ());

        //render the beam
        this.renderBeam(x1, y1, z1, x2, y2, z2, thickness, red, green, blue, alpha);

        //render the orb
        GlStateManager.pushMatrix();
        GlStateManager.rotate((float) -yaw, 0, 1, 0);
        GlStateManager.translate(dx, y1, dz);
        this.renderOrb(red, green, blue, alpha);
        GlStateManager.popMatrix();

        GlStateManager.popAttrib();
        GlStateManager.popMatrix();
    }

    protected void renderBeam(double x1, double y1, double z1, double x2, double y2, double z2, double thickness, int red, int green, int blue, int alpha) {
        Minecraft.getMinecraft().renderEngine.bindTexture(BEAM_TEXTURE);
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer buffer = tessellator.getBuffer();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);

        buffer.pos(x2, y2 + thickness/2, z2).tex(1, 0).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 + thickness/2, z1).tex(1, 1).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 - thickness/2, z1).tex(0, 1).color(red, green, blue, alpha).endVertex();
        buffer.pos(x2, y2 - thickness/2, z2).tex(0, 0).color(red, green, blue, alpha).endVertex();

        buffer.pos(x2, y2 + thickness/2, z2).tex(1, 0).color(red, green, blue, alpha).endVertex();
        buffer.pos(x2, y2 - thickness/2, z2).tex(0, 0).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 - thickness/2, z1).tex(0, 1).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 + thickness/2, z1).tex(1, 1).color(red, green, blue, alpha).endVertex();

        tessellator.draw();
    }<commit_msg>Added First person rendering to the beam<commit_after>package com.teaminfinity.elementalinvocations.render.player;

import com.infinityraider.infinitylib.render.RenderUtilBase;
import com.infinityraider.infinitylib.utility.RayTraceHelper;
import com.infinityraider.infinitylib.utility.math.TransformationMatrix;
import com.teaminfinity.elementalinvocations.ElementalInvocations;
import com.teaminfinity.elementalinvocations.magic.spell.BeamHandler;
import com.teaminfinity.elementalinvocations.magic.spell.MagicBeam;
import com.teaminfinity.elementalinvocations.reference.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.client.event.RenderHandEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;

import java.util.Optional;

@SideOnly(Side.CLIENT)
public class RenderBeam extends RenderUtilBase {
    private static final RenderBeam INSTANCE = new RenderBeam();

    public static final ResourceLocation BEAM_TEXTURE = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/entities/beam.png");
    public static final ResourceLocation ORB_TEXTURE = new ResourceLocation(Reference.MOD_ID.toLowerCase(), "textures/entities/beam_orb.png");

    public static RenderBeam getInstance() {
        return INSTANCE;
    }

    private RenderBeam() {}

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    @SuppressWarnings("unused")
    public void onRenderPlayer(RenderPlayerEvent.Post event) {
        EntityPlayer player = event.getEntityPlayer();
        Optional<MagicBeam> optional = BeamHandler.getInstance().getMagicBeam(player);
        if(!optional.isPresent()) {
            return;
        }

        MagicBeam beam = optional.get();

        double thickness = 1.0/16;

        int red = beam.getRed();
        int green = beam.getGreen();
        int blue = beam.getBlue();
        int alpha = 127;

        double range = beam.getRange();
        RayTraceResult hit = RayTraceHelper.getTargetEntityOrBlock(player, range);
        Vec3d target;
        if(hit == null) {
            target = player.getPositionEyes(event.getPartialRenderTick()).add(player.getLook(event.getPartialRenderTick()).scale(range));
        } else {
            target = hit.hitVec;
        }

        double pX = player.prevPosX + event.getPartialRenderTick()*(player.posX - player.prevPosX);
        double pY = player.prevPosY + event.getPartialRenderTick()*(player.posY - player.prevPosY);
        double pZ = player.prevPosZ + event.getPartialRenderTick()*(player.posZ - player.prevPosZ);

        double yaw = player.prevRenderYawOffset + event.getPartialRenderTick()*(player.renderYawOffset - player.prevRenderYawOffset);
        double cos = Math.cos(Math.toRadians(yaw));
        double sin = Math.sin(Math.toRadians(yaw));

        double dx = 0;
        double dz = 0.5;

        double x1 = dx*cos - dz*sin;
        double y1 = 0.65*player.height;
        double z1 = dx*sin + dz*cos;

        double x2 = target.xCoord - pX;
        double y2 = target.yCoord - pY;
        double z2 = target.zCoord - pZ;

        GlStateManager.pushMatrix();
        GlStateManager.pushAttrib();

        GlStateManager.enableBlend();
        GlStateManager.disableLighting();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.alphaFunc(GL11.GL_GREATER, 0.05F);

        GlStateManager.translate(event.getX(), event.getY(), event.getZ());

        //render the beam
        this.renderBeam(x1, y1, z1, x2, y2, z2, thickness, red, green, blue, alpha);

        //render the orb
        GlStateManager.pushMatrix();
        GlStateManager.rotate((float) -yaw, 0, 1, 0);
        GlStateManager.translate(dx, y1, dz);
        this.renderOrb(red, green, blue, alpha);
        GlStateManager.popMatrix();

        GlStateManager.popAttrib();
        GlStateManager.popMatrix();
    }

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    @SuppressWarnings("unused")
    public void onRenderHand(RenderHandEvent event) {
        EntityPlayer player = ElementalInvocations.proxy.getClientPlayer();
        Optional<MagicBeam> optional = BeamHandler.getInstance().getMagicBeam(player);
        if (!optional.isPresent()) {
            return;
        }

        MagicBeam beam = optional.get();

        double thickness = 2.0 / 16;

        int red = beam.getRed();
        int green = beam.getGreen();
        int blue = beam.getBlue();
        int alpha = 127;

        double range = beam.getRange();
        RayTraceResult hit = RayTraceHelper.getTargetEntityOrBlock(player, range);
        Vec3d target;
        if (hit == null) {
            target = player.getPositionEyes(event.getPartialTicks()).add(player.getLook(event.getPartialTicks()).scale(range));
        } else {
            target = hit.hitVec;
        }

        double pX = player.prevPosX + event.getPartialTicks()*(player.posX - player.prevPosX);
        double pY = player.prevPosY + event.getPartialTicks()*(player.posY - player.prevPosY);
        double pZ = player.prevPosZ + event.getPartialTicks()*(player.posZ - player.prevPosZ);

        Vec3d eyes = player.getPositionEyes(event.getPartialTicks());

        double pitch = player.prevRotationPitch + event.getPartialTicks()*(player.rotationPitch - player.prevRotationPitch);
        double cosPitch = Math.cos(Math.toRadians(pitch));
        double sinPitch = Math.sin(Math.toRadians(pitch));

        double yaw = player.prevRotationYaw + event.getPartialTicks()*(player.rotationYaw - player.prevRotationYaw);
        double cosYaw = Math.cos(Math.toRadians(yaw));
        double sinYaw = Math.sin(Math.toRadians(yaw));

        //parallel with screen width
        double dx = -0.25;
        //parallel with screen height
        double dy = 0.95*player.height;
        //parallel with screen normal
        double dz = -0.25;

        TransformationMatrix matrix = new TransformationMatrix(-yaw, 0, 1, 0)
                .multiplyRightWith(new TransformationMatrix(-pitch, 1, 0, 0));

        double[] transformed = matrix.transform(dx, dy, dz);

        double x1 = pX + transformed[0];
        double y1 = pY + transformed[1];
        double z1 = pZ + transformed[2];

        double x2 = target.xCoord;
        double y2 = target.yCoord;
        double z2 = target.zCoord;

        GlStateManager.pushMatrix();
        GlStateManager.pushAttrib();

        GlStateManager.enableBlend();
        GlStateManager.disableLighting();
        GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GlStateManager.alphaFunc(GL11.GL_GREATER, 0.05F);

        GlStateManager.rotate((float) pitch, 1, 0, 0);
        GlStateManager.rotate((float) yaw + 180, 0, 1, 0);
        GlStateManager.translate(-eyes.xCoord, -eyes.yCoord, -eyes.zCoord);

        this.renderBeam(x1, y1, z1, x2, y2, z2, thickness, red, green, blue, alpha);

        GlStateManager.popAttrib();
        GlStateManager.popMatrix();
    }

    protected void renderBeam(double x1, double y1, double z1, double x2, double y2, double z2, double thickness, int red, int green, int blue, int alpha) {
        Minecraft.getMinecraft().renderEngine.bindTexture(BEAM_TEXTURE);
        Tessellator tessellator = Tessellator.getInstance();
        VertexBuffer buffer = tessellator.getBuffer();
        buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);

        buffer.pos(x2, y2 + thickness/2, z2).tex(1, 0).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 + thickness/2, z1).tex(1, 1).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 - thickness/2, z1).tex(0, 1).color(red, green, blue, alpha).endVertex();
        buffer.pos(x2, y2 - thickness/2, z2).tex(0, 0).color(red, green, blue, alpha).endVertex();

        buffer.pos(x2, y2 + thickness/2, z2).tex(1, 0).color(red, green, blue, alpha).endVertex();
        buffer.pos(x2, y2 - thickness/2, z2).tex(0, 0).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 - thickness/2, z1).tex(0, 1).color(red, green, blue, alpha).endVertex();
        buffer.pos(x1, y1 + thickness/2, z1).tex(1, 1).color(red, green, blue, alpha).endVertex();

        tessellator.draw();
    }
{'fraction_non_alphanumeric': 0.12090135342542208, 'fraction_numerical': 0.01765034184456537, 'mean_word_length': 3.3282004830917873, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '833535', 'n_tokens_mistral': 4594, 'n_tokens_neox': 4433, 'n_words': 849}