| 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.core.particles.PowerParticleOption;
|
| 7 | import net.minecraft.util.Mth;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 |
|
| 10 | @Environment(EnvType.CLIENT)
|
| 11 | public class DragonBreathParticle extends SingleQuadParticle {
|
| 12 | private static final int COLOR_MIN = 11993298;
|
| 13 | private static final int COLOR_MAX = 14614777;
|
| 14 | private static final float COLOR_MIN_RED = 0.7176471F;
|
| 15 | private static final float COLOR_MIN_GREEN = 0.0F;
|
| 16 | private static final float COLOR_MIN_BLUE = 0.8235294F;
|
| 17 | private static final float COLOR_MAX_RED = 0.8745098F;
|
| 18 | private static final float COLOR_MAX_GREEN = 0.0F;
|
| 19 | private static final float COLOR_MAX_BLUE = 0.9764706F;
|
| 20 | private boolean hasHitGround;
|
| 21 | private final SpriteSet sprites;
|
| 22 |
|
| 23 | private DragonBreathParticle(
|
| 24 | final ClientLevel level, final double x, final double y, final double z, final double xa, final double ya, final double za, final SpriteSet sprites
|
| 25 | ) {
|
| 26 | super(level, x, y, z, sprites.first());
|
| 27 | this.friction = 0.96F;
|
| 28 | this.xd = xa;
|
| 29 | this.yd = ya;
|
| 30 | this.zd = za;
|
| 31 | this.rCol = Mth.nextFloat(this.random, 0.7176471F, 0.8745098F);
|
| 32 | this.gCol = Mth.nextFloat(this.random, 0.0F, 0.0F);
|
| 33 | this.bCol = Mth.nextFloat(this.random, 0.8235294F, 0.9764706F);
|
| 34 | this.quadSize *= 0.75F;
|
| 35 | this.lifetime = (int)(20.0 / (this.random.nextFloat() * 0.8 + 0.2));
|
| 36 | this.hasHitGround = false;
|
| 37 | this.hasPhysics = false;
|
| 38 | this.sprites = sprites;
|
| 39 | this.setSpriteFromAge(sprites);
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | public void tick() {
|
| 44 | this.xo = this.x;
|
| 45 | this.yo = this.y;
|
| 46 | this.zo = this.z;
|
| 47 | if (this.age++ >= this.lifetime) {
|
| 48 | this.remove();
|
| 49 | } else {
|
| 50 | this.setSpriteFromAge(this.sprites);
|
| 51 | if (this.onGround) {
|
| 52 | this.yd = 0.0;
|
| 53 | this.hasHitGround = true;
|
| 54 | }
|
| 55 |
|
| 56 | if (this.hasHitGround) {
|
| 57 | this.yd += 0.002;
|
| 58 | }
|
| 59 |
|
| 60 | this.move(this.xd, this.yd, this.zd);
|
| 61 | if (this.y == this.yo) {
|
| 62 | this.xd *= 1.1;
|
| 63 | this.zd *= 1.1;
|
| 64 | }
|
| 65 |
|
| 66 | this.xd = this.xd * this.friction;
|
| 67 | this.zd = this.zd * this.friction;
|
| 68 | if (this.hasHitGround) {
|
| 69 | this.yd = this.yd * this.friction;
|
| 70 | }
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | @Override
|
| 75 | public SingleQuadParticle.Layer getLayer() {
|
| 76 | return SingleQuadParticle.Layer.OPAQUE;
|
| 77 | }
|
| 78 |
|
| 79 | @Override
|
| 80 | public float getQuadSize(final float a) {
|
| 81 | return this.quadSize * Mth.clamp((this.age + a) / this.lifetime * 32.0F, 0.0F, 1.0F);
|
| 82 | }
|
| 83 |
|
| 84 | @Environment(EnvType.CLIENT)
|
| 85 | public static class Provider implements ParticleProvider<PowerParticleOption> {
|
| 86 | private final SpriteSet sprites;
|
| 87 |
|
| 88 | public Provider(final SpriteSet sprites) {
|
| 89 | this.sprites = sprites;
|
| 90 | }
|
| 91 |
|
| 92 | public Particle createParticle(
|
| 93 | final PowerParticleOption options,
|
| 94 | final ClientLevel level,
|
| 95 | final double x,
|
| 96 | final double y,
|
| 97 | final double z,
|
| 98 | final double xAux,
|
| 99 | final double yAux,
|
| 100 | final double zAux,
|
| 101 | final RandomSource random
|
| 102 | ) {
|
| 103 | DragonBreathParticle particle = new DragonBreathParticle(level, x, y, z, xAux, yAux, zAux, this.sprites);
|
| 104 | particle.setPower(options.getPower());
|
| 105 | return particle;
|
| 106 | }
|
| 107 | }
|
| 108 | }
|
| 109 |
|