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;
|
2021-02-02 11:52:50 +01:00
|
|
|
import net.minecraft.server.world.ServerWorld;
|
|
|
|
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
|
|
|
*/
|
|
|
|
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 -> {
|
2021-02-02 11:52:50 +01:00
|
|
|
spawnParticle(entity.world, 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);
|
|
|
|
});
|
|
|
|
}
|
2021-02-02 11:52:50 +01:00
|
|
|
|
|
|
|
public static void spawnParticle(World world, ParticleEffect effect, double x, double y, double z, double vX, double vY, double vZ) {
|
|
|
|
if (world instanceof ServerWorld) {
|
|
|
|
((ServerWorld)world).spawnParticles(effect, x, y, z, 1, vX, vY, vZ, 0);
|
|
|
|
} else {
|
|
|
|
world.addParticle(effect, x, y, z, vX, vY, vZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|