| 1 | package net.minecraft.client.particle;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 6 | import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
| 7 | import net.minecraft.core.particles.SimpleParticleType;
|
| 8 | import net.minecraft.util.Mth;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 |
|
| 11 | @Environment(EnvType.CLIENT)
|
| 12 | public class CritParticle extends SingleQuadParticle {
|
| 13 | private CritParticle(
|
| 14 | final ClientLevel level, final double x, final double y, final double z, final double xa, final double ya, final double za, final TextureAtlasSprite sprite
|
| 15 | ) {
|
| 16 | super(level, x, y, z, 0.0, 0.0, 0.0, sprite);
|
| 17 | this.friction = 0.7F;
|
| 18 | this.gravity = 0.5F;
|
| 19 | this.xd *= 0.1F;
|
| 20 | this.yd *= 0.1F;
|
| 21 | this.zd *= 0.1F;
|
| 22 | this.xd += xa * 0.4;
|
| 23 | this.yd += ya * 0.4;
|
| 24 | this.zd += za * 0.4;
|
| 25 | float col = this.random.nextFloat() * 0.3F + 0.6F;
|
| 26 | this.rCol = col;
|
| 27 | this.gCol = col;
|
| 28 | this.bCol = col;
|
| 29 | this.quadSize *= 0.75F;
|
| 30 | this.lifetime = Math.max((int)(6.0 / (this.random.nextFloat() * 0.8 + 0.6)), 1);
|
| 31 | this.hasPhysics = false;
|
| 32 | this.tick();
|
| 33 | }
|
| 34 |
|
| 35 | @Override
|
| 36 | public float getQuadSize(final float a) {
|
| 37 | return this.quadSize * Mth.clamp((this.age + a) / this.lifetime * 32.0F, 0.0F, 1.0F);
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | public void tick() {
|
| 42 | super.tick();
|
| 43 | this.gCol *= 0.96F;
|
| 44 | this.bCol *= 0.9F;
|
| 45 | }
|
| 46 |
|
| 47 | @Override
|
| 48 | public SingleQuadParticle.Layer getLayer() {
|
| 49 | return SingleQuadParticle.Layer.OPAQUE;
|
| 50 | }
|
| 51 |
|
| 52 | @Environment(EnvType.CLIENT)
|
| 53 | public static class DamageIndicatorProvider implements ParticleProvider<SimpleParticleType> {
|
| 54 | private final SpriteSet sprite;
|
| 55 |
|
| 56 | public DamageIndicatorProvider(final SpriteSet sprite) {
|
| 57 | this.sprite = sprite;
|
| 58 | }
|
| 59 |
|
| 60 | public Particle createParticle(
|
| 61 | final SimpleParticleType options,
|
| 62 | final ClientLevel level,
|
| 63 | final double x,
|
| 64 | final double y,
|
| 65 | final double z,
|
| 66 | final double xAux,
|
| 67 | final double yAux,
|
| 68 | final double zAux,
|
| 69 | final RandomSource random
|
| 70 | ) {
|
| 71 | CritParticle particle = new CritParticle(level, x, y, z, xAux, yAux + 1.0, zAux, this.sprite.get(random));
|
| 72 | particle.setLifetime(20);
|
| 73 | return particle;
|
| 74 | }
|
| 75 | }
|
| 76 |
|
| 77 | @Environment(EnvType.CLIENT)
|
| 78 | public static class MagicProvider implements ParticleProvider<SimpleParticleType> {
|
| 79 | private final SpriteSet sprite;
|
| 80 |
|
| 81 | public MagicProvider(final SpriteSet sprite) {
|
| 82 | this.sprite = sprite;
|
| 83 | }
|
| 84 |
|
| 85 | public Particle createParticle(
|
| 86 | final SimpleParticleType options,
|
| 87 | final ClientLevel level,
|
| 88 | final double x,
|
| 89 | final double y,
|
| 90 | final double z,
|
| 91 | final double xAux,
|
| 92 | final double yAux,
|
| 93 | final double zAux,
|
| 94 | final RandomSource random
|
| 95 | ) {
|
| 96 | CritParticle particle = new CritParticle(level, x, y, z, xAux, yAux, zAux, this.sprite.get(random));
|
| 97 | particle.rCol *= 0.3F;
|
| 98 | particle.gCol *= 0.8F;
|
| 99 | return particle;
|
| 100 | }
|
| 101 | }
|
| 102 |
|
| 103 | @Environment(EnvType.CLIENT)
|
| 104 | public static class Provider implements ParticleProvider<SimpleParticleType> {
|
| 105 | private final SpriteSet sprite;
|
| 106 |
|
| 107 | public Provider(final SpriteSet sprite) {
|
| 108 | this.sprite = sprite;
|
| 109 | }
|
| 110 |
|
| 111 | public Particle createParticle(
|
| 112 | final SimpleParticleType options,
|
| 113 | final ClientLevel level,
|
| 114 | final double x,
|
| 115 | final double y,
|
| 116 | final double z,
|
| 117 | final double xAux,
|
| 118 | final double yAux,
|
| 119 | final double zAux,
|
| 120 | final RandomSource random
|
| 121 | ) {
|
| 122 | return new CritParticle(level, x, y, z, xAux, yAux, zAux, this.sprite.get(random));
|
| 123 | }
|
| 124 | }
|
| 125 | }
|
| 126 |
|