Unicopia/src/main/java/com/minelittlepony/unicopia/particles/ParticleSource.java

43 lines
1.1 KiB
Java
Raw Normal View History

2020-04-22 16:28:20 +02:00
package com.minelittlepony.unicopia.particles;
2020-01-27 11:05:22 +01:00
import java.util.function.Consumer;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.util.shape.Shape;
2020-01-27 11:05:22 +01:00
import net.minecraft.entity.Entity;
2020-01-27 11:05:22 +01:00
import net.minecraft.particle.ParticleEffect;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public interface ParticleSource {
2020-01-27 11:05:22 +01:00
/**
* gets the minecraft world
*/
World getWorld();
/**
* Gets the center position where this caster is located.
*/
Vec3d getOriginVector();
Entity getEntity();
2020-01-27 11:05:22 +01:00
default void spawnParticles(ParticleEffect particleId, int count) {
ParticleUtils.spawnParticles(particleId, getEntity(), count);
2020-01-27 11:05:22 +01:00
}
2020-04-15 18:12:00 +02:00
default void spawnParticles(Shape area, int count, Consumer<Vec3d> particleSpawner) {
2020-01-27 11:05:22 +01:00
Vec3d pos = getOriginVector();
2020-04-24 00:17:38 +02:00
area.randomPoints(count, getWorld().random)
2020-01-27 11:05:22 +01:00
.map(point -> point.add(pos))
.forEach(particleSpawner);
}
default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) {
getWorld().addParticle(effect, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z);
}
}