FallingParticle .java

net.minecraft.client.particle.FallingParticle (class): members: CURVE_ENDPOINT_TIME, ACCELERATION_SCALE, INITIAL_LIFETIME, spinAcceleration, swirlPeriod.

net.minecraft.client.particleclass100 linesclientextends SingleQuadParticle3.1 KB

API Surface (2)

SingleQuadParticle.Layer getLayer()
void tick()

Fields & Constants (19)

ACCELERATION_SCALE
INITIAL_LIFETIME
CURVE_ENDPOINT_TIME
rotSpeed
spinAcceleration
windBig
swirl
flowAway
xaFlowScale
zaFlowScale
swirlPeriod
level
x
y
z
sprite
fallAcceleration
sideAcceleration
scale

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

FallingParticle.java100 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
8
@Environment(EnvType.CLIENT)
9
public class FallingParticle extends SingleQuadParticle {
10
	private static final float ACCELERATION_SCALE = 0.0025F;
11
	private static final int INITIAL_LIFETIME = 300;
12
	private static final int CURVE_ENDPOINT_TIME = 300;
13
	private float rotSpeed = (float)Math.toRadians(this.random.nextBoolean() ? -30.0 : 30.0);
14
	private final float spinAcceleration = (float)Math.toRadians(this.random.nextBoolean() ? -5.0 : 5.0);
15
	private final float windBig;
16
	private final boolean swirl;
17
	private final boolean flowAway;
18
	private final double xaFlowScale;
19
	private final double zaFlowScale;
20
	private final double swirlPeriod;
21
22
	protected FallingParticle(
23
		final ClientLevel level,
24
		final double x,
25
		final double y,
26
		final double z,
27
		final TextureAtlasSprite sprite,
28
		final float fallAcceleration,
29
		final float sideAcceleration,
30
		final boolean swirl,
31
		final boolean flowAway,
32
		final float scale,
33
		final float startVelocity
34
	) {
35
		super(level, x, y, z, sprite);
36
		this.windBig = sideAcceleration;
37
		this.swirl = swirl;
38
		this.flowAway = flowAway;
39
		this.lifetime = 300;
40
		this.gravity = fallAcceleration * 1.2F * 0.0025F;
41
		float size = scale * (this.random.nextBoolean() ? 0.05F : 0.075F);
42
		this.quadSize = size;
43
		this.setSize(size, size);
44
		this.friction = 1.0F;
45
		this.yd = -startVelocity;
46
		float particleRandom = this.random.nextFloat();
47
		this.xaFlowScale = Math.cos(Math.toRadians(particleRandom * 60.0F)) * this.windBig;
48
		this.zaFlowScale = Math.sin(Math.toRadians(particleRandom * 60.0F)) * this.windBig;
49
		this.swirlPeriod = Math.toRadians(1000.0F + particleRandom * 3000.0F);
50
	}
51
52
	@Override
53
	public SingleQuadParticle.Layer getLayer() {
54
		return SingleQuadParticle.Layer.OPAQUE;
55
	}
56
57
	@Override
58
	public void tick() {
59
		this.xo = this.x;
60
		this.yo = this.y;
61
		this.zo = this.z;
62
		if (this.lifetime-- <= 0) {
63
			this.remove();
64
		}
65
66
		if (!this.removed) {
67
			float aliveTicks = 300 - this.lifetime;
68
			float relativeAge = Math.min(aliveTicks / 300.0F, 1.0F);
69
			double xa = 0.0;
70
			double za = 0.0;
71
			if (this.flowAway) {
72
				xa += this.xaFlowScale * Math.pow(relativeAge, 1.25);
73
				za += this.zaFlowScale * Math.pow(relativeAge, 1.25);
74
			}
75
76
			if (this.swirl) {
77
				xa += relativeAge * Math.cos(relativeAge * this.swirlPeriod) * this.windBig;
78
				za += relativeAge * Math.sin(relativeAge * this.swirlPeriod) * this.windBig;
79
			}
80
81
			this.xd += xa * 0.0025F;
82
			this.zd += za * 0.0025F;
83
			this.yd = this.yd - this.gravity;
84
			this.rotSpeed = this.rotSpeed + this.spinAcceleration / 20.0F;
85
			this.oRoll = this.roll;
86
			this.roll = this.roll + this.rotSpeed / 20.0F;
87
			this.move(this.xd, this.yd, this.zd);
88
			if (this.onGround || this.lifetime < 299 && (this.xd == 0.0 || this.zd == 0.0)) {
89
				this.remove();
90
			}
91
92
			if (!this.removed) {
93
				this.xd = this.xd * this.friction;
94
				this.yd = this.yd * this.friction;
95
				this.zd = this.zd * this.friction;
96
			}
97
		}
98
	}
99
}
100

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