Search in sources :

Example 1 with ManaCostEvent

use of am2.api.events.ManaCostEvent in project ArsMagica2 by Mithion.

the class SpellBase method addInformation.

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
    if (!stack.hasTagCompound())
        return;
    ItemStack legacySpell = SpellUtils.instance.constructSpellStack(stack);
    SpellRequirements reqs = SpellUtils.instance.getSpellRequirements(legacySpell, player);
    float manaCost = reqs.manaCost;
    float burnout = reqs.burnout;
    ArrayList<ItemStack> reagents = reqs.reagents;
    ManaCostEvent mce = new ManaCostEvent(legacySpell, player, manaCost, 0);
    MinecraftForge.EVENT_BUS.post(mce);
    manaCost = mce.manaCost;
    list.add(String.format("\2477Mana Cost: %.2f", manaCost));
    if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
        HashMap<Affinity, Float> affinityData = SpellUtils.instance.AffinityFor(legacySpell);
        for (Affinity aff : affinityData.keySet()) {
            list.add(String.format("%s (%.2f%%)", aff.toString(), affinityData.get(aff) * 100));
        }
        if (stack.stackTagCompound.hasKey("Lore")) {
            NBTTagList nbttaglist1 = stack.stackTagCompound.getTagList("Lore", Constants.NBT.TAG_COMPOUND);
            if (nbttaglist1.tagCount() > 0) {
                for (int j = 0; j < nbttaglist1.tagCount(); ++j) {
                    list.add(EnumChatFormatting.DARK_PURPLE + "" + EnumChatFormatting.ITALIC + nbttaglist1.getStringTagAt(j));
                }
            }
        }
    } else {
        list.add(StatCollector.translateToLocal("am2.tooltip.shiftForAffinity"));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) SpellRequirements(am2.spell.SpellUtils.SpellRequirements) ManaCostEvent(am2.api.events.ManaCostEvent) Affinity(am2.api.spell.enums.Affinity) ItemStack(net.minecraft.item.ItemStack) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 2 with ManaCostEvent

use of am2.api.events.ManaCostEvent in project ArsMagica2 by Mithion.

the class SpellHelper method preSpellCast.

private SpellCastingEvent.Pre preSpellCast(ItemStack stack, EntityLivingBase caster, boolean isChanneled) {
    SpellRequirements reqs = SpellUtils.instance.getSpellRequirements(stack, caster);
    float manaCost = reqs.manaCost;
    float burnout = reqs.burnout;
    ArrayList<ItemStack> reagents = reqs.reagents;
    ManaCostEvent mce = new ManaCostEvent(stack, caster, manaCost, burnout);
    MinecraftForge.EVENT_BUS.post(mce);
    manaCost = mce.manaCost;
    burnout = mce.burnout;
    SpellCastingEvent.Pre event = new SpellCastingEvent().new Pre(stack, (ItemSpellBase) stack.getItem(), caster, manaCost, burnout, isChanneled);
    if (MinecraftForge.EVENT_BUS.post(event)) {
        event.castResult = SpellCastResult.EFFECT_FAILED;
        return event;
    }
    event.castResult = SpellCastResult.SUCCESS;
    if (!SpellUtils.instance.casterHasAllReagents(caster, reagents))
        event.castResult = SpellCastResult.REAGENTS_MISSING;
    if (!SpellUtils.instance.casterHasMana(caster, manaCost))
        event.castResult = SpellCastResult.NOT_ENOUGH_MANA;
    return event;
}
Also used : SpellRequirements(am2.spell.SpellUtils.SpellRequirements) ManaCostEvent(am2.api.events.ManaCostEvent) ItemStack(net.minecraft.item.ItemStack) SpellCastingEvent(am2.api.events.SpellCastingEvent)

Aggregations

ManaCostEvent (am2.api.events.ManaCostEvent)2 SpellRequirements (am2.spell.SpellUtils.SpellRequirements)2 ItemStack (net.minecraft.item.ItemStack)2 SpellCastingEvent (am2.api.events.SpellCastingEvent)1 Affinity (am2.api.spell.enums.Affinity)1 SideOnly (cpw.mods.fml.relauncher.SideOnly)1 NBTTagList (net.minecraft.nbt.NBTTagList)1