FlyStraightTowardsParticle .java

net.minecraft.client.particle.FlyStraightTowardsParticle (class): members: OminousSpawnProvider, startColor, endColor, xStart, zStart, xd, yStart, yd, zd.

net.minecraft.client.particleclass111 linesclientextends SingleQuadParticle3.0 KB

API Surface (5)

SingleQuadParticle.Layer getLayer()
void move(final double xa, final double ya, final double za)
int getLightCoords(final float a)
void tick()
Particle createParticle(final SimpleParticleType 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 (12)

xStart
yStart
zStart
startColor
endColor
level
x
y
z
xd
yd
zd

Full Source

FlyStraightTowardsParticle.java111 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.SimpleParticleType;
8
import net.minecraft.util.ARGB;
9
import net.minecraft.util.LightCoordsUtil;
10
import net.minecraft.util.Mth;
11
import net.minecraft.util.RandomSource;
12
13
@Environment(EnvType.CLIENT)
14
public class FlyStraightTowardsParticle extends SingleQuadParticle {
15
	private final double xStart;
16
	private final double yStart;
17
	private final double zStart;
18
	private final int startColor;
19
	private final int endColor;
20
21
	private FlyStraightTowardsParticle(
22
		final ClientLevel level,
23
		final double x,
24
		final double y,
25
		final double z,
26
		final double xd,
27
		final double yd,
28
		final double zd,
29
		final int startColor,
30
		final int endColor,
31
		final TextureAtlasSprite sprite
32
	) {
33
		super(level, x, y, z, sprite);
34
		this.xd = xd;
35
		this.yd = yd;
36
		this.zd = zd;
37
		this.xStart = x;
38
		this.yStart = y;
39
		this.zStart = z;
40
		this.xo = x + xd;
41
		this.yo = y + yd;
42
		this.zo = z + zd;
43
		this.x = this.xo;
44
		this.y = this.yo;
45
		this.z = this.zo;
46
		this.quadSize = 0.1F * (this.random.nextFloat() * 0.5F + 0.2F);
47
		this.hasPhysics = false;
48
		this.lifetime = (int)(this.random.nextFloat() * 5.0F) + 25;
49
		this.startColor = startColor;
50
		this.endColor = endColor;
51
	}
52
53
	@Override
54
	public SingleQuadParticle.Layer getLayer() {
55
		return SingleQuadParticle.Layer.OPAQUE;
56
	}
57
58
	@Override
59
	public void move(final double xa, final double ya, final double za) {
60
	}
61
62
	@Override
63
	public int getLightCoords(final float a) {
64
		return LightCoordsUtil.withBlock(super.getLightCoords(a), 15);
65
	}
66
67
	@Override
68
	public void tick() {
69
		this.xo = this.x;
70
		this.yo = this.y;
71
		this.zo = this.z;
72
		if (this.age++ >= this.lifetime) {
73
			this.remove();
74
		} else {
75
			float normalizedAge = (float)this.age / this.lifetime;
76
			float posAlpha = 1.0F - normalizedAge;
77
			this.x = this.xStart + this.xd * posAlpha;
78
			this.y = this.yStart + this.yd * posAlpha;
79
			this.z = this.zStart + this.zd * posAlpha;
80
			int color = ARGB.srgbLerp(normalizedAge, this.startColor, this.endColor);
81
			this.setColor(ARGB.red(color) / 255.0F, ARGB.green(color) / 255.0F, ARGB.blue(color) / 255.0F);
82
			this.setAlpha(ARGB.alpha(color) / 255.0F);
83
		}
84
	}
85
86
	@Environment(EnvType.CLIENT)
87
	public static class OminousSpawnProvider implements ParticleProvider<SimpleParticleType> {
88
		private final SpriteSet sprite;
89
90
		public OminousSpawnProvider(final SpriteSet sprite) {
91
			this.sprite = sprite;
92
		}
93
94
		public Particle createParticle(
95
			final SimpleParticleType options,
96
			final ClientLevel level,
97
			final double x,
98
			final double y,
99
			final double z,
100
			final double xAux,
101
			final double yAux,
102
			final double zAux,
103
			final RandomSource random
104
		) {
105
			FlyStraightTowardsParticle particle = new FlyStraightTowardsParticle(level, x, y, z, xAux, yAux, zAux, -12210434, -1, this.sprite.get(random));
106
			particle.scale(Mth.randomBetween(level.getRandom(), 3.0F, 5.0F));
107
			return particle;
108
		}
109
	}
110
}
111

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