FallingDustParticle .java

net.minecraft.client.particle.FallingDustParticle (class): members: rotSpeed, getQuadSize, sprites, getLayer, Provider, tick. imports: FallingBlock.

net.minecraft.client.particleclass114 linesclientextends SingleQuadParticle3.4 KB

API Surface (3)

SingleQuadParticle.Layer getLayer()
float getQuadSize(final float a)
void tick()

Fields & Constants (3)

rotSpeed
sprites
b

Full Source

FallingDustParticle.java114 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.Mth;
11
import net.minecraft.util.RandomSource;
12
import net.minecraft.world.level.block.FallingBlock;
13
import net.minecraft.world.level.block.RenderShape;
14
import net.minecraft.world.level.block.state.BlockState;
15
import org.jspecify.annotations.Nullable;
16
17
@Environment(EnvType.CLIENT)
18
public class FallingDustParticle extends SingleQuadParticle {
19
	private final float rotSpeed;
20
	private final SpriteSet sprites;
21
22
	private FallingDustParticle(
23
		final ClientLevel level, final double x, final double y, final double z, final float r, final float g, final float b, final SpriteSet sprites
24
	) {
25
		super(level, x, y, z, sprites.first());
26
		this.sprites = sprites;
27
		this.rCol = r;
28
		this.gCol = g;
29
		this.bCol = b;
30
		float scale = 0.9F;
31
		this.quadSize *= 0.67499995F;
32
		int baseLifetime = (int)(32.0 / (this.random.nextFloat() * 0.8 + 0.2));
33
		this.lifetime = (int)Math.max(baseLifetime * 0.9F, 1.0F);
34
		this.setSpriteFromAge(sprites);
35
		this.rotSpeed = (this.random.nextFloat() - 0.5F) * 0.1F;
36
		this.roll = this.random.nextFloat() * (float) (Math.PI * 2);
37
	}
38
39
	@Override
40
	public SingleQuadParticle.Layer getLayer() {
41
		return SingleQuadParticle.Layer.OPAQUE;
42
	}
43
44
	@Override
45
	public float getQuadSize(final float a) {
46
		return this.quadSize * Mth.clamp((this.age + a) / this.lifetime * 32.0F, 0.0F, 1.0F);
47
	}
48
49
	@Override
50
	public void tick() {
51
		this.xo = this.x;
52
		this.yo = this.y;
53
		this.zo = this.z;
54
		if (this.age++ >= this.lifetime) {
55
			this.remove();
56
		} else {
57
			this.setSpriteFromAge(this.sprites);
58
			this.oRoll = this.roll;
59
			this.roll = this.roll + (float) Math.PI * this.rotSpeed * 2.0F;
60
			if (this.onGround) {
61
				this.oRoll = this.roll = 0.0F;
62
			}
63
64
			this.move(this.xd, this.yd, this.zd);
65
			this.yd -= 0.003F;
66
			this.yd = Math.max(this.yd, -0.14F);
67
		}
68
	}
69
70
	@Environment(EnvType.CLIENT)
71
	public static class Provider implements ParticleProvider<BlockParticleOption> {
72
		private final SpriteSet sprite;
73
74
		public Provider(final SpriteSet sprite) {
75
			this.sprite = sprite;
76
		}
77
78
		public @Nullable Particle createParticle(
79
			final BlockParticleOption options,
80
			final ClientLevel level,
81
			final double x,
82
			final double y,
83
			final double z,
84
			final double xAux,
85
			final double yAux,
86
			final double zAux,
87
			final RandomSource random
88
		) {
89
			BlockState blockState = options.getState();
90
			if (!blockState.isAir() && blockState.getRenderShape() == RenderShape.INVISIBLE) {
91
				return null;
92
			}
93
94
			BlockPos pos = BlockPos.containing(x, y, z);
95
			int tintColor;
96
			if (blockState.getBlock() instanceof FallingBlock fallingBlock) {
97
				tintColor = fallingBlock.getDustColor(blockState, level, pos);
98
			} else {
99
				BlockTintSource tintSource = Minecraft.getInstance().getBlockColors().getTintSource(blockState, 0);
100
				if (tintSource != null) {
101
					tintColor = tintSource.colorAsTerrainParticle(blockState, level, pos);
102
				} else {
103
					tintColor = blockState.getMapColor(level, pos).col;
104
				}
105
			}
106
107
			float r = (tintColor >> 16 & 0xFF) / 255.0F;
108
			float g = (tintColor >> 8 & 0xFF) / 255.0F;
109
			float b = (tintColor & 0xFF) / 255.0F;
110
			return new FallingDustParticle(level, x, y, z, r, g, b, this.sprite);
111
		}
112
	}
113
}
114

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