Advertisement
Guest User

Untitled

a guest
Jan 25th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1.  
  2. /** Spawns particle of a given type in a given direction*/
  3. @OnlyIn(Dist.CLIENT)
  4. public static void createLinearParticles(IParticleData particleType, World worldIn, Vec3d pos, Vec3d direction,
  5. double speed, double acceleration, int count, double distanceIn, double distanceMax) {
  6. double upper = 0.1;
  7. double lower = -0.1;
  8. double upperVelocity = 0.03;
  9. double lowerVelocity = -0.03;
  10. int lifetime;
  11. for(int i = 0; i <= count; ++i) {
  12. double velocity = speed + (acceleration * i);
  13. if(distanceIn == distanceMax) {
  14. lifetime = (int) (distanceIn / velocity) - 1;
  15. //System.out.println("dist" + distanceIn);
  16. //System.out.println("vel" + velocity);
  17. }
  18. else {
  19. lifetime = (int) (distanceIn / velocity);
  20. //System.out.println("dist" + distanceIn);
  21. //System.out.println("vel" + velocity);
  22. }
  23. GraphicHelper.addParticle(particleType, worldIn,
  24. pos.x + ((Math.random() * (upper - lower) + lower)),
  25. pos.y + ((Math.random() * (upper - lower) + lower)),
  26. pos.z + ((Math.random() * (upper - lower) + lower)),
  27. (direction.x + ((Math.random() * (upperVelocity - lowerVelocity) + lowerVelocity))) * velocity,
  28. (direction.y + ((Math.random() * (upperVelocity - lowerVelocity) + lowerVelocity))) * velocity,
  29. (direction.z + ((Math.random() * (upperVelocity - lowerVelocity) + lowerVelocity))) * velocity,
  30. lifetime);
  31. //System.out.println(speed * (1 + acceleration*i));
  32. }
  33. }
  34.  
  35. /** Adds a particle with a custom lifetime to the world*/
  36. @OnlyIn(Dist.CLIENT)
  37. public static void addParticle(IParticleData particleData, World worldIn, double x, double y, double z, double xSpeed,
  38. double ySpeed, double zSpeed, int lifetime) {
  39. Minecraft mc = Minecraft.getInstance();
  40. ActiveRenderInfo activerenderinfo = mc.gameRenderer.getActiveRenderInfo();
  41. Particle particle;
  42. if (activerenderinfo.isValid() && mc.particles != null) {
  43. ParticleStatus particlestatus = getParticleStatus(false, mc, worldIn);
  44. if (particleData.getType().getAlwaysShow()) {
  45. particle = mc.particles.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
  46. assert particle != null;
  47. particle.setMaxAge(lifetime);
  48. } else if (activerenderinfo.getProjectedView().squareDistanceTo(x, y, z) > 1024.0D) {
  49. System.out.println("out of render range");
  50. } else {
  51. if (particlestatus == ParticleStatus.MINIMAL) System.out.println("minimal status");
  52. else {
  53. particle = mc.particles.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
  54. assert particle != null;
  55. particle.setMaxAge(lifetime);
  56. }
  57. }
  58. } else {
  59. System.out.println("null particle");
  60. }
  61. }
  62.  
  63. /** Gets particle status with custom implementation*/
  64. @OnlyIn(Dist.CLIENT)
  65. private static ParticleStatus getParticleStatus(boolean render, Minecraft mc, World worldIn) {
  66. ParticleStatus particlestatus = mc.gameSettings.particles;
  67. if (render && particlestatus == ParticleStatus.MINIMAL && worldIn.rand.nextInt(10) == 0) {
  68. particlestatus = ParticleStatus.DECREASED;
  69. }
  70. if (particlestatus == ParticleStatus.DECREASED && worldIn.rand.nextInt(3) == 0) {
  71. particlestatus = ParticleStatus.MINIMAL;
  72. }
  73. return particlestatus;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement