| 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.BlockPos;
|
| 8 | import net.minecraft.core.particles.SimpleParticleType;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 | import net.minecraft.world.level.material.Fluids;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public class SulfurBubbleParticle extends SingleQuadParticle {
|
| 14 | private static final float SIZE_START = 0.02F;
|
| 15 | private static final float SIZE_END = 0.15F;
|
| 16 | private static final float UPWARDS_SPEED = 0.04F;
|
| 17 | private static final float HORIZONTAL_WIGGLING = 0.003F;
|
| 18 | private final double yStart;
|
| 19 | private final double yEnd;
|
| 20 | private final float sizeStart;
|
| 21 | private double yPrev;
|
| 22 |
|
| 23 | private SulfurBubbleParticle(
|
| 24 | final ClientLevel level, final double x, final double y, final double z, final double xa, final double za, final TextureAtlasSprite sprite
|
| 25 | ) {
|
| 26 | super(level, x, y, z, sprite);
|
| 27 | this.gravity = -0.04F;
|
| 28 | this.friction = 0.85F;
|
| 29 | this.setSize(0.02F, 0.02F);
|
| 30 | this.xd = xa * 0.2F + (this.random.nextFloat() * 2.0F - 1.0F) * 0.02F;
|
| 31 | this.zd = za * 0.2F + (this.random.nextFloat() * 2.0F - 1.0F) * 0.02F;
|
| 32 | this.sizeStart = 0.02F + 0.02F * this.random.nextFloat();
|
| 33 | this.quadSize = this.sizeStart;
|
| 34 | this.lifetime = Integer.MAX_VALUE;
|
| 35 | this.yStart = this.yo;
|
| 36 | this.yEnd = this.yo + 4.0 - 1.0;
|
| 37 | this.yPrev = y;
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | public void tick() {
|
| 42 | super.tick();
|
| 43 | if (!this.removed && !this.level.getFluidState(BlockPos.containing(this.x, this.y, this.z)).isSourceOfType(Fluids.WATER)) {
|
| 44 | this.remove();
|
| 45 | }
|
| 46 |
|
| 47 | if (!this.removed && this.y >= this.yEnd) {
|
| 48 | this.remove();
|
| 49 | }
|
| 50 |
|
| 51 | if (!this.removed && this.y <= this.yPrev) {
|
| 52 | this.remove();
|
| 53 | }
|
| 54 |
|
| 55 | this.xd = this.xd + this.randomHorizontalWiggling();
|
| 56 | this.zd = this.zd + this.randomHorizontalWiggling();
|
| 57 | this.move(this.xd, 0.0, this.zd);
|
| 58 | float travelProgress = (float)((this.y - this.yStart) / (this.yEnd - this.yStart));
|
| 59 | this.quadSize = this.sizeStart + travelProgress * (0.15F - this.sizeStart);
|
| 60 | this.yPrev = this.y;
|
| 61 | }
|
| 62 |
|
| 63 | private double randomHorizontalWiggling() {
|
| 64 | return this.random.nextFloat() * 0.003F * (this.random.nextBoolean() ? 1 : -1) * 0.5;
|
| 65 | }
|
| 66 |
|
| 67 | @Override
|
| 68 | public SingleQuadParticle.Layer getLayer() {
|
| 69 | return SingleQuadParticle.Layer.OPAQUE;
|
| 70 | }
|
| 71 |
|
| 72 | @Environment(EnvType.CLIENT)
|
| 73 | public static class Provider implements ParticleProvider<SimpleParticleType> {
|
| 74 | private final SpriteSet sprite;
|
| 75 |
|
| 76 | public Provider(final SpriteSet sprite) {
|
| 77 | this.sprite = sprite;
|
| 78 | }
|
| 79 |
|
| 80 | public Particle createParticle(
|
| 81 | final SimpleParticleType options,
|
| 82 | final ClientLevel level,
|
| 83 | final double x,
|
| 84 | final double y,
|
| 85 | final double z,
|
| 86 | final double xAux,
|
| 87 | final double yAux,
|
| 88 | final double zAux,
|
| 89 | final RandomSource random
|
| 90 | ) {
|
| 91 | return new SulfurBubbleParticle(level, x, y, z, xAux, yAux, this.sprite.get(random));
|
| 92 | }
|
| 93 | }
|
| 94 | }
|
| 95 |
|