Search in sources :

Example 1 with LightningGenerator

use of com.teamwizardry.wizardry.api.LightningGenerator in project Wizardry by TeamWizardry.

the class ModuleEffectLightning method run.

@Override
public boolean run(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    World world = spell.world;
    Vec3d target = spell.getTarget();
    Entity caster = spell.getCaster();
    float yaw = spell.getData(YAW, 0F);
    float pitch = spell.getData(PITCH, 0F);
    if (target == null)
        return false;
    Vec3d origin = target;
    if (caster != null) {
        float offX = 0.5f * (float) Math.sin(Math.toRadians(-90.0f - yaw));
        float offZ = 0.5f * (float) Math.cos(Math.toRadians(-90.0f - yaw));
        origin = new Vec3d(offX, caster.getEyeHeight(), offZ).add(target);
    }
    double range = spellRing.getAttributeValue(AttributeRegistry.RANGE, spell);
    double strength = spellRing.getAttributeValue(AttributeRegistry.POTENCY, spell) / 2.0;
    if (!spellRing.taxCaster(spell))
        return false;
    RayTraceResult traceResult = new RayTrace(world, PosUtils.vecFromRotations(pitch, yaw), target, range).setSkipBlocks(true).setSkipEntities(true).trace();
    long seed = RandUtil.nextLong(100, 100000);
    spell.addData(SEED, seed);
    LightningGenerator generator = new LightningGenerator(origin, traceResult.hitVec, new RandUtilSeed(seed));
    ArrayList<Vec3d> points = generator.generate();
    spell.world.playSound(null, new BlockPos(traceResult.hitVec), ModSounds.LIGHTNING, SoundCategory.NEUTRAL, 0.5f, RandUtil.nextFloat(1, 1.5f));
    for (Vec3d point : points) {
        List<Entity> entityList = world.getEntitiesWithinAABBExcludingEntity(caster, new AxisAlignedBB(new BlockPos(point)).contract(0.2, 0.2, 0.2));
        if (!entityList.isEmpty()) {
            for (Entity entity : entityList) {
                LightningTracker.INSTANCE.addEntity(origin, entity, caster, (int) strength);
            }
        }
    }
    return true;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) Vec3d(net.minecraft.util.math.Vec3d) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) BlockPos(net.minecraft.util.math.BlockPos) LightningGenerator(com.teamwizardry.wizardry.api.LightningGenerator)

Aggregations

LightningGenerator (com.teamwizardry.wizardry.api.LightningGenerator)1 RandUtilSeed (com.teamwizardry.wizardry.api.util.RandUtilSeed)1 RayTrace (com.teamwizardry.wizardry.api.util.RayTrace)1 Entity (net.minecraft.entity.Entity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1