Search in sources :

Example 1 with ModuleOverride

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;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Vec3d(net.minecraft.util.math.Vec3d) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Example 2 with ModuleOverride

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);
}
Also used : Entity(net.minecraft.entity.Entity) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) Vec3d(net.minecraft.util.math.Vec3d) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Example 3 with ModuleOverride

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);
}
Also used : Entity(net.minecraft.entity.Entity) RandUtilSeed(com.teamwizardry.wizardry.api.util.RandUtilSeed) Vec3d(net.minecraft.util.math.Vec3d) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Example 4 with ModuleOverride

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);
}
Also used : Entity(net.minecraft.entity.Entity) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Example 5 with ModuleOverride

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;
}
Also used : ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride) HashMap(java.util.HashMap) Parameter(java.lang.reflect.Parameter) OverrideDefaultMethod(com.teamwizardry.wizardry.api.spell.module.ModuleRegistry.OverrideDefaultMethod) Method(java.lang.reflect.Method)

Aggregations

ModuleOverride (com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)11 Vec3d (net.minecraft.util.math.Vec3d)10 Entity (net.minecraft.entity.Entity)9 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 RandUtilSeed (com.teamwizardry.wizardry.api.util.RandUtilSeed)4 RayTrace (com.teamwizardry.wizardry.api.util.RayTrace)2 EntityLightningProjectile (com.teamwizardry.wizardry.common.entity.projectile.EntityLightningProjectile)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 PacketHandler (com.teamwizardry.librarianlib.features.network.PacketHandler)1 LightningGenerator (com.teamwizardry.wizardry.api.LightningGenerator)1 SpellData (com.teamwizardry.wizardry.api.spell.SpellData)1 LOOK (com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys.LOOK)1 SpellRing (com.teamwizardry.wizardry.api.spell.SpellRing)1 ContextRing (com.teamwizardry.wizardry.api.spell.annotation.ContextRing)1 ContextSuper (com.teamwizardry.wizardry.api.spell.annotation.ContextSuper)1 RegisterModule (com.teamwizardry.wizardry.api.spell.annotation.RegisterModule)1 AttributeRegistry (com.teamwizardry.wizardry.api.spell.attribute.AttributeRegistry)1 IModuleEffect (com.teamwizardry.wizardry.api.spell.module.IModuleEffect)1 ModuleInstanceEffect (com.teamwizardry.wizardry.api.spell.module.ModuleInstanceEffect)1