66 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
	
		
			2.1 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.minecraft.client.particle;
 | |
| 
 | |
| import net.fabricmc.api.EnvType;
 | |
| import net.fabricmc.api.Environment;
 | |
| import net.minecraft.client.multiplayer.ClientLevel;
 | |
| import net.minecraft.core.particles.TrailParticleOption;
 | |
| import net.minecraft.util.ARGB;
 | |
| import net.minecraft.util.Mth;
 | |
| import net.minecraft.world.phys.Vec3;
 | |
| 
 | |
| @Environment(EnvType.CLIENT)
 | |
| public class TrailParticle extends TextureSheetParticle {
 | |
| 	private final Vec3 target;
 | |
| 
 | |
| 	TrailParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, Vec3 target, int color) {
 | |
| 		super(level, x, y, z, xSpeed, ySpeed, zSpeed);
 | |
| 		color = ARGB.scaleRGB(color, 0.875F + this.random.nextFloat() * 0.25F, 0.875F + this.random.nextFloat() * 0.25F, 0.875F + this.random.nextFloat() * 0.25F);
 | |
| 		this.rCol = ARGB.red(color) / 255.0F;
 | |
| 		this.gCol = ARGB.green(color) / 255.0F;
 | |
| 		this.bCol = ARGB.blue(color) / 255.0F;
 | |
| 		this.quadSize = 0.26F;
 | |
| 		this.target = target;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public ParticleRenderType getRenderType() {
 | |
| 		return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public void tick() {
 | |
| 		this.xo = this.x;
 | |
| 		this.yo = this.y;
 | |
| 		this.zo = this.z;
 | |
| 		if (this.age++ >= this.lifetime) {
 | |
| 			this.remove();
 | |
| 		} else {
 | |
| 			int i = this.lifetime - this.age;
 | |
| 			double d = 1.0 / i;
 | |
| 			this.x = Mth.lerp(d, this.x, this.target.x());
 | |
| 			this.y = Mth.lerp(d, this.y, this.target.y());
 | |
| 			this.z = Mth.lerp(d, this.z, this.target.z());
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	@Override
 | |
| 	public int getLightColor(float partialTick) {
 | |
| 		return 15728880;
 | |
| 	}
 | |
| 
 | |
| 	@Environment(EnvType.CLIENT)
 | |
| 	public static class Provider implements ParticleProvider<TrailParticleOption> {
 | |
| 		private final SpriteSet sprite;
 | |
| 
 | |
| 		public Provider(SpriteSet sprite) {
 | |
| 			this.sprite = sprite;
 | |
| 		}
 | |
| 
 | |
| 		public Particle createParticle(TrailParticleOption type, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
 | |
| 			TrailParticle trailParticle = new TrailParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, type.target(), type.color());
 | |
| 			trailParticle.pickSprite(this.sprite);
 | |
| 			trailParticle.setLifetime(type.duration());
 | |
| 			return trailParticle;
 | |
| 		}
 | |
| 	}
 | |
| }
 |