Advertisement
Guest User

Particle

a guest
Jul 27th, 2016
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. package com.daskaktus.ancienttech.entity.fx;
  2.  
  3. import java.awt.Color;
  4.  
  5. import net.minecraft.client.Minecraft;
  6. import net.minecraft.client.particle.Particle;
  7. import net.minecraft.client.renderer.texture.TextureAtlasSprite;
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.util.ResourceLocation;
  10. import net.minecraft.util.math.MathHelper;
  11. import net.minecraft.world.World;
  12. import net.minecraftforge.fml.client.FMLClientHandler;
  13.  
  14. public class ConsumeParticles extends Particle {
  15.  
  16. private double targetX;
  17. private double targetY;
  18. private double targetZ;
  19.  
  20. public double colorR = 0;
  21. public double colorG = 0;
  22. public double colorB = 0;
  23.  
  24. public ResourceLocation texture = new ResourceLocation("ancienttech:particles/sacrificealtar");
  25.  
  26. public ConsumeParticles(World w, double x, double y, double z, double tx, double ty, double tz, int count, int color, float scale) {
  27. super(w, x, y, z, 0.0D, 0.0D, 0.0D);
  28.  
  29. this.particleRed = (this.particleGreen = this.particleBlue = 0.6F);
  30. this.particleScale = ((MathHelper.sin(count / 2.0F) * 0.1F + 1.0F) * scale);
  31.  
  32. this.targetX = tx;
  33. this.targetY = ty;
  34. this.targetZ = tz;
  35. this.posY += 0.33000001311302185D;
  36. double dx = tx - this.posX;
  37. double dy = ty - this.posY;
  38. double dz = tz - this.posZ;
  39. int base = (int)(MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz) * 30.0F);
  40. if (base < 1) {
  41. base = 1;
  42. }
  43. this.particleMaxAge = (base / 2 + this.rand.nextInt(base));
  44.  
  45. this.motionX = (MathHelper.sin(count / 4.0F) * 0.015F + this.rand.nextGaussian() * 0.0020000000949949026D);
  46. this.motionY = (MathHelper.sin(count / 3.0F) * 0.015F + this.rand.nextGaussian() * 0.0020000000949949026D);
  47. this.motionZ = (MathHelper.sin(count / 2.0F) * 0.015F + this.rand.nextGaussian() * 0.0020000000949949026D);
  48.  
  49. if (this.isCollided){
  50. this.motionX *= 0.699999988079071D;
  51. this.motionZ *= 0.699999988079071D;
  52. }
  53.  
  54. Color c = new Color(color);
  55. float mr = c.getRed() / 255.0F * 0.2F;
  56. float mg = c.getGreen() / 255.0F * 0.2F;
  57. float mb = c.getBlue() / 255.0F * 0.2F;
  58. this.particleRed = (c.getRed() / 255.0F - mr + this.rand.nextFloat() * mr) / 2;
  59. this.particleGreen = (c.getGreen() / 255.0F - mg + this.rand.nextFloat() * mg) / 2;
  60. this.particleBlue = (c.getBlue() / 255.0F - mb + this.rand.nextFloat() * mb) / 2;
  61.  
  62. this.particleGravity = 0.2F;
  63.  
  64. TextureAtlasSprite sprite = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(texture.toString());
  65. this.setParticleTexture(sprite);
  66. System.out.println(texture.toString());
  67.  
  68. //this.noClip = true;
  69. try
  70. {
  71. Entity renderentity = FMLClientHandler.instance().getClient().getRenderViewEntity();
  72. int visibleDistance = 64;
  73. if (!FMLClientHandler.instance().getClient().gameSettings.fancyGraphics) {
  74. visibleDistance = 32;
  75. }
  76. if (renderentity.getDistance(this.posX, this.posY, this.posZ) > visibleDistance) {
  77. this.particleMaxAge = 0;
  78. }
  79. }
  80. catch (Exception e) {}
  81. }
  82.  
  83. @Override
  84. public boolean isTransparent(){
  85. return true;
  86. }
  87.  
  88. public void onUpdate(){
  89.  
  90. this.prevPosX = this.posX;
  91. this.prevPosY = this.posY;
  92. this.prevPosZ = this.posZ;
  93. if (this.particleAge++ >= this.particleMaxAge){
  94. this.setExpired();
  95. return;
  96. }
  97. this.motionY += 0.01D * this.particleGravity;
  98.  
  99. moveEntity(this.motionX, this.motionY, this.motionZ);
  100.  
  101. this.motionX *= 0.985D;
  102. this.motionY *= 0.985D;
  103. this.motionZ *= 0.985D;
  104.  
  105. this.motionX = MathHelper.clamp_float((float)this.motionX, -0.05F, 0.05F);
  106. this.motionY = MathHelper.clamp_float((float)this.motionY, -0.05F, 0.05F);
  107. this.motionZ = MathHelper.clamp_float((float)this.motionZ, -0.05F, 0.05F);
  108.  
  109. double dx = this.targetX - this.posX;
  110. double dy = this.targetY - this.posY;
  111. double dz = this.targetZ - this.posZ;
  112. double d13 = 0.01D;
  113. double d11 = MathHelper.sqrt_double(dx * dx + dy * dy + dz * dz);
  114. if (d11 < 2.0D) {
  115. this.particleScale *= 0.98F;
  116. }
  117. if (this.particleScale < 0.2F){
  118. this.setExpired();
  119. return;
  120. }
  121. dx /= d11;
  122. dy /= d11;
  123. dz /= d11;
  124.  
  125. this.motionX += dx * (d13 / Math.min(1.0D, d11));
  126. this.motionY += dy * (d13 / Math.min(1.0D, d11));
  127. this.motionZ += dz * (d13 / Math.min(1.0D, d11));
  128.  
  129.  
  130. float lifeCoeff = ((float)this.particleMaxAge-(float)this.particleAge)/(float)this.particleMaxAge;
  131. this.particleRed = Math.min(1.0f, (float)colorR*(1.5f-lifeCoeff)+lifeCoeff / 2);
  132. this.particleGreen = Math.min(1.0f, (float)colorG*(1.5f-lifeCoeff)+lifeCoeff / 2);
  133. this.particleBlue = Math.min(1.0f, (float)colorB*(1.5f-lifeCoeff)+lifeCoeff / 2);
  134.  
  135.  
  136.  
  137.  
  138. //System.out.println(this.particleRed);
  139.  
  140. }
  141.  
  142. public int getFXLayer(){
  143. return 1;
  144. }
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement