SingleQuadParticle .java

net.minecraft.client.particle.SingleQuadParticle (class): members: extractRotatedQuad, FacingCameraMode, setSpriteFromAge, setSprite, quadSize, oRoll.

net.minecraft.client.particleclass206 linesclientextends Particle6.9 KB

API Surface (18)

SingleQuadParticle.FacingCameraMode getFacingCameraMode()
void extract(final QuadParticleRenderState particleTypeRenderState, final Camera camera, final float partialTickTime)
void extractRotatedQuad(final QuadParticleRenderState particleTypeRenderState, final Camera camera, final Quaternionf rotation, final float partialTickTime)
void extractRotatedQuad(final QuadParticleRenderState particleTypeRenderState, final Quaternionf rotation, final float x, final float y, final float z, final float partialTickTime)
float getQuadSize(final float a)
Particle scale(final float scale)
ParticleRenderType getGroup()
void setSpriteFromAge(final SpriteSet sprites)
void setSprite(final TextureAtlasSprite icon)
float getU0()
float getU1()
float getV0()
float getV1()
void setColor(final float r, final float g, final float b)
void setAlpha(final float alpha)
String toString()
record Layer(boolean translucent, Identifier textureAtlasLocation, RenderPipeline pipeline, @Nullable OitPipelineSet oitPipelineSet)
SingleQuadParticle.Layer bySprite(final TextureAtlasSprite sprite)

Fields & Constants (11)

quadSize
rCol
gCol
bCol
alpha
roll
oRoll
sprite
za
rotation
z

String literals (3)

", Pos ("
"), RGBA ("
"), Age "

Full Source

SingleQuadParticle.java206 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.particle;
2
3
import com.mojang.renderpearl.api.pipeline.RenderPipeline;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.client.Camera;
7
import net.minecraft.client.multiplayer.ClientLevel;
8
import net.minecraft.client.renderer.RenderPipelines;
9
import net.minecraft.client.renderer.oit.OitPipelineSet;
10
import net.minecraft.client.renderer.state.level.QuadParticleRenderState;
11
import net.minecraft.client.renderer.texture.TextureAtlas;
12
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
13
import net.minecraft.resources.Identifier;
14
import net.minecraft.util.ARGB;
15
import net.minecraft.util.Mth;
16
import net.minecraft.world.phys.Vec3;
17
import org.joml.Quaternionf;
18
import org.jspecify.annotations.Nullable;
19
20
@Environment(EnvType.CLIENT)
21
public abstract class SingleQuadParticle extends Particle {
22
	protected float quadSize;
23
	protected float rCol = 1.0F;
24
	protected float gCol = 1.0F;
25
	protected float bCol = 1.0F;
26
	protected float alpha = 1.0F;
27
	protected float roll;
28
	protected float oRoll;
29
	protected TextureAtlasSprite sprite;
30
31
	protected SingleQuadParticle(final ClientLevel level, final double x, final double y, final double z, final TextureAtlasSprite sprite) {
32
		super(level, x, y, z);
33
		this.sprite = sprite;
34
		this.quadSize = 0.1F * (this.random.nextFloat() * 0.5F + 0.5F) * 2.0F;
35
	}
36
37
	protected SingleQuadParticle(
38
		final ClientLevel level, final double x, final double y, final double z, final double xa, final double ya, final double za, final TextureAtlasSprite sprite
39
	) {
40
		super(level, x, y, z, xa, ya, za);
41
		this.sprite = sprite;
42
		this.quadSize = 0.1F * (this.random.nextFloat() * 0.5F + 0.5F) * 2.0F;
43
	}
44
45
	public SingleQuadParticle.FacingCameraMode getFacingCameraMode() {
46
		return SingleQuadParticle.FacingCameraMode.LOOKAT_XYZ;
47
	}
48
49
	public void extract(final QuadParticleRenderState particleTypeRenderState, final Camera camera, final float partialTickTime) {
50
		Quaternionf rotation = new Quaternionf();
51
		this.getFacingCameraMode().setRotation(rotation, camera, partialTickTime);
52
		if (this.roll != 0.0F) {
53
			rotation.rotateZ(Mth.lerp(partialTickTime, this.oRoll, this.roll));
54
		}
55
56
		this.extractRotatedQuad(particleTypeRenderState, camera, rotation, partialTickTime);
57
	}
58
59
	protected void extractRotatedQuad(
60
		final QuadParticleRenderState particleTypeRenderState, final Camera camera, final Quaternionf rotation, final float partialTickTime
61
	) {
62
		Vec3 pos = camera.position();
63
		float x = (float)(Mth.lerp(partialTickTime, this.xo, this.x) - pos.x());
64
		float y = (float)(Mth.lerp(partialTickTime, this.yo, this.y) - pos.y());
65
		float z = (float)(Mth.lerp(partialTickTime, this.zo, this.z) - pos.z());
66
		this.extractRotatedQuad(particleTypeRenderState, rotation, x, y, z, partialTickTime);
67
	}
68
69
	protected void extractRotatedQuad(
70
		final QuadParticleRenderState particleTypeRenderState, final Quaternionf rotation, final float x, final float y, final float z, final float partialTickTime
71
	) {
72
		particleTypeRenderState.add(
73
			this.getLayer(),
74
			x,
75
			y,
76
			z,
77
			rotation.x,
78
			rotation.y,
79
			rotation.z,
80
			rotation.w,
81
			this.getQuadSize(partialTickTime),
82
			this.getU0(),
83
			this.getU1(),
84
			this.getV0(),
85
			this.getV1(),
86
			ARGB.colorFromFloat(this.alpha, this.rCol, this.gCol, this.bCol),
87
			this.getLightCoords(partialTickTime)
88
		);
89
	}
90
91
	public float getQuadSize(final float a) {
92
		return this.quadSize;
93
	}
94
95
	@Override
96
	public Particle scale(final float scale) {
97
		this.quadSize *= scale;
98
		return super.scale(scale);
99
	}
100
101
	@Override
102
	public ParticleRenderType getGroup() {
103
		return ParticleRenderType.SINGLE_QUADS;
104
	}
105
106
	public void setSpriteFromAge(final SpriteSet sprites) {
107
		if (!this.removed) {
108
			this.setSprite(sprites.get(this.age, this.lifetime));
109
		}
110
	}
111
112
	protected void setSprite(final TextureAtlasSprite icon) {
113
		this.sprite = icon;
114
	}
115
116
	protected float getU0() {
117
		return this.sprite.getU0();
118
	}
119
120
	protected float getU1() {
121
		return this.sprite.getU1();
122
	}
123
124
	protected float getV0() {
125
		return this.sprite.getV0();
126
	}
127
128
	protected float getV1() {
129
		return this.sprite.getV1();
130
	}
131
132
	protected abstract SingleQuadParticle.Layer getLayer();
133
134
	public void setColor(final float r, final float g, final float b) {
135
		this.rCol = r;
136
		this.gCol = g;
137
		this.bCol = b;
138
	}
139
140
	protected void setAlpha(final float alpha) {
141
		this.alpha = alpha;
142
	}
143
144
	@Override
145
	public String toString() {
146
		return this.getClass().getSimpleName()
147
			+ ", Pos ("
148
			+ this.x
149
			+ ","
150
			+ this.y
151
			+ ","
152
			+ this.z
153
			+ "), RGBA ("
154
			+ this.rCol
155
			+ ","
156
			+ this.gCol
157
			+ ","
158
			+ this.bCol
159
			+ ","
160
			+ this.alpha
161
			+ "), Age "
162
			+ this.age;
163
	}
164
165
	@Environment(EnvType.CLIENT)
166
	public interface FacingCameraMode {
167
		SingleQuadParticle.FacingCameraMode LOOKAT_XYZ = (target, camera, partialTickTime) -> target.set(camera.rotation());
168
		SingleQuadParticle.FacingCameraMode LOOKAT_Y = (target, camera, partialTickTime) -> target.set(0.0F, camera.rotation().y, 0.0F, camera.rotation().w);
169
170
		void setRotation(final Quaternionf target, final Camera camera, final float partialTickTime);
171
	}
172
173
	@Environment(EnvType.CLIENT)
174
	public record Layer(boolean translucent, Identifier textureAtlasLocation, RenderPipeline pipeline, @Nullable OitPipelineSet oitPipelineSet) {
175
		public static final SingleQuadParticle.Layer OPAQUE_TERRAIN = new SingleQuadParticle.Layer(
176
			false, TextureAtlas.LOCATION_BLOCKS, RenderPipelines.OPAQUE_PARTICLE
177
		);
178
		public static final SingleQuadParticle.Layer TRANSLUCENT_TERRAIN = new SingleQuadParticle.Layer(
179
			true, TextureAtlas.LOCATION_BLOCKS, RenderPipelines.TRANSLUCENT_PARTICLE, RenderPipelines.OIT_PARTICLE
180
		);
181
		public static final SingleQuadParticle.Layer OPAQUE_ITEMS = new SingleQuadParticle.Layer(false, TextureAtlas.LOCATION_ITEMS, RenderPipelines.OPAQUE_PARTICLE);
182
		public static final SingleQuadParticle.Layer TRANSLUCENT_ITEMS = new SingleQuadParticle.Layer(
183
			true, TextureAtlas.LOCATION_ITEMS, RenderPipelines.TRANSLUCENT_PARTICLE, RenderPipelines.OIT_PARTICLE
184
		);
185
		public static final SingleQuadParticle.Layer OPAQUE = new SingleQuadParticle.Layer(false, TextureAtlas.LOCATION_PARTICLES, RenderPipelines.OPAQUE_PARTICLE);
186
		public static final SingleQuadParticle.Layer TRANSLUCENT = new SingleQuadParticle.Layer(
187
			true, TextureAtlas.LOCATION_PARTICLES, RenderPipelines.TRANSLUCENT_PARTICLE, RenderPipelines.OIT_PARTICLE
188
		);
189
190
		public Layer(final boolean translucent, final Identifier textureAtlasLocation, final RenderPipeline pipeline) {
191
			this(translucent, textureAtlasLocation, pipeline, null);
192
		}
193
194
		public static SingleQuadParticle.Layer bySprite(final TextureAtlasSprite sprite) {
195
			boolean translucent = sprite.transparency().hasTranslucent();
196
			if (sprite.atlasLocation().equals(TextureAtlas.LOCATION_BLOCKS)) {
197
				return translucent ? TRANSLUCENT_TERRAIN : OPAQUE_TERRAIN;
198
			} else if (sprite.atlasLocation().equals(TextureAtlas.LOCATION_ITEMS)) {
199
				return translucent ? TRANSLUCENT_ITEMS : OPAQUE_ITEMS;
200
			} else {
201
				return translucent ? TRANSLUCENT : OPAQUE;
202
			}
203
		}
204
	}
205
}
206

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