| 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.RandomSource;
|
| 9 |
|
| 10 | @Environment(EnvType.CLIENT)
|
| 11 | public class CampfireSmokeParticle extends SingleQuadParticle {
|
| 12 | private CampfireSmokeParticle(
|
| 13 | final ClientLevel level,
|
| 14 | final double x,
|
| 15 | final double y,
|
| 16 | final double z,
|
| 17 | final double xa,
|
| 18 | final double ya,
|
| 19 | final double za,
|
| 20 | final boolean isSignalFire,
|
| 21 | final TextureAtlasSprite sprite
|
| 22 | ) {
|
| 23 | super(level, x, y, z, sprite);
|
| 24 | this.scale(3.0F);
|
| 25 | this.setSize(0.25F, 0.25F);
|
| 26 | if (isSignalFire) {
|
| 27 | this.lifetime = this.random.nextInt(50) + 280;
|
| 28 | } else {
|
| 29 | this.lifetime = this.random.nextInt(50) + 80;
|
| 30 | }
|
| 31 |
|
| 32 | this.gravity = 3.0E-6F;
|
| 33 | this.xd = xa;
|
| 34 | this.yd = ya + this.random.nextFloat() / 500.0F;
|
| 35 | this.zd = za;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public void tick() {
|
| 40 | this.xo = this.x;
|
| 41 | this.yo = this.y;
|
| 42 | this.zo = this.z;
|
| 43 | if (this.age++ < this.lifetime && !(this.alpha <= 0.0F)) {
|
| 44 | this.xd = this.xd + this.random.nextFloat() / 5000.0F * (this.random.nextBoolean() ? 1 : -1);
|
| 45 | this.zd = this.zd + this.random.nextFloat() / 5000.0F * (this.random.nextBoolean() ? 1 : -1);
|
| 46 | this.yd = this.yd - this.gravity;
|
| 47 | this.move(this.xd, this.yd, this.zd);
|
| 48 | if (this.age >= this.lifetime - 60 && this.alpha > 0.01F) {
|
| 49 | this.alpha -= 0.015F;
|
| 50 | }
|
| 51 | } else {
|
| 52 | this.remove();
|
| 53 | }
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | public SingleQuadParticle.Layer getLayer() {
|
| 58 | return SingleQuadParticle.Layer.TRANSLUCENT;
|
| 59 | }
|
| 60 |
|
| 61 | @Environment(EnvType.CLIENT)
|
| 62 | public static class CosyProvider implements ParticleProvider<SimpleParticleType> {
|
| 63 | private final SpriteSet sprites;
|
| 64 |
|
| 65 | public CosyProvider(final SpriteSet sprites) {
|
| 66 | this.sprites = sprites;
|
| 67 | }
|
| 68 |
|
| 69 | public Particle createParticle(
|
| 70 | final SimpleParticleType options,
|
| 71 | final ClientLevel level,
|
| 72 | final double x,
|
| 73 | final double y,
|
| 74 | final double z,
|
| 75 | final double xAux,
|
| 76 | final double yAux,
|
| 77 | final double zAux,
|
| 78 | final RandomSource random
|
| 79 | ) {
|
| 80 | CampfireSmokeParticle particle = new CampfireSmokeParticle(level, x, y, z, xAux, yAux, zAux, false, this.sprites.get(random));
|
| 81 | particle.setAlpha(0.9F);
|
| 82 | return particle;
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | @Environment(EnvType.CLIENT)
|
| 87 | public static class SignalProvider implements ParticleProvider<SimpleParticleType> {
|
| 88 | private final SpriteSet sprites;
|
| 89 |
|
| 90 | public SignalProvider(final SpriteSet sprites) {
|
| 91 | this.sprites = sprites;
|
| 92 | }
|
| 93 |
|
| 94 | public Particle createParticle(
|
| 95 | final SimpleParticleType options,
|
| 96 | final ClientLevel level,
|
| 97 | final double x,
|
| 98 | final double y,
|
| 99 | final double z,
|
| 100 | final double xAux,
|
| 101 | final double yAux,
|
| 102 | final double zAux,
|
| 103 | final RandomSource random
|
| 104 | ) {
|
| 105 | CampfireSmokeParticle particle = new CampfireSmokeParticle(level, x, y, z, xAux, yAux, zAux, true, this.sprites.get(random));
|
| 106 | particle.setAlpha(0.95F);
|
| 107 | return particle;
|
| 108 | }
|
| 109 | }
|
| 110 | }
|
| 111 |
|