| 1 | package net.minecraft.client.particle;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.Camera;
|
| 6 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 7 | import net.minecraft.client.renderer.state.level.QuadParticleRenderState;
|
| 8 | import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
| 9 | import net.minecraft.core.particles.SimpleParticleType;
|
| 10 | import net.minecraft.util.LightCoordsUtil;
|
| 11 | import net.minecraft.util.RandomSource;
|
| 12 |
|
| 13 | @Environment(EnvType.CLIENT)
|
| 14 | public class FlyTowardsPositionParticle extends SingleQuadParticle {
|
| 15 | private final double xStart;
|
| 16 | private final double yStart;
|
| 17 | private final double zStart;
|
| 18 | private final boolean isGlowing;
|
| 19 | private final Particle.LifetimeAlpha lifetimeAlpha;
|
| 20 |
|
| 21 | private FlyTowardsPositionParticle(
|
| 22 | final ClientLevel level, final double x, final double y, final double z, final double xd, final double yd, final double zd, final TextureAtlasSprite sprite
|
| 23 | ) {
|
| 24 | this(level, x, y, z, xd, yd, zd, false, Particle.LifetimeAlpha.ALWAYS_OPAQUE, sprite);
|
| 25 | }
|
| 26 |
|
| 27 | private FlyTowardsPositionParticle(
|
| 28 | final ClientLevel level,
|
| 29 | final double x,
|
| 30 | final double y,
|
| 31 | final double z,
|
| 32 | final double xd,
|
| 33 | final double yd,
|
| 34 | final double zd,
|
| 35 | final boolean isGlowing,
|
| 36 | final Particle.LifetimeAlpha lifetimeAlpha,
|
| 37 | final TextureAtlasSprite sprite
|
| 38 | ) {
|
| 39 | super(level, x, y, z, sprite);
|
| 40 | this.isGlowing = isGlowing;
|
| 41 | this.lifetimeAlpha = lifetimeAlpha;
|
| 42 | this.setAlpha(lifetimeAlpha.startAlpha());
|
| 43 | this.xd = xd;
|
| 44 | this.yd = yd;
|
| 45 | this.zd = zd;
|
| 46 | this.xStart = x;
|
| 47 | this.yStart = y;
|
| 48 | this.zStart = z;
|
| 49 | this.xo = x + xd;
|
| 50 | this.yo = y + yd;
|
| 51 | this.zo = z + zd;
|
| 52 | this.x = this.xo;
|
| 53 | this.y = this.yo;
|
| 54 | this.z = this.zo;
|
| 55 | this.quadSize = 0.1F * (this.random.nextFloat() * 0.5F + 0.2F);
|
| 56 | float br = this.random.nextFloat() * 0.6F + 0.4F;
|
| 57 | this.rCol = 0.9F * br;
|
| 58 | this.gCol = 0.9F * br;
|
| 59 | this.bCol = br;
|
| 60 | this.hasPhysics = false;
|
| 61 | this.lifetime = (int)(this.random.nextFloat() * 10.0F) + 30;
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | public SingleQuadParticle.Layer getLayer() {
|
| 66 | return this.lifetimeAlpha.isOpaque() ? SingleQuadParticle.Layer.OPAQUE : SingleQuadParticle.Layer.TRANSLUCENT;
|
| 67 | }
|
| 68 |
|
| 69 | @Override
|
| 70 | public void move(final double xa, final double ya, final double za) {
|
| 71 | this.setBoundingBox(this.getBoundingBox().move(xa, ya, za));
|
| 72 | this.setLocationFromBoundingbox();
|
| 73 | }
|
| 74 |
|
| 75 | @Override
|
| 76 | public int getLightCoords(final float a) {
|
| 77 | if (this.isGlowing) {
|
| 78 | return LightCoordsUtil.withBlock(super.getLightCoords(a), 15);
|
| 79 | }
|
| 80 |
|
| 81 | float brightness = (float)this.age / this.lifetime;
|
| 82 | brightness *= brightness;
|
| 83 | brightness *= brightness;
|
| 84 | return LightCoordsUtil.addSmoothBlockEmission(super.getLightCoords(a), brightness);
|
| 85 | }
|
| 86 |
|
| 87 | @Override
|
| 88 | public void tick() {
|
| 89 | this.xo = this.x;
|
| 90 | this.yo = this.y;
|
| 91 | this.zo = this.z;
|
| 92 | if (this.age++ >= this.lifetime) {
|
| 93 | this.remove();
|
| 94 | } else {
|
| 95 | float pos = (float)this.age / this.lifetime;
|
| 96 | pos = 1.0F - pos;
|
| 97 | float pp = 1.0F - pos;
|
| 98 | pp *= pp;
|
| 99 | pp *= pp;
|
| 100 | this.x = this.xStart + this.xd * pos;
|
| 101 | this.y = this.yStart + this.yd * pos - pp * 1.2F;
|
| 102 | this.z = this.zStart + this.zd * pos;
|
| 103 | }
|
| 104 | }
|
| 105 |
|
| 106 | @Override
|
| 107 | public void extract(final QuadParticleRenderState particleTypeRenderState, final Camera camera, final float partialTickTime) {
|
| 108 | this.setAlpha(this.lifetimeAlpha.currentAlphaForAge(this.age, this.lifetime, partialTickTime));
|
| 109 | super.extract(particleTypeRenderState, camera, partialTickTime);
|
| 110 | }
|
| 111 |
|
| 112 | @Environment(EnvType.CLIENT)
|
| 113 | public static class EnchantProvider implements ParticleProvider<SimpleParticleType> {
|
| 114 | private final SpriteSet sprite;
|
| 115 |
|
| 116 | public EnchantProvider(final SpriteSet sprite) {
|
| 117 | this.sprite = sprite;
|
| 118 | }
|
| 119 |
|
| 120 | public Particle createParticle(
|
| 121 | final SimpleParticleType options,
|
| 122 | final ClientLevel level,
|
| 123 | final double x,
|
| 124 | final double y,
|
| 125 | final double z,
|
| 126 | final double xAux,
|
| 127 | final double yAux,
|
| 128 | final double zAux,
|
| 129 | final RandomSource random
|
| 130 | ) {
|
| 131 | return new FlyTowardsPositionParticle(level, x, y, z, xAux, yAux, zAux, this.sprite.get(random));
|
| 132 | }
|
| 133 | }
|
| 134 |
|
| 135 | @Environment(EnvType.CLIENT)
|
| 136 | public static class NautilusProvider implements ParticleProvider<SimpleParticleType> {
|
| 137 | private final SpriteSet sprite;
|
| 138 |
|
| 139 | public NautilusProvider(final SpriteSet sprite) {
|
| 140 | this.sprite = sprite;
|
| 141 | }
|
| 142 |
|
| 143 | public Particle createParticle(
|
| 144 | final SimpleParticleType options,
|
| 145 | final ClientLevel level,
|
| 146 | final double x,
|
| 147 | final double y,
|
| 148 | final double z,
|
| 149 | final double xAux,
|
| 150 | final double yAux,
|
| 151 | final double zAux,
|
| 152 | final RandomSource random
|
| 153 | ) {
|
| 154 | return new FlyTowardsPositionParticle(level, x, y, z, xAux, yAux, zAux, this.sprite.get(random));
|
| 155 | }
|
| 156 | }
|
| 157 |
|
| 158 | @Environment(EnvType.CLIENT)
|
| 159 | public static class VaultConnectionProvider implements ParticleProvider<SimpleParticleType> {
|
| 160 | private final SpriteSet sprite;
|
| 161 |
|
| 162 | public VaultConnectionProvider(final SpriteSet sprite) {
|
| 163 | this.sprite = sprite;
|
| 164 | }
|
| 165 |
|
| 166 | public Particle createParticle(
|
| 167 | final SimpleParticleType options,
|
| 168 | final ClientLevel level,
|
| 169 | final double x,
|
| 170 | final double y,
|
| 171 | final double z,
|
| 172 | final double xAux,
|
| 173 | final double yAux,
|
| 174 | final double zAux,
|
| 175 | final RandomSource random
|
| 176 | ) {
|
| 177 | FlyTowardsPositionParticle particle = new FlyTowardsPositionParticle(
|
| 178 | level, x, y, z, xAux, yAux, zAux, true, new Particle.LifetimeAlpha(0.0F, 0.6F, 0.25F, 1.0F), this.sprite.get(random)
|
| 179 | );
|
| 180 | particle.scale(1.5F);
|
| 181 | return particle;
|
| 182 | }
|
| 183 | }
|
| 184 | }
|
| 185 |
|