2020-09-22 15:11:20 +02:00
|
|
|
package com.minelittlepony.unicopia.particle;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-04-15 18:12:00 +02:00
|
|
|
import com.minelittlepony.unicopia.util.shape.Shape;
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.util.shape.Sphere;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.particle.ParticleEffect;
|
|
|
|
|
|
|
|
/**
|
2020-04-15 14:22:03 +02:00
|
|
|
* Utility for spawning particles.
|
2020-01-16 12:35:46 +01:00
|
|
|
*/
|
|
|
|
public final class ParticleUtils {
|
|
|
|
|
|
|
|
public static void spawnParticles(ParticleEffect particleId, Entity entity, int count) {
|
2020-05-07 13:14:46 +02:00
|
|
|
double halfDist = Math.abs(entity.getStandingEyeHeight() / 1.5);
|
2020-06-26 11:44:47 +02:00
|
|
|
double middle = entity.getBoundingBox().minY + halfDist;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-05-07 13:14:46 +02:00
|
|
|
Shape shape = new Sphere(false, Math.abs((float)halfDist + entity.getWidth()));
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
shape.randomPoints(count, entity.world.random).forEach(point -> {
|
|
|
|
entity.world.addParticle(particleId,
|
2020-04-22 16:28:20 +02:00
|
|
|
entity.getX() + point.x,
|
2020-01-16 12:35:46 +01:00
|
|
|
middle + point.y,
|
2020-04-22 16:28:20 +02:00
|
|
|
entity.getZ() + point.z,
|
2020-01-16 12:35:46 +01:00
|
|
|
0, 0, 0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|