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;
}
Aggregations