jayhillx

FallingLeafParticle

Apr 30th, 2022 (edited)
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. package com.mysticsbiomes.client.particle;
  2.  
  3. import net.minecraft.client.multiplayer.ClientLevel;
  4. import net.minecraft.client.particle.*;
  5. import net.minecraft.core.particles.SimpleParticleType;
  6. import net.minecraftforge.api.distmarker.Dist;
  7. import net.minecraftforge.api.distmarker.OnlyIn;
  8.  
  9. @OnlyIn(Dist.CLIENT)
  10. public class FallingLeafParticle extends TextureSheetParticle {
  11.     private final float rotSpeed;
  12.  
  13.     protected FallingLeafParticle(ClientLevel level, double x, double y, double z) {
  14.         super(level, x, y, z);
  15.  
  16.         this.quadSize *= 1.0F;
  17.         this.lifetime = 80;
  18.         this.rotSpeed = ((float) Math.random() - 0.5F) * 0.1F;
  19.         this.roll = (float) Math.random() * ((float) Math.PI * 2F);
  20.     }
  21.  
  22.     public ParticleRenderType getRenderType() {
  23.         return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
  24.     }
  25.  
  26.     public void tick() {
  27.         this.xo = this.x;
  28.         this.yo = this.y;
  29.         this.zo = this.z;
  30.         if (this.age++ >= this.lifetime) {
  31.             this.remove();
  32.         } else {
  33.             this.oRoll = this.roll;
  34.             this.roll += (float)Math.PI * this.rotSpeed * 2.0F;
  35.             if (this.onGround) {
  36.                 this.oRoll = this.roll = 0.0F;
  37.             }
  38.  
  39.             this.move(this.xd, this.yd, this.zd);
  40.             this.yd -= 0.003F;
  41.             this.yd = Math.max(this.yd, -0.14F);
  42.         }
  43.     }
  44.  
  45.     @OnlyIn(Dist.CLIENT)
  46.     public static class Provider implements ParticleProvider<SimpleParticleType> {
  47.         private final SpriteSet sprite;
  48.  
  49.         public Provider(SpriteSet set) {
  50.             this.sprite = set;
  51.         }
  52.  
  53.         public Particle createParticle(SimpleParticleType option, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
  54.             FallingLeafParticle particle = new FallingLeafParticle(level, x, y, z);
  55.  
  56.             particle.setColor((float)xSpeed, (float)ySpeed, (float)zSpeed);
  57.  
  58.             particle.pickSprite(this.sprite);
  59.             return particle;
  60.         }
  61.     }
  62.  
  63. }
Add Comment
Please, Sign In to add comment