| 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.ParticleTypes;
|
| 8 | import net.minecraft.core.particles.SimpleParticleType;
|
| 9 | import net.minecraft.util.LightCoordsUtil;
|
| 10 | import net.minecraft.util.RandomSource;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public class LavaParticle extends SingleQuadParticle {
|
| 14 | private LavaParticle(final ClientLevel level, final double x, final double y, final double z, final TextureAtlasSprite sprite) {
|
| 15 | super(level, x, y, z, 0.0, 0.0, 0.0, sprite);
|
| 16 | this.gravity = 0.75F;
|
| 17 | this.friction = 0.999F;
|
| 18 | this.xd *= 0.8F;
|
| 19 | this.yd *= 0.8F;
|
| 20 | this.zd *= 0.8F;
|
| 21 | this.yd = this.random.nextFloat() * 0.4F + 0.05F;
|
| 22 | this.quadSize = this.quadSize * (this.random.nextFloat() * 2.0F + 0.2F);
|
| 23 | this.lifetime = (int)(16.0 / (this.random.nextFloat() * 0.8 + 0.2));
|
| 24 | }
|
| 25 |
|
| 26 | @Override
|
| 27 | public SingleQuadParticle.Layer getLayer() {
|
| 28 | return SingleQuadParticle.Layer.OPAQUE;
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | public int getLightCoords(final float a) {
|
| 33 | return LightCoordsUtil.withBlock(super.getLightCoords(a), 15);
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | public float getQuadSize(final float a) {
|
| 38 | float s = (this.age + a) / this.lifetime;
|
| 39 | return this.quadSize * (1.0F - s * s);
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | public void tick() {
|
| 44 | super.tick();
|
| 45 | if (!this.removed) {
|
| 46 | float odds = (float)this.age / this.lifetime;
|
| 47 | if (this.random.nextFloat() > odds) {
|
| 48 | this.level.addParticle(ParticleTypes.SMOKE, this.x, this.y, this.z, this.xd, this.yd, this.zd);
|
| 49 | }
|
| 50 | }
|
| 51 | }
|
| 52 |
|
| 53 | @Environment(EnvType.CLIENT)
|
| 54 | public static class Provider implements ParticleProvider<SimpleParticleType> {
|
| 55 | private final SpriteSet sprite;
|
| 56 |
|
| 57 | public Provider(final SpriteSet sprite) {
|
| 58 | this.sprite = sprite;
|
| 59 | }
|
| 60 |
|
| 61 | public Particle createParticle(
|
| 62 | final SimpleParticleType options,
|
| 63 | final ClientLevel level,
|
| 64 | final double x,
|
| 65 | final double y,
|
| 66 | final double z,
|
| 67 | final double xAux,
|
| 68 | final double yAux,
|
| 69 | final double zAux,
|
| 70 | final RandomSource random
|
| 71 | ) {
|
| 72 | return new LavaParticle(level, x, y, z, this.sprite.get(random));
|
| 73 | }
|
| 74 | }
|
| 75 | }
|
| 76 |
|