SpellParticle.java

net.minecraft.client.particle.SpellParticle

信息

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

    TODO

字段/常量

  • RANDOM

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

      TODO

  • sprites

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

      TODO

  • originalAlpha

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

      TODO

内部类/嵌套类型

  • net.minecraft.client.particle.SpellParticle.InstantProvider

    • 类型: class
    • 修饰符: public static
    • 源码定位: L73
    • 说明:

      TODO

  • net.minecraft.client.particle.SpellParticle.MobEffectProvider

    • 类型: class
    • 修饰符: public static
    • 源码定位: L91
    • 说明:

      TODO

  • net.minecraft.client.particle.SpellParticle.Provider

    • 类型: class
    • 修饰符: public static
    • 源码定位: L109
    • 说明:

      TODO

  • net.minecraft.client.particle.SpellParticle.WitchProvider

    • 类型: class
    • 修饰符: public static
    • 源码定位: L124
    • 说明:

      TODO

构造器

private SpellParticle(ClientLevel level, double x, double y, double z, double xa, double ya, double za, SpriteSet sprites) @ L20

  • 构造器名:SpellParticle
  • 源码定位:L20
  • 修饰符:private

参数:

  • level: ClientLevel
  • x: double
  • y: double
  • z: double
  • xa: double
  • ya: double
  • za: double
  • sprites: SpriteSet

说明:

TODO

方法

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

public SingleQuadParticle.Layer getLayer() @ L41

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

参数:

说明:

TODO

public void tick() @ L46

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

参数:

说明:

TODO

protected void setAlpha(float alpha) @ L57

  • 方法名:setAlpha
  • 源码定位:L57
  • 返回类型:void
  • 修饰符:protected

参数:

  • alpha: float

说明:

TODO

private boolean isCloseToScopingPlayer() @ L63

  • 方法名:isCloseToScopingPlayer
  • 源码定位:L63
  • 返回类型:boolean
  • 修饰符:private

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class SpellParticle extends SingleQuadParticle {
    private static final RandomSource RANDOM = RandomSource.create();
    private final SpriteSet sprites;
    private float originalAlpha = 1.0F;
 
    private SpellParticle(ClientLevel level, double x, double y, double z, double xa, double ya, double za, SpriteSet sprites) {
        super(level, x, y, z, 0.5 - RANDOM.nextDouble(), ya, 0.5 - RANDOM.nextDouble(), sprites.first());
        this.friction = 0.96F;
        this.gravity = -0.1F;
        this.speedUpWhenYMotionIsBlocked = true;
        this.sprites = sprites;
        this.yd *= 0.2F;
        if (xa == 0.0 && za == 0.0) {
            this.xd *= 0.1F;
            this.zd *= 0.1F;
        }
 
        this.quadSize *= 0.75F;
        this.lifetime = (int)(8.0 / (this.random.nextFloat() * 0.8 + 0.2));
        this.hasPhysics = false;
        this.setSpriteFromAge(sprites);
        if (this.isCloseToScopingPlayer()) {
            this.setAlpha(0.0F);
        }
    }
 
    @Override
    public SingleQuadParticle.Layer getLayer() {
        return SingleQuadParticle.Layer.TRANSLUCENT;
    }
 
    @Override
    public void tick() {
        super.tick();
        this.setSpriteFromAge(this.sprites);
        if (this.isCloseToScopingPlayer()) {
            this.alpha = 0.0F;
        } else {
            this.alpha = Mth.lerp(0.05F, this.alpha, this.originalAlpha);
        }
    }
 
    @Override
    protected void setAlpha(float alpha) {
        super.setAlpha(alpha);
        this.originalAlpha = alpha;
    }
 
    private boolean isCloseToScopingPlayer() {
        Minecraft instance = Minecraft.getInstance();
        LocalPlayer player = instance.player;
        return player != null
            && player.getEyePosition().distanceToSqr(this.x, this.y, this.z) <= 9.0
            && instance.options.getCameraType().isFirstPerson()
            && player.isScoping();
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class InstantProvider implements ParticleProvider<SpellParticleOption> {
        private final SpriteSet sprite;
 
        public InstantProvider(SpriteSet sprite) {
            this.sprite = sprite;
        }
 
        public Particle createParticle(
            SpellParticleOption options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random
        ) {
            SpellParticle particle = new SpellParticle(level, x, y, z, xAux, yAux, zAux, this.sprite);
            particle.setColor(options.getRed(), options.getGreen(), options.getBlue());
            particle.setPower(options.getPower());
            return particle;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class MobEffectProvider implements ParticleProvider<ColorParticleOption> {
        private final SpriteSet sprite;
 
        public MobEffectProvider(SpriteSet sprite) {
            this.sprite = sprite;
        }
 
        public Particle createParticle(
            ColorParticleOption options, ClientLevel level, double x, double y, double z, double xAux, double yAux, double zAux, RandomSource random
        ) {
            SpellParticle particle = new SpellParticle(level, x, y, z, xAux, yAux, zAux, this.sprite);
            particle.setColor(options.getRed(), options.getGreen(), options.getBlue());
            particle.setAlpha(options.getAlpha());
            return particle;
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class Provider implements ParticleProvider<SimpleParticleType> {
        private final SpriteSet sprite;
 
        public Provider(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
        ) {
            return new SpellParticle(level, x, y, z, xAux, yAux, zAux, this.sprite);
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class WitchProvider implements ParticleProvider<SimpleParticleType> {
        private final SpriteSet sprite;
 
        public WitchProvider(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
        ) {
            SpellParticle particle = new SpellParticle(level, x, y, z, xAux, yAux, zAux, this.sprite);
            float randBrightness = random.nextFloat() * 0.5F + 0.35F;
            particle.setColor(1.0F * randBrightness, 0.0F * randBrightness, 1.0F * randBrightness);
            return particle;
        }
    }
}

引用的其他类

  • Minecraft

    • 引用位置: 方法调用
    • 关联成员: Minecraft.getInstance()
  • ClientLevel

    • 引用位置: 参数
  • SingleQuadParticle

    • 引用位置: 继承/返回值
  • SpriteSet

    • 引用位置: 参数/字段
  • Mth

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

    • 引用位置: 字段/方法调用
    • 关联成员: RandomSource.create()