Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. package com.yourname.yourmod.particle;
  2.  
  3. import com.yourname.yourmod.particle.GWParticle;
  4. import com.yourname.yourmod.particle.GWParticleTextures;
  5. import net.minecraft.client.particle.Particle;
  6. import net.minecraft.client.renderer.ActiveRenderInfo;
  7. import net.minecraft.client.renderer.BufferBuilder;
  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.api.distmarker.Dist;
  13. import net.minecraftforge.api.distmarker.OnlyIn;
  14.  
  15.  
  16. public class 1Particle extends MainParticle
  17. {
  18. private final float rotSpeed;
  19. private final float scale;
  20. private float angle;
  21. private final int MAX_FRAME_ID = 5;
  22. protected int currentFrame = 0;
  23. private boolean directionRight = true;
  24. private int lastTick = 0;
  25.  
  26. public 1Particle(World world, double posX, double posY, double posZ, double motionX, double motionY, double motionZ) {
  27. super(world, posX, posY, posZ, motionX, motionY, motionZ);
  28. this.motionX = this.motionX * 0.009999999776482582d + motionX;
  29. this.motionY = this.motionY * 0.009999999776482582d + motionY;
  30. this.motionZ = this.motionZ * 0.009999999776482582d + motionZ;
  31. this.scale = this.particleScale = 0.5f;
  32. this.rotSpeed = ((float)Math.random() - 0.5F) * 0.1F;
  33. this.particleAngle = (float)Math.random() * ((float)Math.PI * 2F);
  34. this.angle = (float)Math.random() * ((float)Math.PI * 2F);
  35. this.particleGravity = 0.035F;
  36. this.particleRed = 1f;
  37. this.particleGreen = 1f;
  38. this.particleBlue = 1f;
  39. this.maxAge = (int) (15d / (Math.random() * 0.8d + 0.2d)) + 4;
  40. }
  41.  
  42. @Override
  43. public void move(double x, double y, double z) {
  44. super.move(x, y, z);
  45. }
  46.  
  47. @Override
  48. public void onPreRender(BufferBuilder buffer, ActiveRenderInfo activeInfo, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
  49. super.onPreRender(buffer, activeInfo, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
  50. Entity entity = activeInfo.getRenderViewEntity();
  51. if (entity.ticksExisted >= this.lastTick + 5) {
  52. if (this.currentFrame == MAX_FRAME_ID) {
  53. this.directionRight = false;
  54. } else if (currentFrame == 0) {
  55. this.directionRight = true;
  56. }
  57. this.currentFrame = this.currentFrame + (directionRight ? 1 : -1);
  58. this.lastTick = entity.ticksExisted;
  59. }
  60. float f = ((float) this.age + partialTicks) / (float) this.maxAge;
  61. this.particleScale = this.scale;
  62. }
  63.  
  64. @Override
  65. public void tick() {
  66. super.tick();
  67. this.prevParticleAngle = this.particleAngle;
  68. this.particleAngle += (float)Math.PI * this.rotSpeed * 2.0F;
  69. if (this.onGround) {
  70. this.prevParticleAngle = this.particleAngle = 0.0F;
  71. }
  72. this.motionX += Math.cos(angle) * 0.0025;
  73. this.motionY *= 1.06D;
  74. this.motionZ += Math.sin(angle) * 0.0025;
  75. }
  76.  
  77. @Override
  78. public int getBrightnessForRender(float partialTick) {
  79. float f = ((float) this.age + partialTick) / (float) this.maxAge;
  80. f = MathHelper.clamp(f, 0f, 1f);
  81. int i = super.getBrightnessForRender(partialTick);
  82. int j = i & 255;
  83. int k = i >> 16 & 255;
  84. j = j + (int) (f * 15f * 16f);
  85. if (j > 240) {
  86. j = 240;
  87. }
  88. return j | k << 16;
  89. }
  90.  
  91. @Override
  92. public ResourceLocation getTexture() {
  93. return GWParticleTextures.1Particle[currentFrame];
  94. }
  95.  
  96. @OnlyIn(Dist.CLIENT)
  97. public static class Factory implements GWIP {
  98.  
  99. @Override
  100. public Particle makeParticle(World world, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, int... params) {
  101. return new 1Particle(world, x, y, z, xSpeed, ySpeed, zSpeed);
  102. }
  103.  
  104. }
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement