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

47 lines
1.4 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.particle;
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;
2020-04-24 22:40:02 +02:00
public interface ParticleSource extends ParticleSpawner {
2020-01-27 11:05:22 +01:00
/**
* gets the minecraft world
*/
World getWorld();
2020-10-02 09:39:00 +02:00
Entity getEntity();
2020-01-27 11:05:22 +01:00
/**
* Gets the center position where this caster is located.
*/
2020-10-02 09:39:00 +02:00
default Vec3d getOriginVector() {
return getEntity().getPos();
}
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) {
2021-03-03 19:03:16 +01:00
spawnParticles(getOriginVector(), area, count, particleSpawner);
}
2020-01-27 11:05:22 +01:00
2021-03-03 19:03:16 +01:00
default void spawnParticles(Vec3d pos, Shape area, int count, Consumer<Vec3d> particleSpawner) {
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);
}
2020-04-24 22:40:02 +02:00
@Override
2020-01-27 11:05:22 +01:00
default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) {
getWorld().addParticle(effect, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z);
}
}