2020-09-22 15:11:20 +02:00
|
|
|
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
|
|
|
|
2020-04-15 14:22:03 +02: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
|
|
|
|
*/
|
2022-06-23 16:24:45 +02:00
|
|
|
World getReferenceWorld();
|
2020-01-27 11:05:22 +01:00
|
|
|
|
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-04-15 14:22:03 +02:00
|
|
|
|
2020-01-27 11:05:22 +01:00
|
|
|
default void spawnParticles(ParticleEffect particleId, int count) {
|
2020-04-15 14:22:03 +02:00
|
|
|
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) {
|
2022-06-23 16:24:45 +02:00
|
|
|
area.randomPoints(count, getReferenceWorld().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) {
|
2022-06-23 16:24:45 +02:00
|
|
|
getReferenceWorld().addParticle(effect, position.x, position.y, position.z, velocity.x, velocity.y, velocity.z);
|
2020-01-27 11:05:22 +01:00
|
|
|
}
|
|
|
|
}
|