ParticleUtils.java

net.minecraft.util.ParticleUtils

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

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

public static void spawnParticlesOnBlockFaces(Level level, BlockPos pos, ParticleOptions particle, IntProvider particlesPerFaceRange) @ L17

  • 方法名:spawnParticlesOnBlockFaces
  • 源码定位:L17
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: Level
  • pos: BlockPos
  • particle: ParticleOptions
  • particlesPerFaceRange: IntProvider

说明:

TODO

public static void spawnParticlesOnBlockFace(Level level, BlockPos pos, ParticleOptions particle, IntProvider particlesPerFaceRange, Direction face, Supplier<Vec3> speedSupplier, double stepFactor) @ L25

  • 方法名:spawnParticlesOnBlockFace
  • 源码定位:L25
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: Level
  • pos: BlockPos
  • particle: ParticleOptions
  • particlesPerFaceRange: IntProvider
  • face: Direction
  • speedSupplier: Supplier
  • stepFactor: double

说明:

TODO

private static Vec3 getRandomSpeedRanges(RandomSource random) @ L35

  • 方法名:getRandomSpeedRanges
  • 源码定位:L35
  • 返回类型:Vec3
  • 修饰符:private static

参数:

  • random: RandomSource

说明:

TODO

public static void spawnParticlesAlongAxis(Direction.Axis attachedAxis, Level level, BlockPos pos, double radius, ParticleOptions particle, UniformInt sparkCount) @ L39

  • 方法名:spawnParticlesAlongAxis
  • 源码定位:L39
  • 返回类型:void
  • 修饰符:public static

参数:

  • attachedAxis: Direction.Axis
  • level: Level
  • pos: BlockPos
  • radius: double
  • particle: ParticleOptions
  • sparkCount: UniformInt

说明:

TODO

public static void spawnParticleOnFace(Level level, BlockPos pos, Direction face, ParticleOptions particle, Vec3 speed, double stepFactor) @ L60

  • 方法名:spawnParticleOnFace
  • 源码定位:L60
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: Level
  • pos: BlockPos
  • face: Direction
  • particle: ParticleOptions
  • speed: Vec3
  • stepFactor: double

说明:

TODO

public static void spawnParticleBelow(Level level, BlockPos pos, RandomSource random, ParticleOptions particle) @ L75

  • 方法名:spawnParticleBelow
  • 源码定位:L75
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: Level
  • pos: BlockPos
  • random: RandomSource
  • particle: ParticleOptions

说明:

TODO

public static void spawnParticleInBlock(LevelAccessor level, BlockPos pos, int count, ParticleOptions particle) @ L82

  • 方法名:spawnParticleInBlock
  • 源码定位:L82
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: LevelAccessor
  • pos: BlockPos
  • count: int
  • particle: ParticleOptions

说明:

TODO

public static void spawnParticles(LevelAccessor level, BlockPos pos, int count, double spreadWidth, double spreadHeight, boolean allowFloatingParticles, ParticleOptions particle) @ L89

  • 方法名:spawnParticles
  • 源码定位:L89
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: LevelAccessor
  • pos: BlockPos
  • count: int
  • spreadWidth: double
  • spreadHeight: double
  • allowFloatingParticles: boolean
  • particle: ParticleOptions

说明:

TODO

public static void spawnSmashAttackParticles(LevelAccessor level, BlockPos pos, int count) @ L108

  • 方法名:spawnSmashAttackParticles
  • 源码定位:L108
  • 返回类型:void
  • 修饰符:public static

参数:

  • level: LevelAccessor
  • pos: BlockPos
  • count: int

说明:

TODO

代码

public class ParticleUtils {
    public static void spawnParticlesOnBlockFaces(Level level, BlockPos pos, ParticleOptions particle, IntProvider particlesPerFaceRange) {
        RandomSource random = level.getRandom();
 
        for (Direction direction : Direction.values()) {
            spawnParticlesOnBlockFace(level, pos, particle, particlesPerFaceRange, direction, () -> getRandomSpeedRanges(random), 0.55);
        }
    }
 
    public static void spawnParticlesOnBlockFace(
        Level level, BlockPos pos, ParticleOptions particle, IntProvider particlesPerFaceRange, Direction face, Supplier<Vec3> speedSupplier, double stepFactor
    ) {
        int particleCount = particlesPerFaceRange.sample(level.getRandom());
 
        for (int i = 0; i < particleCount; i++) {
            spawnParticleOnFace(level, pos, face, particle, speedSupplier.get(), stepFactor);
        }
    }
 
    private static Vec3 getRandomSpeedRanges(RandomSource random) {
        return new Vec3(Mth.nextDouble(random, -0.5, 0.5), Mth.nextDouble(random, -0.5, 0.5), Mth.nextDouble(random, -0.5, 0.5));
    }
 
    public static void spawnParticlesAlongAxis(
        Direction.Axis attachedAxis, Level level, BlockPos pos, double radius, ParticleOptions particle, UniformInt sparkCount
    ) {
        Vec3 centerOfBlock = Vec3.atCenterOf(pos);
        boolean stepX = attachedAxis == Direction.Axis.X;
        boolean stepY = attachedAxis == Direction.Axis.Y;
        boolean stepZ = attachedAxis == Direction.Axis.Z;
        RandomSource random = level.getRandom();
        int particleCount = sparkCount.sample(random);
 
        for (int i = 0; i < particleCount; i++) {
            double x = centerOfBlock.x + Mth.nextDouble(random, -1.0, 1.0) * (stepX ? 0.5 : radius);
            double y = centerOfBlock.y + Mth.nextDouble(random, -1.0, 1.0) * (stepY ? 0.5 : radius);
            double z = centerOfBlock.z + Mth.nextDouble(random, -1.0, 1.0) * (stepZ ? 0.5 : radius);
            double xBaseSpeed = stepX ? Mth.nextDouble(random, -1.0, 1.0) : 0.0;
            double yBaseSpeed = stepY ? Mth.nextDouble(random, -1.0, 1.0) : 0.0;
            double zBaseSpeed = stepZ ? Mth.nextDouble(random, -1.0, 1.0) : 0.0;
            level.addParticle(particle, x, y, z, xBaseSpeed, yBaseSpeed, zBaseSpeed);
        }
    }
 
    public static void spawnParticleOnFace(Level level, BlockPos pos, Direction face, ParticleOptions particle, Vec3 speed, double stepFactor) {
        Vec3 centerOfBlock = Vec3.atCenterOf(pos);
        int stepX = face.getStepX();
        int stepY = face.getStepY();
        int stepZ = face.getStepZ();
        RandomSource random = level.getRandom();
        double x = centerOfBlock.x + (stepX == 0 ? Mth.nextDouble(random, -0.5, 0.5) : stepX * stepFactor);
        double y = centerOfBlock.y + (stepY == 0 ? Mth.nextDouble(random, -0.5, 0.5) : stepY * stepFactor);
        double z = centerOfBlock.z + (stepZ == 0 ? Mth.nextDouble(random, -0.5, 0.5) : stepZ * stepFactor);
        double xBaseSpeed = stepX == 0 ? speed.x() : 0.0;
        double yBaseSpeed = stepY == 0 ? speed.y() : 0.0;
        double zBaseSpeed = stepZ == 0 ? speed.z() : 0.0;
        level.addParticle(particle, x, y, z, xBaseSpeed, yBaseSpeed, zBaseSpeed);
    }
 
    public static void spawnParticleBelow(Level level, BlockPos pos, RandomSource random, ParticleOptions particle) {
        double x = pos.getX() + random.nextDouble();
        double y = pos.getY() - 0.05;
        double z = pos.getZ() + random.nextDouble();
        level.addParticle(particle, x, y, z, 0.0, 0.0, 0.0);
    }
 
    public static void spawnParticleInBlock(LevelAccessor level, BlockPos pos, int count, ParticleOptions particle) {
        double spreadWidth = 0.5;
        BlockState blockState = level.getBlockState(pos);
        double spreadHeight = blockState.isAir() ? 1.0 : blockState.getShape(level, pos).max(Direction.Axis.Y);
        spawnParticles(level, pos, count, 0.5, spreadHeight, true, particle);
    }
 
    public static void spawnParticles(
        LevelAccessor level, BlockPos pos, int count, double spreadWidth, double spreadHeight, boolean allowFloatingParticles, ParticleOptions particle
    ) {
        RandomSource random = level.getRandom();
 
        for (int i = 0; i < count; i++) {
            double xVelocity = random.nextGaussian() * 0.02;
            double yVelocity = random.nextGaussian() * 0.02;
            double zVelocity = random.nextGaussian() * 0.02;
            double spreadStartOffset = 0.5 - spreadWidth;
            double x = pos.getX() + spreadStartOffset + random.nextDouble() * spreadWidth * 2.0;
            double y = pos.getY() + random.nextDouble() * spreadHeight;
            double z = pos.getZ() + spreadStartOffset + random.nextDouble() * spreadWidth * 2.0;
            if (allowFloatingParticles || !level.getBlockState(BlockPos.containing(x, y, z).below()).isAir()) {
                level.addParticle(particle, x, y, z, xVelocity, yVelocity, zVelocity);
            }
        }
    }
 
    public static void spawnSmashAttackParticles(LevelAccessor level, BlockPos pos, int count) {
        Vec3 center = pos.getCenter().add(0.0, 0.5, 0.0);
        BlockParticleOption particle = new BlockParticleOption(ParticleTypes.DUST_PILLAR, level.getBlockState(pos));
 
        for (int i = 0; i < count / 3.0F; i++) {
            double x = center.x + level.getRandom().nextGaussian() / 2.0;
            double y = center.y;
            double z = center.z + level.getRandom().nextGaussian() / 2.0;
            double xd = level.getRandom().nextGaussian() * 0.2F;
            double yd = level.getRandom().nextGaussian() * 0.2F;
            double zd = level.getRandom().nextGaussian() * 0.2F;
            level.addParticle(particle, x, y, z, xd, yd, zd);
        }
 
        for (int i = 0; i < count / 1.5F; i++) {
            double x = center.x + 3.5 * Math.cos(i) + level.getRandom().nextGaussian() / 2.0;
            double y = center.y;
            double z = center.z + 3.5 * Math.sin(i) + level.getRandom().nextGaussian() / 2.0;
            double xd = level.getRandom().nextGaussian() * 0.05F;
            double yd = level.getRandom().nextGaussian() * 0.05F;
            double zd = level.getRandom().nextGaussian() * 0.05F;
            level.addParticle(particle, x, y, z, xd, yd, zd);
        }
    }
}

引用的其他类

  • BlockPos

    • 引用位置: 参数/方法调用
    • 关联成员: BlockPos.containing()
  • Direction

    • 引用位置: 参数/方法调用
    • 关联成员: Direction.values()
  • BlockParticleOption

    • 引用位置: 构造调用
    • 关联成员: BlockParticleOption()
  • ParticleOptions

    • 引用位置: 参数
  • Mth

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

    • 引用位置: 参数
  • IntProvider

    • 引用位置: 参数
  • UniformInt

    • 引用位置: 参数
  • Level

    • 引用位置: 参数
  • LevelAccessor

    • 引用位置: 参数
  • Vec3

    • 引用位置: 参数/方法调用/构造调用/返回值
    • 关联成员: Vec3(), Vec3.atCenterOf()