2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.particle;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-10-01 23:53:18 +02:00
|
|
|
import com.minelittlepony.unicopia.util.shape.*;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.particle.ParticleEffect;
|
2021-02-02 11:52:50 +01:00
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2021-02-19 15:56:01 +01:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2021-02-02 11:52:50 +01:00
|
|
|
import net.minecraft.world.World;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
/**
|
2020-04-15 14:22:03 +02:00
|
|
|
* Utility for spawning particles.
|
2020-01-16 12:35:46 +01:00
|
|
|
*/
|
2022-10-01 23:53:18 +02:00
|
|
|
public interface ParticleUtils {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-10-01 23:53:18 +02:00
|
|
|
static PointGenerator getShapeFor(Entity entity) {
|
|
|
|
final double halfDist = Math.abs(entity.getStandingEyeHeight() / 1.5);
|
|
|
|
final double middle = entity.getBoundingBox().minY + halfDist;
|
|
|
|
return new Sphere(false, Math.abs((float)halfDist + entity.getWidth())).offset(new Vec3d(entity.getX(), middle, entity.getZ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void spawnParticles(ParticleEffect effect, Entity entity, int count) {
|
|
|
|
spawnParticles(entity.world, getShapeFor(entity), effect, count);
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-10-01 23:53:18 +02:00
|
|
|
static void spawnParticles(ParticleEffect effect, World world, Vec3d origin, int count) {
|
|
|
|
spawnParticles(world, Sphere.UNIT_SPHERE.offset(origin), effect, count);
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-10-01 23:53:18 +02:00
|
|
|
static void spawnParticles(World world, PointGenerator points, ParticleEffect effect, int count) {
|
|
|
|
points.randomPoints(count, world.random).forEach(point -> spawnParticle(world, effect, point, Vec3d.ZERO));
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
2021-02-02 11:52:50 +01:00
|
|
|
|
2022-10-01 23:53:18 +02:00
|
|
|
static void spawnParticle(World world, ParticleEffect effect, Vec3d pos, Vec3d vel) {
|
2021-12-28 01:20:08 +01:00
|
|
|
spawnParticle(world, effect, pos.x, pos.y, pos.z, vel.x, vel.y, vel.z);
|
2021-02-19 15:56:01 +01:00
|
|
|
}
|
|
|
|
|
2022-10-01 23:53:18 +02:00
|
|
|
static void spawnParticle(World world, ParticleEffect effect, double x, double y, double z, double vX, double vY, double vZ) {
|
|
|
|
if (world instanceof ServerWorld sw) {
|
|
|
|
sw.spawnParticles(effect, x, y, z, 1, vX, vY, vZ, 0);
|
2021-02-02 11:52:50 +01:00
|
|
|
} else {
|
|
|
|
world.addParticle(effect, x, y, z, vX, vY, vZ);
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|