FireflyParticle.java

net.minecraft.client.particle.FireflyParticle

信息

  • 全限定名:net.minecraft.client.particle.FireflyParticle
  • 类型:public class
  • 包:net.minecraft.client.particle
  • 源码路径:src/main/java/net/minecraft/client/particle/FireflyParticle.java
  • 起始行号:L13
  • 继承:SingleQuadParticle
  • 职责:

    TODO

字段/常量

  • PARTICLE_FADE_OUT_LIGHT_TIME

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L14
    • 说明:

      TODO

  • PARTICLE_FADE_IN_LIGHT_TIME

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L15
    • 说明:

      TODO

  • PARTICLE_FADE_OUT_ALPHA_TIME

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L16
    • 说明:

      TODO

  • PARTICLE_FADE_IN_ALPHA_TIME

    • 类型: float
    • 修饰符: private static final
    • 源码定位: L17
    • 说明:

      TODO

  • PARTICLE_MIN_LIFETIME

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L18
    • 说明:

      TODO

  • PARTICLE_MAX_LIFETIME

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L19
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.particle.FireflyParticle.FireflyProvider
    • 类型: class
    • 修饰符: public static
    • 源码定位: L67
    • 说明:

      TODO

构造器

private FireflyParticle(ClientLevel level, double x, double y, double z, double xa, double ya, double za, TextureAtlasSprite sprite) @ L21

  • 构造器名:FireflyParticle
  • 源码定位:L21
  • 修饰符:private

参数:

  • level: ClientLevel
  • x: double
  • y: double
  • z: double
  • xa: double
  • ya: double
  • za: double
  • sprite: TextureAtlasSprite

说明:

TODO

方法

下面的方法块按源码顺序生成。

public SingleQuadParticle.Layer getLayer() @ L31

  • 方法名:getLayer
  • 源码定位:L31
  • 返回类型:SingleQuadParticle.Layer
  • 修饰符:public

参数:

说明:

TODO

public int getLightCoords(float a) @ L36

  • 方法名:getLightCoords
  • 源码定位:L36
  • 返回类型:int
  • 修饰符:public

参数:

  • a: float

说明:

TODO

public void tick() @ L41

  • 方法名:tick
  • 源码定位:L41
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

private float getLifetimeProgress(float currentAge) @ L54

  • 方法名:getLifetimeProgress
  • 源码定位:L54
  • 返回类型:float
  • 修饰符:private

参数:

  • currentAge: float

说明:

TODO

private static float getFadeAmount(float lifetimeProgress, float fadeInTime, float fadeOutTime) @ L58

  • 方法名:getFadeAmount
  • 源码定位:L58
  • 返回类型:float
  • 修饰符:private static

参数:

  • lifetimeProgress: float
  • fadeInTime: float
  • fadeOutTime: float

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class FireflyParticle extends SingleQuadParticle {
    private static final float PARTICLE_FADE_OUT_LIGHT_TIME = 0.3F;
    private static final float PARTICLE_FADE_IN_LIGHT_TIME = 0.1F;
    private static final float PARTICLE_FADE_OUT_ALPHA_TIME = 0.5F;
    private static final float PARTICLE_FADE_IN_ALPHA_TIME = 0.3F;
    private static final int PARTICLE_MIN_LIFETIME = 200;
    private static final int PARTICLE_MAX_LIFETIME = 300;
 
    private FireflyParticle(ClientLevel level, double x, double y, double z, double xa, double ya, double za, TextureAtlasSprite sprite) {
        super(level, x, y, z, xa, ya, za, sprite);
        this.speedUpWhenYMotionIsBlocked = true;
        this.friction = 0.96F;
        this.quadSize *= 0.75F;
        this.yd *= 0.8F;
        this.xd *= 0.8F;
        this.zd *= 0.8F;
    }
 
    @Override
    public SingleQuadParticle.Layer getLayer() {
        return SingleQuadParticle.Layer.TRANSLUCENT;
    }
 
    @Override
    public int getLightCoords(float a) {
        return (int)(255.0F * getFadeAmount(this.getLifetimeProgress(this.age + a), 0.1F, 0.3F));
    }
 
    @Override
    public void tick() {
        super.tick();
        if (!this.level.getBlockState(BlockPos.containing(this.x, this.y, this.z)).isAir()) {
            this.remove();
        } else {
            this.setAlpha(getFadeAmount(this.getLifetimeProgress(this.age), 0.3F, 0.5F));
            if (this.random.nextFloat() > 0.95F || this.age == 1) {
                this.setParticleSpeed(-0.05F + 0.1F * this.random.nextFloat(), -0.05F + 0.1F * this.random.nextFloat(), -0.05F + 0.1F * this.random.nextFloat());
            }
        }
    }
 
    private float getLifetimeProgress(float currentAge) {
        return Mth.clamp(currentAge / this.lifetime, 0.0F, 1.0F);
    }
 
    private static float getFadeAmount(float lifetimeProgress, float fadeInTime, float fadeOutTime) {
        if (lifetimeProgress >= 1.0F - fadeInTime) {
            return (1.0F - lifetimeProgress) / fadeInTime;
        } else {
            return lifetimeProgress <= fadeOutTime ? lifetimeProgress / fadeOutTime : 1.0F;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class FireflyProvider implements ParticleProvider<SimpleParticleType> {
        private final SpriteSet sprite;
 
        public FireflyProvider(SpriteSet sprite) {
            this.sprite = sprite;
        }
 
        public Particle createParticle(
            SimpleParticleType options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random
        ) {
            FireflyParticle particle = new FireflyParticle(
                level, x, y, z, 0.5 - random.nextDouble(), random.nextBoolean() ? yAux : -yAux, 0.5 - random.nextDouble(), this.sprite.get(random)
            );
            particle.setLifetime(random.nextIntBetweenInclusive(200, 300));
            particle.scale(1.5F);
            particle.setAlpha(0.0F);
            return particle;
        }
    }
}

引用的其他类