Search in sources :

Example 6 with ModuleInstanceShape

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape in project Wizardry by TeamWizardry.

the class ModuleShapeZone method renderVisualization.

@SideOnly(Side.CLIENT)
@Override
public SpellData renderVisualization(@Nonnull World world, ModuleInstanceShape instance, @Nonnull SpellData data, @Nonnull SpellRing ring, float partialTicks) {
    Vec3d look = data.getData(SpellData.DefaultKeys.LOOK);
    Entity caster = data.getCaster(world);
    if (caster == null)
        return data;
    if (look == null)
        return data;
    Vec3d target;
    double interpPosX = caster.lastTickPosX + (caster.posX - caster.lastTickPosX) * partialTicks;
    double interpPosY = caster.lastTickPosY + (caster.posY - caster.lastTickPosY) * partialTicks;
    double interpPosZ = caster.lastTickPosZ + (caster.posZ - caster.lastTickPosZ) * partialTicks;
    RayTraceResult result = new RayTrace(world, look, new Vec3d(interpPosX, interpPosY + caster.getEyeHeight(), interpPosZ), caster instanceof EntityLivingBase ? ((EntityLivingBase) caster).getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue() : 5).setEntityFilter(input -> input != caster).setReturnLastUncollidableBlock(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
    data.processTrace(result);
    BlockPos pos = data.getTargetPos();
    if (pos == null)
        return data;
    data.processTrace(result);
    target = data.getTarget(world);
    if (target == null)
        return data;
    double aoe = ring.getAttributeValue(world, AttributeRegistry.AREA, data);
    RenderUtils.drawCircle(target, aoe, false, false);
    return data;
}
Also used : InterpCircle(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpCircle) RenderUtils(com.teamwizardry.wizardry.api.util.RenderUtils) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Random(java.util.Random) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) ILingeringModule(com.teamwizardry.wizardry.api.spell.ILingeringModule) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) InterpFloatInOut(com.teamwizardry.librarianlib.features.math.interpolate.numeric.InterpFloatInOut) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) InterpColorHSV(com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV) ModuleInstanceShape(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape) List(java.util.List) AttributeRegistry(com.teamwizardry.wizardry.api.spell.attribute.AttributeRegistry) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NBTHelper(com.teamwizardry.librarianlib.features.helpers.NBTHelper) ResourceLocation(net.minecraft.util.ResourceLocation) RegisterModule(com.teamwizardry.wizardry.api.spell.annotation.RegisterModule) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) NBTConstants(com.teamwizardry.wizardry.api.NBTConstants) NotNull(org.jetbrains.annotations.NotNull) IModuleShape(com.teamwizardry.wizardry.api.spell.module.IModuleShape) DefaultKeys(com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys) Entity(net.minecraft.entity.Entity) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Example 7 with ModuleInstanceShape

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape in project Wizardry by TeamWizardry.

the class ModuleShapeCone method run.

/**
 * {@inheritDoc}
 */
@Override
public boolean run(@NotNull World world, ModuleInstanceShape instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    float yaw = spell.getYaw();
    float pitch = spell.getPitch();
    Entity caster = spell.getCaster(world);
    Vec3d origin = spell.getOriginHand(world);
    if (origin == null)
        return false;
    double range = spellRing.getAttributeValue(world, AttributeRegistry.RANGE, spell);
    int potency = (int) (spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell));
    for (int i = 0; i < potency; i++) {
        if (!spellRing.taxCaster(world, spell, 1.0 / potency, true))
            return false;
        long seed = RandUtil.nextLong(100, 10000);
        spell.addData(SEED, seed);
        IShapeOverrides overrides = spellRing.getOverrideHandler().getConsumerInterface(IShapeOverrides.class);
        overrides.onRunCone(world, spell, spellRing);
        float angle = (float) range * 2;
        float newPitch = pitch + RandUtil.nextFloat(-angle, angle);
        float newYaw = yaw + RandUtil.nextFloat(-angle, angle);
        Vec3d target = PosUtils.vecFromRotations(newPitch, newYaw);
        SpellData newSpell = spell.copy();
        RayTraceResult result = new RayTrace(world, target.normalize(), origin, range).setEntityFilter(input -> input != caster).trace();
        Vec3d lookFallback = spell.getData(LOOK);
        if (lookFallback != null)
            lookFallback.scale(range);
        newSpell.processTrace(result, lookFallback);
        // Is already executed via SpellRing.runSpellRing() ???
        instance.sendRenderPacket(world, newSpell, spellRing);
        newSpell.addData(ORIGIN, result.hitVec);
        if (spellRing.getChildRing() != null) {
            spellRing.getChildRing().runSpellRing(world, newSpell.copy(), true);
        }
    }
    return true;
}
Also used : RenderUtils(com.teamwizardry.wizardry.api.util.RenderUtils) InterpScale(com.teamwizardry.wizardry.api.util.interp.InterpScale) ParticleSpawner(com.teamwizardry.librarianlib.features.particle.ParticleSpawner) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride) PosUtils(com.teamwizardry.wizardry.api.util.PosUtils) ParticleBuilder(com.teamwizardry.librarianlib.features.particle.ParticleBuilder) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) RayTraceResult(net.minecraft.util.math.RayTraceResult) InterpLine(com.teamwizardry.librarianlib.features.math.interpolate.position.InterpLine) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) InterpFloatInOut(com.teamwizardry.librarianlib.features.math.interpolate.numeric.InterpFloatInOut) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) Wizardry(com.teamwizardry.wizardry.Wizardry) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) InterpColorHSV(com.teamwizardry.librarianlib.features.particle.functions.InterpColorHSV) ModuleInstanceShape(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape) AttributeRegistry(com.teamwizardry.wizardry.api.spell.attribute.AttributeRegistry) ResourceLocation(net.minecraft.util.ResourceLocation) RegisterModule(com.teamwizardry.wizardry.api.spell.annotation.RegisterModule) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) NBTConstants(com.teamwizardry.wizardry.api.NBTConstants) NotNull(org.jetbrains.annotations.NotNull) IModuleShape(com.teamwizardry.wizardry.api.spell.module.IModuleShape) DefaultKeys(com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys) Entity(net.minecraft.entity.Entity) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) 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 8 with ModuleInstanceShape

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape in project Wizardry by TeamWizardry.

the class ModuleShapeBeam method renderVisualization.

@NotNull
@Override
public SpellData renderVisualization(@Nonnull World world, ModuleInstanceShape instance, @Nonnull SpellData data, @Nonnull SpellRing ring, float partialTicks) {
    Vec3d look = data.getData(LOOK);
    Vec3d position = data.getOrigin(world);
    Entity caster = data.getCaster(world);
    if (look == null || position == null || caster == null)
        return data;
    double range = ring.getAttributeValue(world, AttributeRegistry.RANGE, data);
    double interpPosX = caster.lastTickPosX + (caster.posX - caster.lastTickPosX) * partialTicks;
    double interpPosY = caster.lastTickPosY + (caster.posY - caster.lastTickPosY) * partialTicks;
    double interpPosZ = caster.lastTickPosZ + (caster.posZ - caster.lastTickPosZ) * partialTicks;
    RayTraceResult result = new RayTrace(world, look, new Vec3d(interpPosX, interpPosY + caster.getEyeHeight(), interpPosZ), range).setEntityFilter(input -> input != caster).setReturnLastUncollidableBlock(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
    data.processTrace(result, look.scale(range));
    Vec3d target = data.getTarget(world);
    if (target == null)
        return data;
    RenderUtils.drawCircle(target, 0.3, true, false);
    return data;
}
Also used : RenderUtils(com.teamwizardry.wizardry.api.util.RenderUtils) HashMap(java.util.HashMap) ModuleOverrideSuper(com.teamwizardry.wizardry.api.spell.module.ModuleOverrideSuper) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) Mod(net.minecraftforge.fml.common.Mod) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) ConfigValues(com.teamwizardry.wizardry.api.ConfigValues) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) ContextSuper(com.teamwizardry.wizardry.api.spell.annotation.ContextSuper) LOOK(com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys.LOOK) Wizardry(com.teamwizardry.wizardry.Wizardry) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) ModuleInstanceShape(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape) IContinuousModule(com.teamwizardry.wizardry.api.spell.IContinuousModule) AttributeRegistry(com.teamwizardry.wizardry.api.spell.attribute.AttributeRegistry) EntityLivingBase(net.minecraft.entity.EntityLivingBase) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) RegisterModule(com.teamwizardry.wizardry.api.spell.annotation.RegisterModule) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) NotNull(org.jetbrains.annotations.NotNull) IModuleShape(com.teamwizardry.wizardry.api.spell.module.IModuleShape) Entity(net.minecraft.entity.Entity) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) NotNull(org.jetbrains.annotations.NotNull) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Example 9 with ModuleInstanceShape

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape in project Wizardry by TeamWizardry.

the class ModuleShapeBeam method run.

/**
 * {@inheritDoc}
 */
@Override
public boolean run(@NotNull World world, ModuleInstanceShape instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    Vec3d look = spell.getData(LOOK);
    Vec3d position = spell.getOrigin(world);
    Entity caster = spell.getCaster(world);
    if (look == null || position == null || caster == null)
        return false;
    ItemStack stack = ((EntityLivingBase) caster).getHeldItemMainhand();
    if (stack.isEmpty())
        return true;
    beamTickMap.putIfAbsent(stack, new BeamTicker());
    BeamTicker ticker = beamTickMap.get(stack);
    double range = spellRing.getAttributeValue(world, AttributeRegistry.RANGE, spell);
    double potency = spellRing.getAttributeValue(world, AttributeRegistry.POTENCY, spell);
    double beamOffset = ticker.ticks + potency;
    ticker.cast = false;
    if (beamOffset >= ConfigValues.beamTimer) {
        beamOffset %= ConfigValues.beamTimer;
        if (!spellRing.taxCaster(world, spell, true)) {
            ticker.ticks = beamOffset;
            return false;
        }
        IShapeOverrides overrides = spellRing.getOverrideHandler().getConsumerInterface(IShapeOverrides.class);
        overrides.onRunBeam(world, spell, spellRing);
        RayTraceResult trace = new RayTrace(world, look, position, range).setEntityFilter(input -> input != caster).setReturnLastUncollidableBlock(true).setIgnoreBlocksWithoutBoundingBoxes(true).trace();
        spell.processTrace(trace, look.scale(range));
        if (spellRing.getChildRing() != null)
            spellRing.getChildRing().runSpellRing(world, spell, true);
        ticker.cast = true;
        // Is already executed via SpellRing.runSpellRing() ???
        instance.sendRenderPacket(world, spell, spellRing);
    }
    ticker.ticks = beamOffset;
    return true;
}
Also used : RenderUtils(com.teamwizardry.wizardry.api.util.RenderUtils) HashMap(java.util.HashMap) ModuleOverrideSuper(com.teamwizardry.wizardry.api.spell.module.ModuleOverrideSuper) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride) SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) Mod(net.minecraftforge.fml.common.Mod) SpellData(com.teamwizardry.wizardry.api.spell.SpellData) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nonnull(javax.annotation.Nonnull) ConfigValues(com.teamwizardry.wizardry.api.ConfigValues) Entity(net.minecraft.entity.Entity) World(net.minecraft.world.World) ContextSuper(com.teamwizardry.wizardry.api.spell.annotation.ContextSuper) LOOK(com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys.LOOK) Wizardry(com.teamwizardry.wizardry.Wizardry) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) ModuleInstanceShape(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape) IContinuousModule(com.teamwizardry.wizardry.api.spell.IContinuousModule) AttributeRegistry(com.teamwizardry.wizardry.api.spell.attribute.AttributeRegistry) EntityLivingBase(net.minecraft.entity.EntityLivingBase) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) RegisterModule(com.teamwizardry.wizardry.api.spell.annotation.RegisterModule) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) NotNull(org.jetbrains.annotations.NotNull) IModuleShape(com.teamwizardry.wizardry.api.spell.module.IModuleShape) Entity(net.minecraft.entity.Entity) RayTrace(com.teamwizardry.wizardry.api.util.RayTrace) EntityLivingBase(net.minecraft.entity.EntityLivingBase) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) ModuleOverride(com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)

Aggregations

SpellData (com.teamwizardry.wizardry.api.spell.SpellData)9 SpellRing (com.teamwizardry.wizardry.api.spell.SpellRing)9 ModuleOverride (com.teamwizardry.wizardry.api.spell.annotation.ModuleOverride)9 RegisterModule (com.teamwizardry.wizardry.api.spell.annotation.RegisterModule)9 IModuleShape (com.teamwizardry.wizardry.api.spell.module.IModuleShape)9 ModuleInstanceShape (com.teamwizardry.wizardry.api.spell.module.ModuleInstanceShape)9 RandUtil (com.teamwizardry.wizardry.api.util.RandUtil)9 RayTrace (com.teamwizardry.wizardry.api.util.RayTrace)9 RenderUtils (com.teamwizardry.wizardry.api.util.RenderUtils)9 Nonnull (javax.annotation.Nonnull)9 Entity (net.minecraft.entity.Entity)9 RayTraceResult (net.minecraft.util.math.RayTraceResult)9 Vec3d (net.minecraft.util.math.Vec3d)9 World (net.minecraft.world.World)9 Side (net.minecraftforge.fml.relauncher.Side)9 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)9 NotNull (org.jetbrains.annotations.NotNull)9 Wizardry (com.teamwizardry.wizardry.Wizardry)8 AttributeRegistry (com.teamwizardry.wizardry.api.spell.attribute.AttributeRegistry)7 LOOK (com.teamwizardry.wizardry.api.spell.SpellData.DefaultKeys.LOOK)6