2025-11-24 22:52:51 +03:00

117 lines
4.7 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.client.particle;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.SingleQuadParticle;
import net.minecraft.client.renderer.item.ItemStackRenderState;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.particles.ItemParticleOption;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.data.AtlasIds;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
public class BreakingItemParticle
extends SingleQuadParticle {
private final float uo;
private final float vo;
private final SingleQuadParticle.Layer layer;
private BreakingItemParticle(ClientLevel level, double x, double y, double z, double xa, double ya, double za, TextureAtlasSprite sprite) {
this(level, x, y, z, sprite);
this.xd *= (double)0.1f;
this.yd *= (double)0.1f;
this.zd *= (double)0.1f;
this.xd += xa;
this.yd += ya;
this.zd += za;
}
protected BreakingItemParticle(ClientLevel level, double x, double y, double z, TextureAtlasSprite sprite) {
super(level, x, y, z, 0.0, 0.0, 0.0, sprite);
this.gravity = 1.0f;
this.quadSize /= 2.0f;
this.uo = this.random.nextFloat() * 3.0f;
this.vo = this.random.nextFloat() * 3.0f;
this.layer = sprite.atlasLocation() == TextureAtlas.LOCATION_BLOCKS ? SingleQuadParticle.Layer.TERRAIN : SingleQuadParticle.Layer.ITEMS;
}
@Override
protected float getU0() {
return this.sprite.getU((this.uo + 1.0f) / 4.0f);
}
@Override
protected float getU1() {
return this.sprite.getU(this.uo / 4.0f);
}
@Override
protected float getV0() {
return this.sprite.getV(this.vo / 4.0f);
}
@Override
protected float getV1() {
return this.sprite.getV((this.vo + 1.0f) / 4.0f);
}
@Override
public SingleQuadParticle.Layer getLayer() {
return this.layer;
}
public static class SnowballProvider
extends ItemParticleProvider<SimpleParticleType> {
@Override
public Particle createParticle(SimpleParticleType options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random) {
return new BreakingItemParticle(level, x, y, z, this.getSprite(new ItemStack(Items.SNOWBALL), level, random));
}
}
public static class CobwebProvider
extends ItemParticleProvider<SimpleParticleType> {
@Override
public Particle createParticle(SimpleParticleType options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random) {
return new BreakingItemParticle(level, x, y, z, this.getSprite(new ItemStack(Items.COBWEB), level, random));
}
}
public static class SlimeProvider
extends ItemParticleProvider<SimpleParticleType> {
@Override
public Particle createParticle(SimpleParticleType options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random) {
return new BreakingItemParticle(level, x, y, z, this.getSprite(new ItemStack(Items.SLIME_BALL), level, random));
}
}
public static class Provider
extends ItemParticleProvider<ItemParticleOption> {
@Override
public Particle createParticle(ItemParticleOption options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random) {
return new BreakingItemParticle(level, x, y, z, xAux, yAux, zAux, this.getSprite(options.getItem(), level, random));
}
}
public static abstract class ItemParticleProvider<T extends ParticleOptions>
implements ParticleProvider<T> {
private final ItemStackRenderState scratchRenderState = new ItemStackRenderState();
protected TextureAtlasSprite getSprite(ItemStack itemStack, ClientLevel level, RandomSource random) {
Minecraft.getInstance().getItemModelResolver().updateForTopItem(this.scratchRenderState, itemStack, ItemDisplayContext.GROUND, level, null, 0);
TextureAtlasSprite icon = this.scratchRenderState.pickParticleIcon(random);
return icon != null ? icon : Minecraft.getInstance().getAtlasManager().getAtlasOrThrow(AtlasIds.ITEMS).missingSprite();
}
}
}