Search in sources :

Example 1 with ILingeringModule

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

the class Module method castSpell.

/**
 * Use this to run the module properly without rendering.
 *
 * @param spell      The spellData associated with it.
 * @param spellRing The SpellRing made with this.
 * @return If the spellData has succeeded.
 */
public final boolean castSpell(@Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
    if (spell.world.isRemote)
        return true;
    if (this instanceof ILingeringModule) {
        boolean alreadyLingering = false;
        for (SpellTicker.LingeringObject lingeringObject : SpellTicker.getStorageMap()) {
            if (lingeringObject.getSpellRing() == spellRing || lingeringObject.getSpellData() == spell) {
                alreadyLingering = true;
                break;
            }
        }
        if (!alreadyLingering)
            SpellTicker.addLingerSpell(spellRing, spell, ((ILingeringModule) this).getLingeringTime(spell, spellRing));
    }
    SpellCastEvent event = new SpellCastEvent(spellRing, spell);
    MinecraftForge.EVENT_BUS.post(event);
    return !event.isCanceled() && run(spell, spellRing);
}
Also used : SpellTicker(com.teamwizardry.wizardry.common.core.SpellTicker) SpellCastEvent(com.teamwizardry.wizardry.api.events.SpellCastEvent) ILingeringModule(com.teamwizardry.wizardry.api.spell.ILingeringModule)

Example 2 with ILingeringModule

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

the class ModuleInstance method castSpell.

/**
 * Use this to run the module properly.
 *
 * @param data    The spellData associated with it.
 * @param ring    The SpellRing made with this.
 * @return If the spellData has succeeded.
 */
public final boolean castSpell(@Nonnull World world, @Nonnull SpellData data, @Nonnull SpellRing ring) {
    if (world.isRemote)
        return true;
    boolean success;
    boolean ranOnce = false;
    NBTTagList list = data.getDataWithFallback(SpellData.DefaultKeys.TAG_LIST, new NBTTagList());
    for (NBTBase base : list) {
        if (base instanceof NBTTagString) {
            if (((NBTTagString) base).getString().equals(ring.getUniqueID().toString())) {
                ranOnce = true;
                break;
            }
        }
    }
    if (moduleClass instanceof ILingeringModule && !ranOnce) {
        WizardryWorld worldCap = WizardryWorldCapability.get(world);
        list.appendTag(new NBTTagString(ring.getUniqueID().toString()));
        data.addData(SpellData.DefaultKeys.TAG_LIST, list);
        success = internalCastSpell(world, data, ring) && ((ILingeringModule) moduleClass).runOnStart(world, data, ring);
        if (success) {
            worldCap.getSpellObjectManager().addLingering(new SpellObjectManager.LingeringObject(world, data, ring), ((ILingeringModule) moduleClass).getLingeringTime(world, data, ring));
        }
    } else {
        success = internalCastSpell(world, data, ring);
    }
    if (success || ignoreResultsForRendering()) {
        sendRenderPacket(world, data, ring);
    }
    return success;
}
Also used : WizardryWorld(com.teamwizardry.wizardry.api.capability.world.WizardryWorld) SpellObjectManager(com.teamwizardry.wizardry.api.SpellObjectManager) ILingeringModule(com.teamwizardry.wizardry.api.spell.ILingeringModule)

Aggregations

ILingeringModule (com.teamwizardry.wizardry.api.spell.ILingeringModule)2 SpellObjectManager (com.teamwizardry.wizardry.api.SpellObjectManager)1 WizardryWorld (com.teamwizardry.wizardry.api.capability.world.WizardryWorld)1 SpellCastEvent (com.teamwizardry.wizardry.api.events.SpellCastEvent)1 SpellTicker (com.teamwizardry.wizardry.common.core.SpellTicker)1