BreakingItemParticle .java

net.minecraft.client.particle.BreakingItemParticle (class): members: ItemParticleProvider, SulfurCubeProvider, SnowballProvider, CobwebProvider, uo, vo.

net.minecraft.client.particleclass173 linesclientextends SingleQuadParticle5.4 KB

API Surface (11)

float getU0()
float getU1()
float getV0()
float getV1()
SingleQuadParticle.Layer getLayer()
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)
TextureAtlasSprite getSprite(final ItemStackTemplate item, final ClientLevel level, final RandomSource random)
Particle createParticle(final ItemParticleOption 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)
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)
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)
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 (4)

uo
vo
layer
za

Full Source

BreakingItemParticle.java173 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.multiplayer.ClientLevel;
7
import net.minecraft.client.renderer.item.ItemStackRenderState;
8
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
9
import net.minecraft.client.resources.model.sprite.Material;
10
import net.minecraft.core.particles.ItemParticleOption;
11
import net.minecraft.core.particles.ParticleOptions;
12
import net.minecraft.core.particles.SimpleParticleType;
13
import net.minecraft.data.AtlasIds;
14
import net.minecraft.util.RandomSource;
15
import net.minecraft.world.item.ItemDisplayContext;
16
import net.minecraft.world.item.ItemStackTemplate;
17
import net.minecraft.world.item.Items;
18
19
@Environment(EnvType.CLIENT)
20
public class BreakingItemParticle extends SingleQuadParticle {
21
	private final float uo;
22
	private final float vo;
23
	private final SingleQuadParticle.Layer layer;
24
25
	private BreakingItemParticle(
26
		final ClientLevel level, final double x, final double y, final double z, final double xa, final double ya, final double za, final TextureAtlasSprite sprite
27
	) {
28
		this(level, x, y, z, sprite);
29
		this.xd *= 0.1F;
30
		this.yd *= 0.1F;
31
		this.zd *= 0.1F;
32
		this.xd += xa;
33
		this.yd += ya;
34
		this.zd += za;
35
	}
36
37
	protected BreakingItemParticle(final ClientLevel level, final double x, final double y, final double z, final TextureAtlasSprite sprite) {
38
		super(level, x, y, z, 0.0, 0.0, 0.0, sprite);
39
		this.gravity = 1.0F;
40
		this.quadSize /= 2.0F;
41
		this.uo = this.random.nextFloat() * 3.0F;
42
		this.vo = this.random.nextFloat() * 3.0F;
43
		this.layer = SingleQuadParticle.Layer.bySprite(sprite);
44
	}
45
46
	@Override
47
	protected float getU0() {
48
		return this.sprite.getU((this.uo + 1.0F) / 4.0F);
49
	}
50
51
	@Override
52
	protected float getU1() {
53
		return this.sprite.getU(this.uo / 4.0F);
54
	}
55
56
	@Override
57
	protected float getV0() {
58
		return this.sprite.getV(this.vo / 4.0F);
59
	}
60
61
	@Override
62
	protected float getV1() {
63
		return this.sprite.getV((this.vo + 1.0F) / 4.0F);
64
	}
65
66
	@Override
67
	public SingleQuadParticle.Layer getLayer() {
68
		return this.layer;
69
	}
70
71
	@Environment(EnvType.CLIENT)
72
	public static class CobwebProvider extends BreakingItemParticle.ItemParticleProvider<SimpleParticleType> {
73
		public Particle createParticle(
74
			final SimpleParticleType options,
75
			final ClientLevel level,
76
			final double x,
77
			final double y,
78
			final double z,
79
			final double xAux,
80
			final double yAux,
81
			final double zAux,
82
			final RandomSource random
83
		) {
84
			return new BreakingItemParticle(level, x, y, z, this.getSprite(new ItemStackTemplate(Items.COBWEB), level, random));
85
		}
86
	}
87
88
	@Environment(EnvType.CLIENT)
89
	public abstract static class ItemParticleProvider<T extends ParticleOptions> implements ParticleProvider<T> {
90
		private final ItemStackRenderState scratchRenderState = new ItemStackRenderState();
91
92
		protected TextureAtlasSprite getSprite(final ItemStackTemplate item, final ClientLevel level, final RandomSource random) {
93
			Minecraft.getInstance().getItemModelResolver().updateForTopItem(this.scratchRenderState, item.create(), ItemDisplayContext.GROUND, level, null, 0);
94
			Material.Baked material = this.scratchRenderState.pickParticleMaterial(random);
95
			return material != null ? material.sprite() : Minecraft.getInstance().getAtlasManager().getAtlasOrThrow(AtlasIds.ITEMS).missingSprite();
96
		}
97
	}
98
99
	@Environment(EnvType.CLIENT)
100
	public static class Provider extends BreakingItemParticle.ItemParticleProvider<ItemParticleOption> {
101
		public Particle createParticle(
102
			final ItemParticleOption options,
103
			final ClientLevel level,
104
			final double x,
105
			final double y,
106
			final double z,
107
			final double xAux,
108
			final double yAux,
109
			final double zAux,
110
			final RandomSource random
111
		) {
112
			return new BreakingItemParticle(level, x, y, z, xAux, yAux, zAux, this.getSprite(options.getItem(), level, random));
113
		}
114
	}
115
116
	@Environment(EnvType.CLIENT)
117
	public static class SlimeProvider extends BreakingItemParticle.ItemParticleProvider<SimpleParticleType> {
118
		public Particle createParticle(
119
			final SimpleParticleType options,
120
			final ClientLevel level,
121
			final double x,
122
			final double y,
123
			final double z,
124
			final double xAux,
125
			final double yAux,
126
			final double zAux,
127
			final RandomSource random
128
		) {
129
			return new BreakingItemParticle(level, x, y, z, this.getSprite(new ItemStackTemplate(Items.SLIME_BALL), level, random));
130
		}
131
	}
132
133
	@Environment(EnvType.CLIENT)
134
	public static class SnowballProvider extends BreakingItemParticle.ItemParticleProvider<SimpleParticleType> {
135
		public Particle createParticle(
136
			final SimpleParticleType options,
137
			final ClientLevel level,
138
			final double x,
139
			final double y,
140
			final double z,
141
			final double xAux,
142
			final double yAux,
143
			final double zAux,
144
			final RandomSource random
145
		) {
146
			return new BreakingItemParticle(level, x, y, z, this.getSprite(new ItemStackTemplate(Items.SNOWBALL), level, random));
147
		}
148
	}
149
150
	@Environment(EnvType.CLIENT)
151
	public static class SulfurCubeProvider extends BreakingItemParticle.ItemParticleProvider<SimpleParticleType> {
152
		private final SpriteSet sprites;
153
154
		public SulfurCubeProvider(final SpriteSet sprites) {
155
			this.sprites = sprites;
156
		}
157
158
		public Particle createParticle(
159
			final SimpleParticleType options,
160
			final ClientLevel level,
161
			final double x,
162
			final double y,
163
			final double z,
164
			final double xAux,
165
			final double yAux,
166
			final double zAux,
167
			final RandomSource random
168
		) {
169
			return new BreakingItemParticle(level, x, y, z, this.sprites.first());
170
		}
171
	}
172
}
173

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