Guest User

By Melonslise

a guest
Aug 22nd, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.45 KB | None | 0 0
  1. package melonslise.lambda.client.particle;
  2.  
  3. import org.lwjgl.opengl.GL11;
  4.  
  5. import melonslise.lambda.LambdaCore;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.client.particle.Particle;
  8. import net.minecraft.client.renderer.BufferBuilder;
  9. import net.minecraft.client.renderer.GlStateManager;
  10. import net.minecraft.client.renderer.Tessellator;
  11. import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.util.ResourceLocation;
  14. import net.minecraft.util.math.Vec3d;
  15. import net.minecraft.world.World;
  16.  
  17. // TODO Use size instead of radius
  18. // TODO gravity too
  19. public class ParticleTauGlow extends Particle
  20. {
  21.     protected static final ResourceLocation texture = new ResourceLocation(LambdaCore.ID, "textures/entities/tau_glow.png");
  22.     protected double radius;
  23.  
  24.     public ParticleTauGlow(World world, double x, double y, double z, double radius)
  25.     {
  26.         super(world, x, y, z);
  27.         this.radius = radius;
  28.     }
  29.  
  30.     public ParticleTauGlow(World world, Vec3d point, double radius)
  31.     {
  32.         this(world, point.x, point.y, point.z, radius);
  33.     }
  34.  
  35.     // TODO Alpha counter
  36.     @Override
  37.     public void onUpdate()
  38.     {
  39.         this.prevPosX = this.posX;
  40.         this.prevPosY = this.posY;
  41.         this.prevPosZ = this.posZ;
  42.         this.particleAlpha -= 0.01F;
  43.         if(this.particleAlpha <= 0F) this.setExpired();
  44.     }
  45.  
  46.     public int getFXLayer()
  47.     {
  48.         return 3;
  49.     }
  50.  
  51.     // TODO Shorten with helpers
  52.     // TODO Interpolate
  53.     @Override
  54.     public void renderParticle(BufferBuilder buffer, Entity entity, float partialTick, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ)
  55.     {
  56.         Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  57.  
  58.         GL11.glPushAttrib(GL11.GL_LIGHTING_BIT);
  59.         GlStateManager.depthMask(false);
  60.         GlStateManager.enableBlend();
  61.         GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
  62.         GlStateManager.alphaFunc(GL11.GL_GREATER, 0.003921569F);
  63.         GlStateManager.disableLighting();
  64.         GlStateManager.disableDepth();
  65.  
  66.         Vec3d position = new Vec3d
  67.         (
  68.             this.prevPosX + (this.posX - this.prevPosX) * (double) partialTick,
  69.             this.prevPosY + (this.posY - this.prevPosY) * (double)partialTick,
  70.             this.prevPosZ + (this.posZ - this.prevPosZ) * (double)partialTick
  71.         );
  72.         Vec3d offset[] = new Vec3d[]
  73.         {
  74.             new Vec3d(-(rotationX + rotationXY) * this.radius, -rotationZ * this.radius, -(rotationXZ + rotationYZ) * this.radius),
  75.             new Vec3d((-rotationX + rotationXY) * this.radius, rotationZ * this.radius, (rotationXZ - rotationYZ) * this.radius),
  76.             new Vec3d((rotationX + rotationXY) * this.radius, rotationZ * this.radius, (rotationXZ + rotationYZ) * this.radius),
  77.             new Vec3d((rotationX - rotationXY) * this.radius, -rotationZ * this.radius, (-rotationXZ + rotationYZ) * this.radius)
  78.         };
  79.         /*
  80.         if (this.particleAngle != 0F)
  81.         {
  82.             float f8 = this.particleAngle + (this.particleAngle - this.prevParticleAngle) * partialTick;
  83.             double f9 = Math.cos((double) f8 * 0.5D);
  84.             Vec3d camera = cameraViewDir.scale(Math.sin((double) f8 * 0.5D));
  85.             for (int a = 0; a < 4; ++a)
  86.             {
  87.                 offset[a] = camera.scale(2D * offset[a].dotProduct(camera)).add(offset[a].scale(f9 * f9 - camera.dotProduct(camera))).add(camera.crossProduct(offset[a]).scale(2D * f9));
  88.             }
  89.         }
  90.         */
  91.  
  92.         buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
  93.         buffer.pos(position.x  - interpPosX + offset[0].x, position.y - interpPosY + offset[0].y, position.z - interpPosZ + offset[0].z).tex(0D, 0D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).endVertex();
  94.         buffer.pos(position.x  - interpPosX + offset[1].x, position.y - interpPosY + offset[1].y, position.z - interpPosZ + offset[1].z).tex(0D, 1D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).endVertex();
  95.         buffer.pos(position.x  - interpPosX + offset[2].x, position.y - interpPosY + offset[2].y, position.z - interpPosZ + offset[2].z).tex(1D, 1D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).endVertex();
  96.         buffer.pos(position.x  - interpPosX + offset[3].x, position.y - interpPosY + offset[3].y, position.z - interpPosZ + offset[3].z).tex(1D, 0D).color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).endVertex();
  97.         Tessellator.getInstance().draw();
  98.  
  99.         GlStateManager.enableDepth();
  100.         GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
  101.         GlStateManager.disableBlend();
  102.         GlStateManager.depthMask(true);
  103.         GL11.glPopAttrib();
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment