TrailParticle .java

net.minecraft.client.particle.TrailParticle (class, 89 lines): members: zAux, xAux, yAux, getLightCoords, target, getLayer, color, Provider, level, tick.

net.minecraft.client.particleclass89 linesclientextends SingleQuadParticle2.4 KB

API Surface (4)

SingleQuadParticle.Layer getLayer()
void tick()
int getLightCoords(final float a)
Particle createParticle(final TrailParticleOption options, final ClientLevel level, final double x, final double y, final double z, final double xAux, final double yAux, final double zAux, final RandomSource random)

Fields & Constants (9)

target
level
x
y
z
xAux
yAux
zAux
color

Full Source

TrailParticle.java89 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.particle;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.multiplayer.ClientLevel;
6
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
7
import net.minecraft.core.particles.TrailParticleOption;
8
import net.minecraft.util.ARGB;
9
import net.minecraft.util.Mth;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.phys.Vec3;
12
13
@Environment(EnvType.CLIENT)
14
public class TrailParticle extends SingleQuadParticle {
15
	private final Vec3 target;
16
17
	private TrailParticle(
18
		final ClientLevel level,
19
		final double x,
20
		final double y,
21
		final double z,
22
		final double xAux,
23
		final double yAux,
24
		final double zAux,
25
		final Vec3 target,
26
		int color,
27
		final TextureAtlasSprite sprite
28
	) {
29
		super(level, x, y, z, xAux, yAux, zAux, sprite);
30
		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);
31
		this.rCol = ARGB.red(color) / 255.0F;
32
		this.gCol = ARGB.green(color) / 255.0F;
33
		this.bCol = ARGB.blue(color) / 255.0F;
34
		this.quadSize = 0.26F;
35
		this.target = target;
36
	}
37
38
	@Override
39
	public SingleQuadParticle.Layer getLayer() {
40
		return SingleQuadParticle.Layer.OPAQUE;
41
	}
42
43
	@Override
44
	public void tick() {
45
		this.xo = this.x;
46
		this.yo = this.y;
47
		this.zo = this.z;
48
		if (this.age++ >= this.lifetime) {
49
			this.remove();
50
		} else {
51
			int ticksRemaining = this.lifetime - this.age;
52
			double alpha = 1.0 / ticksRemaining;
53
			this.x = Mth.lerp(alpha, this.x, this.target.x());
54
			this.y = Mth.lerp(alpha, this.y, this.target.y());
55
			this.z = Mth.lerp(alpha, this.z, this.target.z());
56
		}
57
	}
58
59
	@Override
60
	public int getLightCoords(final float a) {
61
		return 15728880;
62
	}
63
64
	@Environment(EnvType.CLIENT)
65
	public static class Provider implements ParticleProvider<TrailParticleOption> {
66
		private final SpriteSet sprite;
67
68
		public Provider(final SpriteSet sprite) {
69
			this.sprite = sprite;
70
		}
71
72
		public Particle createParticle(
73
			final TrailParticleOption options,
74
			final ClientLevel level,
75
			final double x,
76
			final double y,
77
			final double z,
78
			final double xAux,
79
			final double yAux,
80
			final double zAux,
81
			final RandomSource random
82
		) {
83
			TrailParticle particle = new TrailParticle(level, x, y, z, xAux, yAux, zAux, options.target(), options.color(), this.sprite.get(random));
84
			particle.setLifetime(options.duration());
85
			return particle;
86
		}
87
	}
88
}
89

Decompiled Minecraft 26.3 source of TrailParticle (net/minecraft/client/particle/TrailParticle.java) with Mojang official mappings, stored verbatim on the site.