EndFlashState.java

net.minecraft.client.renderer.EndFlashState

信息

  • 全限定名:net.minecraft.client.renderer.EndFlashState
  • 类型:public class
  • 包:net.minecraft.client.renderer
  • 源码路径:src/main/java/net/minecraft/client/renderer/EndFlashState.java
  • 起始行号:L9
  • 职责:

    TODO

字段/常量

  • SOUND_DELAY_IN_TICKS

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

      TODO

  • FLASH_INTERVAL_IN_TICKS

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

      TODO

  • MAX_FLASH_OFFSET_IN_TICKS

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

      TODO

  • MIN_FLASH_DURATION_IN_TICKS

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

      TODO

  • MAX_FLASH_DURATION_IN_TICKS

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

      TODO

  • flashSeed

    • 类型: long
    • 修饰符: private
    • 源码定位: L15
    • 说明:

      TODO

  • offset

    • 类型: int
    • 修饰符: private
    • 源码定位: L16
    • 说明:

      TODO

  • duration

    • 类型: int
    • 修饰符: private
    • 源码定位: L17
    • 说明:

      TODO

  • intensity

    • 类型: float
    • 修饰符: private
    • 源码定位: L18
    • 说明:

      TODO

  • oldIntensity

    • 类型: float
    • 修饰符: private
    • 源码定位: L19
    • 说明:

      TODO

  • xAngle

    • 类型: float
    • 修饰符: private
    • 源码定位: L20
    • 说明:

      TODO

  • yAngle

    • 类型: float
    • 修饰符: private
    • 源码定位: L21
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public void tick(long clockTime) @ L23

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

参数:

  • clockTime: long

说明:

TODO

private void calculateFlashParameters(long clockTime) @ L29

  • 方法名:calculateFlashParameters
  • 源码定位:L29
  • 返回类型:void
  • 修饰符:private

参数:

  • clockTime: long

说明:

TODO

private float calculateIntensity(long clockTime) @ L42

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

参数:

  • clockTime: long

说明:

TODO

public float getXAngle() @ L49

  • 方法名:getXAngle
  • 源码定位:L49
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public float getYAngle() @ L53

  • 方法名:getYAngle
  • 源码定位:L53
  • 返回类型:float
  • 修饰符:public

参数:

说明:

TODO

public float getIntensity(float partialTicks) @ L57

  • 方法名:getIntensity
  • 源码定位:L57
  • 返回类型:float
  • 修饰符:public

参数:

  • partialTicks: float

说明:

TODO

public boolean flashStartedThisTick() @ L61

  • 方法名:flashStartedThisTick
  • 源码定位:L61
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class EndFlashState {
    public static final int SOUND_DELAY_IN_TICKS = 30;
    private static final int FLASH_INTERVAL_IN_TICKS = 600;
    private static final int MAX_FLASH_OFFSET_IN_TICKS = 200;
    private static final int MIN_FLASH_DURATION_IN_TICKS = 100;
    private static final int MAX_FLASH_DURATION_IN_TICKS = 380;
    private long flashSeed;
    private int offset;
    private int duration;
    private float intensity;
    private float oldIntensity;
    private float xAngle;
    private float yAngle;
 
    public void tick(long clockTime) {
        this.calculateFlashParameters(clockTime);
        this.oldIntensity = this.intensity;
        this.intensity = this.calculateIntensity(clockTime);
    }
 
    private void calculateFlashParameters(long clockTime) {
        long newSeed = clockTime / 600L;
        if (newSeed != this.flashSeed) {
            RandomSource randomSource = RandomSource.createThreadLocalInstance(newSeed);
            randomSource.nextFloat();
            this.offset = Mth.randomBetweenInclusive(randomSource, 0, 200);
            this.duration = Mth.randomBetweenInclusive(randomSource, 100, Math.min(380, 600 - this.offset));
            this.xAngle = Mth.randomBetween(randomSource, -60.0F, 10.0F);
            this.yAngle = Mth.randomBetween(randomSource, -180.0F, 180.0F);
            this.flashSeed = newSeed;
        }
    }
 
    private float calculateIntensity(long clockTime) {
        long clockTimeWithinInterval = clockTime % 600L;
        return clockTimeWithinInterval >= this.offset && clockTimeWithinInterval <= this.offset + this.duration
            ? Mth.sin((float)(clockTimeWithinInterval - this.offset) * (float) Math.PI / this.duration)
            : 0.0F;
    }
 
    public float getXAngle() {
        return this.xAngle;
    }
 
    public float getYAngle() {
        return this.yAngle;
    }
 
    public float getIntensity(float partialTicks) {
        return Mth.lerp(partialTicks, this.oldIntensity, this.intensity);
    }
 
    public boolean flashStartedThisTick() {
        return this.intensity > 0.0F && this.oldIntensity <= 0.0F;
    }
}

引用的其他类

  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.lerp(), Mth.randomBetween(), Mth.randomBetweenInclusive(), Mth.sin()
  • RandomSource

    • 引用位置: 方法调用
    • 关联成员: RandomSource.createThreadLocalInstance()