use of com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride in project Wizardry by TeamWizardry.
the class ModuleEffectVanish method onRunZone.
@ModuleOverride("shape_zone_run")
public boolean onRunZone(World world, SpellData data, SpellRing ring, @ContextRing SpellRing childRing) {
double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);
Vec3d targetPos = data.getTarget(world);
if (targetPos == null)
return false;
Vec3d min = targetPos.subtract(aoe, range, aoe);
Vec3d max = targetPos.add(aoe, range, aoe);
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(min, max));
for (Entity entity : entities) {
if (entity instanceof EntityLivingBase) {
if (!VanishTracker.isVanished(entity) && entity.getDistanceSq(targetPos.x, targetPos.y, targetPos.z) <= aoe * aoe) {
data.processEntity(entity, false);
run(world, (ModuleInstanceEffect) childRing.getModule(), data, childRing);
}
}
}
return true;
}
use of com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride in project Wizardry by TeamWizardry.
the class ModuleEffectLightning method onRunSelf.
@ModuleOverride("shape_self_run")
public void onRunSelf(@ContextSuper ModuleOverrideSuper ovdSuper, World world, SpellData data, SpellRing shape, @ContextRing SpellRing childRing) {
if (ovdSuper.hasSuper())
ovdSuper.invoke(true, world, data, shape);
if (world.isRemote)
return;
Entity caster = data.getCaster(world);
if (caster == null)
return;
Vec3d origin = data.getOrigin(world);
if (origin == null)
return;
if (!childRing.taxCaster(world, data, true))
return;
double range = childRing.getAttributeValue(world, AttributeRegistry.RANGE, data);
double potency = childRing.getAttributeValue(world, AttributeRegistry.POTENCY, data);
double duration = childRing.getAttributeValue(world, AttributeRegistry.DURATION, data);
RandUtilSeed rand = new RandUtilSeed(RandUtil.nextLong(100, 100000));
float pitch = rand.nextFloat(-45, 45);
float yaw = rand.nextFloat(0, 360);
doLightning(rand.nextLong(100, 100000), world, caster, origin, Vec3d.fromPitchYaw(pitch, yaw).normalize().scale(range).add(origin), range, potency, duration);
}
use of com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride in project Wizardry by TeamWizardry.
the class ModuleEffectLightning method onRunCone.
@ModuleOverride("shape_cone_run")
public void onRunCone(@ContextSuper ModuleOverrideSuper ovdSuper, World world, SpellData data, SpellRing shape, @ContextRing SpellRing childRing) {
if (ovdSuper.hasSuper())
ovdSuper.invoke(true, world, data, shape);
float yaw = data.getYaw();
float pitch = data.getPitch();
Vec3d origin = data.getOriginHand(world);
Entity caster = data.getCaster(world);
if (origin == null)
return;
if (!childRing.taxCaster(world, data, true))
return;
double coneRange = shape.getAttributeValue(world, AttributeRegistry.RANGE, data);
double lightningRange = childRing.getAttributeValue(world, AttributeRegistry.RANGE, data);
double lightningPotency = childRing.getAttributeValue(world, AttributeRegistry.POTENCY, data);
double lightningDuration = childRing.getAttributeValue(world, AttributeRegistry.DURATION, data);
RandUtilSeed rand = new RandUtilSeed(RandUtil.nextLong(100, 100000));
float angle = (float) coneRange * 2;
float newPitch = pitch + rand.nextFloat(-angle, angle);
float newYaw = yaw + rand.nextFloat(-angle, angle);
Vec3d to = Vec3d.fromPitchYaw(newPitch, newYaw).normalize().scale(coneRange).add(origin);
doLightning(rand.nextLong(100, 100000), world, caster, origin, to, lightningRange, lightningPotency, lightningDuration);
}
use of com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride in project Wizardry by TeamWizardry.
the class ModuleEffectLightning method onRunBeam.
@ModuleOverride("shape_beam_run")
public void onRunBeam(@ContextSuper ModuleOverrideSuper ovdSuper, World world, SpellData data, SpellRing shape, @ContextRing SpellRing childRing) {
if (ovdSuper.hasSuper())
ovdSuper.invoke(true, world, data, shape);
if (world.isRemote)
return;
Entity caster = data.getCaster(world);
float yaw = data.getYaw();
float pitch = data.getPitch();
Vec3d origin = data.getOriginHand(world);
if (origin == null)
return;
if (!childRing.taxCaster(world, data, true))
return;
double lightningRange = childRing.getAttributeValue(world, AttributeRegistry.RANGE, data);
double lightningPotency = childRing.getAttributeValue(world, AttributeRegistry.POTENCY, data);
double lightningDuration = childRing.getAttributeValue(world, AttributeRegistry.DURATION, data);
double beamRange = shape.getAttributeValue(world, AttributeRegistry.RANGE, data);
RayTraceResult traceResult = new RayTrace(world, PosUtils.vecFromRotations(pitch, yaw), origin, beamRange).setSkipBlocks(true).setSkipEntities(true).trace();
doLightning(RandUtil.nextLong(100, 100000), world, caster, origin, traceResult.hitVec, lightningRange, lightningPotency, lightningDuration);
}
use of com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride in project Wizardry by TeamWizardry.
the class ModuleOverrideHandler method getOverrideMethodsFromClass.
/**
* Returns a list of override methods from a given type, implementing them.
*
* @param clazz the type.
* @param hasContext if <code>true</code> then the method may contain context parameters.
* @return a collection, mapping override names to their according methods.
* @throws ModuleInitException if a method exists having invalid argument types or if some issues with reflection occurred.
*/
static HashMap<String, OverrideMethod> getOverrideMethodsFromClass(Class<?> clazz, boolean hasContext) throws ModuleInitException {
HashMap<String, OverrideMethod> overridableMethods = new HashMap<>();
// FIXME: Separation of concerns: Overridable methods are not part of factory. Move them or rename factory class appropriately.
for (Method method : clazz.getMethods()) {
ModuleOverride ovrd = method.getDeclaredAnnotation(ModuleOverride.class);
if (ovrd == null)
continue;
if (overridableMethods.containsKey(ovrd.value()))
throw new ModuleInitException("Multiple methods exist in class '" + clazz + "' with same override name '" + ovrd.value() + "'.");
try {
method.setAccessible(true);
} catch (SecurityException e) {
throw new ModuleInitException("Failed to aquire reflection access to method '" + method.toString() + "', annotated by @ModuleOverride.", e);
}
// Search for context parameters
int idxContextParamRing = -1;
int idxContextParamSuper = -2;
Parameter[] params = method.getParameters();
for (int i = 0; i < params.length; i++) {
Parameter param = params[i];
if (param.isAnnotationPresent(ContextRing.class)) {
if (idxContextParamRing >= 0)
throw new ModuleInitException("Method '" + method.toString() + "' has invalid @ContextRing annotated parameter. It is not allowed on multiple parameters.");
idxContextParamRing = i;
}
if (param.isAnnotationPresent(ContextSuper.class)) {
if (idxContextParamSuper >= 0)
throw new ModuleInitException("Method '" + method.toString() + "' has invalid @ContextSuper annotated parameter. It is not allowed on multiple parameters.");
idxContextParamSuper = i;
}
}
if (!hasContext) {
if (idxContextParamRing >= 0 || idxContextParamSuper >= 0)
throw new ModuleInitException("Context parameters are not allowed.");
}
if (idxContextParamRing == idxContextParamSuper)
throw new ModuleInitException("Method '" + method.toString() + "' has a parameter which is annotated with multiple roles.");
OverrideMethod ovrdMethod = new OverrideMethod(method, idxContextParamRing, idxContextParamSuper);
overridableMethods.put(ovrd.value(), ovrdMethod);
}
return overridableMethods;
}
Aggregations