| 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.core.particles.DustColorTransitionOptions;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 | import org.joml.Vector3f;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public class DustColorTransitionParticle extends DustParticleBase<DustColorTransitionOptions> {
|
| 14 | private final Vector3f fromColor;
|
| 15 | private final Vector3f toColor;
|
| 16 |
|
| 17 | protected DustColorTransitionParticle(
|
| 18 | final ClientLevel level,
|
| 19 | final double x,
|
| 20 | final double y,
|
| 21 | final double z,
|
| 22 | final double xAux,
|
| 23 | final double yAux,
|
| 24 | final double zAux,
|
| 25 | final DustColorTransitionOptions options,
|
| 26 | final SpriteSet sprites
|
| 27 | ) {
|
| 28 | super(level, x, y, z, xAux, yAux, zAux, options, sprites);
|
| 29 | float baseFactor = this.random.nextFloat() * 0.4F + 0.6F;
|
| 30 | this.fromColor = this.randomizeColor(options.getFromColor(), baseFactor);
|
| 31 | this.toColor = this.randomizeColor(options.getToColor(), baseFactor);
|
| 32 | }
|
| 33 |
|
| 34 | private Vector3f randomizeColor(final Vector3f color, final float baseFactor) {
|
| 35 | return new Vector3f(this.randomizeColor(color.x(), baseFactor), this.randomizeColor(color.y(), baseFactor), this.randomizeColor(color.z(), baseFactor));
|
| 36 | }
|
| 37 |
|
| 38 | private void lerpColors(final float partialTickTime) {
|
| 39 | float a = (this.age + partialTickTime) / (this.lifetime + 1.0F);
|
| 40 | Vector3f lerpedColor = new Vector3f(this.fromColor).lerp(this.toColor, a);
|
| 41 | this.rCol = lerpedColor.x();
|
| 42 | this.gCol = lerpedColor.y();
|
| 43 | this.bCol = lerpedColor.z();
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | public void extract(final QuadParticleRenderState particleTypeRenderState, final Camera camera, final float partialTickTime) {
|
| 48 | this.lerpColors(partialTickTime);
|
| 49 | super.extract(particleTypeRenderState, camera, partialTickTime);
|
| 50 | }
|
| 51 |
|
| 52 | @Environment(EnvType.CLIENT)
|
| 53 | public static class Provider implements ParticleProvider<DustColorTransitionOptions> {
|
| 54 | private final SpriteSet sprites;
|
| 55 |
|
| 56 | public Provider(final SpriteSet sprites) {
|
| 57 | this.sprites = sprites;
|
| 58 | }
|
| 59 |
|
| 60 | public Particle createParticle(
|
| 61 | final DustColorTransitionOptions options,
|
| 62 | final ClientLevel level,
|
| 63 | final double x,
|
| 64 | final double y,
|
| 65 | final double z,
|
| 66 | final double xAux,
|
| 67 | final double yAux,
|
| 68 | final double zAux,
|
| 69 | final RandomSource random
|
| 70 | ) {
|
| 71 | return new DustColorTransitionParticle(level, x, y, z, xAux, yAux, zAux, options, this.sprites);
|
| 72 | }
|
| 73 | }
|
| 74 | }
|
| 75 |
|