| 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.LightCoordsUtil;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 |
|
| 11 | @Environment(EnvType.CLIENT)
|
| 12 | public class PortalParticle extends SingleQuadParticle {
|
| 13 | private final double xStart;
|
| 14 | private final double yStart;
|
| 15 | private final double zStart;
|
| 16 |
|
| 17 | protected PortalParticle(
|
| 18 | final ClientLevel level, final double x, final double y, final double z, final double xd, final double yd, final double zd, final TextureAtlasSprite sprite
|
| 19 | ) {
|
| 20 | super(level, x, y, z, sprite);
|
| 21 | this.xd = xd;
|
| 22 | this.yd = yd;
|
| 23 | this.zd = zd;
|
| 24 | this.x = x;
|
| 25 | this.y = y;
|
| 26 | this.z = z;
|
| 27 | this.xStart = this.x;
|
| 28 | this.yStart = this.y;
|
| 29 | this.zStart = this.z;
|
| 30 | this.quadSize = 0.1F * (this.random.nextFloat() * 0.2F + 0.5F);
|
| 31 | float br = this.random.nextFloat() * 0.6F + 0.4F;
|
| 32 | this.rCol = br * 0.9F;
|
| 33 | this.gCol = br * 0.3F;
|
| 34 | this.bCol = br;
|
| 35 | this.lifetime = (int)(this.random.nextFloat() * 10.0F) + 40;
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public SingleQuadParticle.Layer getLayer() {
|
| 40 | return SingleQuadParticle.Layer.OPAQUE;
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public void move(final double xa, final double ya, final double za) {
|
| 45 | this.setBoundingBox(this.getBoundingBox().move(xa, ya, za));
|
| 46 | this.setLocationFromBoundingbox();
|
| 47 | }
|
| 48 |
|
| 49 | @Override
|
| 50 | public float getQuadSize(final float a) {
|
| 51 | float s = (this.age + a) / this.lifetime;
|
| 52 | s = 1.0F - s;
|
| 53 | s *= s;
|
| 54 | s = 1.0F - s;
|
| 55 | return this.quadSize * s;
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public int getLightCoords(final float a) {
|
| 60 | float brightness = (float)this.age / this.lifetime;
|
| 61 | brightness *= brightness;
|
| 62 | brightness *= brightness;
|
| 63 | return LightCoordsUtil.addSmoothBlockEmission(super.getLightCoords(a), brightness);
|
| 64 | }
|
| 65 |
|
| 66 | @Override
|
| 67 | public void tick() {
|
| 68 | this.xo = this.x;
|
| 69 | this.yo = this.y;
|
| 70 | this.zo = this.z;
|
| 71 | if (this.age++ >= this.lifetime) {
|
| 72 | this.remove();
|
| 73 | } else {
|
| 74 | float pos = (float)this.age / this.lifetime;
|
| 75 | float a = pos;
|
| 76 | pos = -pos + pos * pos * 2.0F;
|
| 77 | pos = 1.0F - pos;
|
| 78 | this.x = this.xStart + this.xd * pos;
|
| 79 | this.y = this.yStart + this.yd * pos + (1.0F - a);
|
| 80 | this.z = this.zStart + this.zd * pos;
|
| 81 | }
|
| 82 | }
|
| 83 |
|
| 84 | @Environment(EnvType.CLIENT)
|
| 85 | public static class Provider implements ParticleProvider<SimpleParticleType> {
|
| 86 | private final SpriteSet sprite;
|
| 87 |
|
| 88 | public Provider(final SpriteSet sprite) {
|
| 89 | this.sprite = sprite;
|
| 90 | }
|
| 91 |
|
| 92 | public Particle createParticle(
|
| 93 | final SimpleParticleType 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 | return new PortalParticle(level, x, y, z, xAux, yAux, zAux, this.sprite.get(random));
|
| 104 | }
|
| 105 | }
|
| 106 | }
|
| 107 |
|