Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.89 KB | None | 0 0
  1. package io.github.phantamanta44.pcrossbow.client.fx;
  2.  
  3. import net.minecraft.client.particle.EntityFX;
  4. import net.minecraft.client.renderer.Tessellator;
  5. import net.minecraft.util.Vec3;
  6. import net.minecraft.world.World;
  7. import org.lwjgl.opengl.GL11;
  8.  
  9. public class EntityLaser extends EntityFX {
  10.  
  11.     private final Vec3 dir;
  12.     private final double length;
  13.     private final double intensity;
  14.     private final int colour;
  15.  
  16.     public EntityLaser(World world, Vec3 start, Vec3 end, double intensity, int colour) {
  17.         super(world, start.xCoord, start.yCoord, start.zCoord);
  18.         dir = end.subtract(start).normalize();
  19.         length = start.distanceTo(end);
  20.         this.intensity = intensity;
  21.         this.colour = colour;
  22.         this.particleMaxAge = 5;
  23.     }
  24.  
  25.     @Override
  26.     public int getFXLayer() {
  27.         return 1;
  28.     }
  29.  
  30.     @Override
  31.     public void renderParticle(Tessellator tess, float partialTick, float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) {
  32.         tess.draw();
  33.  
  34.         GL11.glDisable(GL11.GL_TEXTURE_2D);
  35.         GL11.glDisable(GL11.GL_LIGHTING);
  36.         GL11.glEnable(GL11.GL_BLEND);
  37.         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
  38.  
  39.         tess.startDrawingQuads();
  40.  
  41.         GL11.glPushMatrix();
  42.         GL11.glTranslated(0.5, 0.5, 0.5);
  43.         GL11.glTranslated(
  44.                 this.prevPosX + (this.posX - this.prevPosX) * (double)partialTick - interpPosX,
  45.                 this.prevPosY + (this.posY - this.prevPosY) * (double)partialTick - interpPosY,
  46.                 this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTick - interpPosZ);
  47.         GL11.glRotated(90 + Math.atan2(dir.zCoord, dir.xCoord) * 180 / Math.PI, 0, 1, 0);
  48.         GL11.glRotated(Math.atan2(dir.yCoord, dir.zCoord) * 180 / Math.PI, 1, 0, 0);
  49.  
  50.         tess.setColorRGBA_I(colour, 40);
  51.  
  52.         double lx = -0.125, ly = -0.125, lz = 0;
  53.         double hx = 0.125, hy = 0.125, hz = length;
  54.  
  55.         tess.addVertex(hx, hy, hz);
  56.         tess.addVertex(hx, ly, hz);
  57.         tess.addVertex(hx, ly, lz);
  58.         tess.addVertex(hx, hy, lz);
  59.  
  60.         tess.addVertex(lx, hy, lz);
  61.         tess.addVertex(lx, ly, lz);
  62.         tess.addVertex(lx, ly, hz);
  63.         tess.addVertex(lx, hy, hz);
  64.  
  65.         tess.addVertex(hx, hy, lz);
  66.         tess.addVertex(lx, hy, lz);
  67.         tess.addVertex(lx, hy, hz);
  68.         tess.addVertex(hx, hy, hz);
  69.  
  70.         tess.addVertex(hx, ly, hz);
  71.         tess.addVertex(lx, ly, hz);
  72.         tess.addVertex(lx, ly, lz);
  73.         tess.addVertex(hx, ly, lz);
  74.  
  75.         tess.addVertex(hx, hy, hz);
  76.         tess.addVertex(lx, hy, hz);
  77.         tess.addVertex(lx, ly, hz);
  78.         tess.addVertex(hx, ly, hz);
  79.  
  80.         tess.draw();
  81.  
  82.         GL11.glPopMatrix();
  83.         GL11.glDisable(GL11.GL_BLEND);
  84.         GL11.glEnable(GL11.GL_LIGHTING);
  85.         GL11.glEnable(GL11.GL_TEXTURE_2D);
  86.  
  87.         tess.startDrawingQuads();
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement