Unicopia/src/main/java/com/minelittlepony/unicopia/spell/ICaster.java

60 lines
1.6 KiB
Java
Raw Normal View History

2018-09-12 01:29:49 +02:00
package com.minelittlepony.unicopia.spell;
2019-01-20 00:07:59 +01:00
import java.util.Random;
import java.util.function.Consumer;
import java.util.stream.Stream;
import com.minelittlepony.unicopia.player.IOwned;
2019-01-20 00:07:59 +01:00
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.vector.VecHelper;
2018-09-12 01:29:49 +02:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
2018-09-24 21:37:16 +02:00
import net.minecraft.util.math.BlockPos;
2019-01-20 00:07:59 +01:00
import net.minecraft.util.math.Vec3d;
2018-09-24 21:37:16 +02:00
import net.minecraft.world.World;
2018-09-12 01:29:49 +02:00
public interface ICaster<E extends EntityLivingBase> extends IOwned<E>, ILevelled {
2018-09-12 01:29:49 +02:00
void setEffect(IMagicEffect effect);
IMagicEffect getEffect();
SpellAffinity getAffinity();
2018-09-12 01:29:49 +02:00
default boolean hasEffect() {
return getEffect() != null;
}
/**
* Gets the entity directly responsible for casting.
*/
2018-09-12 01:29:49 +02:00
default Entity getEntity() {
return getOwner();
}
2018-09-24 21:37:16 +02:00
default World getWorld() {
return getEntity().getEntityWorld();
}
default BlockPos getOrigin() {
return getEntity().getPosition();
}
2019-01-20 00:07:59 +01:00
default void spawnParticles(IShape area, int count, Consumer<Vec3d> particleSpawner) {
Random rand = getWorld().rand;
2019-01-26 18:27:47 +01:00
double x = getEntity().posX;
double y = getEntity().posY;
double z = getEntity().posZ;
2019-01-20 00:07:59 +01:00
for (int i = 0; i < count; i++) {
particleSpawner.accept(area.computePoint(rand).add(x, y, z));
}
}
default Stream<Entity> findAllEntitiesInRange(double radius) {
return VecHelper.findAllEntitiesInRange(getEntity(), getWorld(), getOrigin(), radius);
}
2018-09-12 01:29:49 +02:00
}