TerrainParticle .java

net.minecraft.client.particle.TerrainParticle (class): members: DustPillarProvider, CrumblingProvider, uo, vo, getU0, getU1, getV0, getV1, xAux, yAux, xa.

net.minecraft.client.particleclass163 linesclientextends SingleQuadParticle4.7 KB

API Surface (5)

SingleQuadParticle.Layer getLayer()
float getU0()
float getU1()
float getV0()
float getV1()

Fields & Constants (15)

layer
pos
uo
vo
za
level
x
y
z
xa
ya
blockState
options
xAux
yAux

Full Source

TerrainParticle.java163 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.Minecraft;
6
import net.minecraft.client.color.block.BlockTintSource;
7
import net.minecraft.client.multiplayer.ClientLevel;
8
import net.minecraft.core.BlockPos;
9
import net.minecraft.core.particles.BlockParticleOption;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.level.block.Blocks;
12
import net.minecraft.world.level.block.state.BlockState;
13
import org.jspecify.annotations.Nullable;
14
15
@Environment(EnvType.CLIENT)
16
public class TerrainParticle extends SingleQuadParticle {
17
	private final SingleQuadParticle.Layer layer;
18
	private final BlockPos pos;
19
	private final float uo;
20
	private final float vo;
21
22
	public TerrainParticle(
23
		final ClientLevel level, final double x, final double y, final double z, final double xa, final double ya, final double za, final BlockState blockState
24
	) {
25
		this(level, x, y, z, xa, ya, za, blockState, BlockPos.containing(x, y, z));
26
	}
27
28
	public TerrainParticle(
29
		final ClientLevel level,
30
		final double x,
31
		final double y,
32
		final double z,
33
		final double xa,
34
		final double ya,
35
		final double za,
36
		final BlockState blockState,
37
		final BlockPos pos
38
	) {
39
		super(level, x, y, z, xa, ya, za, Minecraft.getInstance().getModelManager().getBlockStateModelSet().getParticleMaterial(blockState).sprite());
40
		this.pos = pos;
41
		this.gravity = 1.0F;
42
		this.rCol = 0.6F;
43
		this.gCol = 0.6F;
44
		this.bCol = 0.6F;
45
		BlockTintSource tintSource = Minecraft.getInstance().getBlockColors().getTintSource(blockState, 0);
46
		if (tintSource != null) {
47
			int col = tintSource.colorAsTerrainParticle(blockState, level, pos);
48
			this.rCol *= (col >> 16 & 0xFF) / 255.0F;
49
			this.gCol *= (col >> 8 & 0xFF) / 255.0F;
50
			this.bCol *= (col & 0xFF) / 255.0F;
51
		}
52
53
		this.quadSize /= 2.0F;
54
		this.uo = this.random.nextFloat() * 3.0F;
55
		this.vo = this.random.nextFloat() * 3.0F;
56
		this.layer = SingleQuadParticle.Layer.bySprite(this.sprite);
57
	}
58
59
	@Override
60
	public SingleQuadParticle.Layer getLayer() {
61
		return this.layer;
62
	}
63
64
	@Override
65
	protected float getU0() {
66
		return this.sprite.getU((this.uo + 1.0F) / 4.0F);
67
	}
68
69
	@Override
70
	protected float getU1() {
71
		return this.sprite.getU(this.uo / 4.0F);
72
	}
73
74
	@Override
75
	protected float getV0() {
76
		return this.sprite.getV(this.vo / 4.0F);
77
	}
78
79
	@Override
80
	protected float getV1() {
81
		return this.sprite.getV((this.vo + 1.0F) / 4.0F);
82
	}
83
84
	private static @Nullable TerrainParticle createTerrainParticle(
85
		final BlockParticleOption options,
86
		final ClientLevel level,
87
		final double x,
88
		final double y,
89
		final double z,
90
		final double xAux,
91
		final double yAux,
92
		final double zAux
93
	) {
94
		BlockState state = options.getState();
95
		return !state.isAir() && !state.is(Blocks.MOVING_PISTON) && state.shouldSpawnTerrainParticles()
96
			? new TerrainParticle(level, x, y, z, xAux, yAux, zAux, state)
97
			: null;
98
	}
99
100
	@Environment(EnvType.CLIENT)
101
	public static class CrumblingProvider implements ParticleProvider<BlockParticleOption> {
102
		public @Nullable Particle createParticle(
103
			final BlockParticleOption options,
104
			final ClientLevel level,
105
			final double x,
106
			final double y,
107
			final double z,
108
			final double xAux,
109
			final double yAux,
110
			final double zAux,
111
			final RandomSource random
112
		) {
113
			Particle particle = TerrainParticle.createTerrainParticle(options, level, x, y, z, xAux, yAux, zAux);
114
			if (particle != null) {
115
				particle.setParticleSpeed(0.0, 0.0, 0.0);
116
				particle.setLifetime(random.nextInt(10) + 1);
117
			}
118
119
			return particle;
120
		}
121
	}
122
123
	@Environment(EnvType.CLIENT)
124
	public static class DustPillarProvider implements ParticleProvider<BlockParticleOption> {
125
		public @Nullable Particle createParticle(
126
			final BlockParticleOption options,
127
			final ClientLevel level,
128
			final double x,
129
			final double y,
130
			final double z,
131
			final double xAux,
132
			final double yAux,
133
			final double zAux,
134
			final RandomSource random
135
		) {
136
			Particle particle = TerrainParticle.createTerrainParticle(options, level, x, y, z, xAux, yAux, zAux);
137
			if (particle != null) {
138
				particle.setParticleSpeed(random.nextGaussian() / 30.0, yAux + random.nextGaussian() / 2.0, random.nextGaussian() / 30.0);
139
				particle.setLifetime(random.nextInt(20) + 20);
140
			}
141
142
			return particle;
143
		}
144
	}
145
146
	@Environment(EnvType.CLIENT)
147
	public static class Provider implements ParticleProvider<BlockParticleOption> {
148
		public @Nullable Particle createParticle(
149
			final BlockParticleOption options,
150
			final ClientLevel level,
151
			final double x,
152
			final double y,
153
			final double z,
154
			final double xAux,
155
			final double yAux,
156
			final double zAux,
157
			final RandomSource random
158
		) {
159
			return TerrainParticle.createTerrainParticle(options, level, x, y, z, xAux, yAux, zAux);
160
		}
161
	}
162
}
163

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