Search in sources :

Example 1 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.

the class SpellValidator method validateStage.

private StageValidations validateStage(ArrayList<ISpellPart> stageDefinition, boolean isFinalStage) {
    boolean terminus = false;
    boolean principum = false;
    boolean one_component = !isFinalStage;
    boolean one_shape = false;
    for (ISpellPart part : stageDefinition) {
        if (part instanceof Summon)
            return StageValidations.TERMINUS;
        if (part instanceof ISpellShape) {
            one_shape = true;
            if (((ISpellShape) part).isTerminusShape())
                terminus = true;
            if (((ISpellShape) part).isPrincipumShape())
                principum = true;
            continue;
        }
        if (part instanceof ISpellComponent) {
            one_component = true;
            continue;
        }
    }
    if (principum)
        return StageValidations.PRINCIPUM;
    if (!one_component || !one_shape)
        return StageValidations.NOT_VALID;
    if (terminus)
        return StageValidations.TERMINUS;
    return StageValidations.VALID;
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) Summon(am2.spell.components.Summon) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) ISpellPart(am2.api.spell.component.interfaces.ISpellPart)

Example 2 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.

the class SpellRecipeManager method RegisterRecipe.

public void RegisterRecipe(ISpellPart part) {
    ArrayList<Object> recipeItems = new ArrayList<Object>();
    Object[] recipe = part.getRecipeItems();
    SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipe);
    MinecraftForge.EVENT_BUS.post(event);
    recipe = event.recipeItems;
    if (recipe == null) {
        LogHelper.info("Component %s has been registered with no craftable recipe - is this intentional?  If so, return a 0-length array for recipe.", SkillManager.instance.getDisplayName(part));
        return;
    }
    if (recipe.length == 0) {
        return;
    }
    for (int i = 0; i < recipe.length; ++i) {
        Object o = recipe[i];
        if (o instanceof Item) {
            recipeItems.add(new ItemStack((Item) o));
        } else if (o instanceof Block) {
            recipeItems.add(new ItemStack((Block) o));
        } else if (o instanceof String) {
            if (((String) o).toLowerCase().startsWith("e:")) {
                if (i == recipe.length - 1 || !(recipe[i + 1] instanceof Integer)) {
                    LogHelper.warn("Error registering recipe.  Power must be declared in Integer pairs (type flags, quantity)).");
                    return;
                }
                int[] ids = ParseEssenceIDs((String) o);
                int flag = 0;
                for (int f : ids) {
                    flag |= f;
                }
                int quantity = (Integer) recipe[++i];
                ItemStack stack = new ItemStack(ItemsCommonProxy.essence, quantity, ItemEssence.META_MAX + flag);
                recipeItems.add(stack);
            } else {
                recipeItems.add(o);
            }
        } else {
            recipeItems.add(o);
        }
    }
    recipes.put(recipeItems, part);
}
Also used : Item(net.minecraft.item.Item) SpellRecipeItemsEvent(am2.api.events.SpellRecipeItemsEvent) ArrayList(java.util.ArrayList) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.

the class TileEntityInscriptionTable method createSpellForPlayer.

public void createSpellForPlayer(EntityPlayer player) {
    if (worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(xCoord);
        writer.add(yCoord);
        writer.add(zCoord);
        writer.add(MAKE_SPELL);
        writer.add(player.getEntityId());
        AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.INSCRIPTION_TABLE_UPDATE, writer.generate());
    } else {
        ArrayList<ArrayList<KeyValuePair<ISpellPart, byte[]>>> shapeGroupSetup = new ArrayList<ArrayList<KeyValuePair<ISpellPart, byte[]>>>();
        ArrayList<KeyValuePair<ISpellPart, byte[]>> curRecipeSetup = new ArrayList<KeyValuePair<ISpellPart, byte[]>>();
        for (ArrayList<ISpellPart> arr : shapeGroups) {
            shapeGroupSetup.add(new ArrayList<KeyValuePair<ISpellPart, byte[]>>());
            for (ISpellPart part : arr) {
                shapeGroupSetup.get(shapeGroupSetup.size() - 1).add(new KeyValuePair<ISpellPart, byte[]>(part, new byte[0]));
            }
        }
        for (ISpellPart part : currentRecipe) {
            curRecipeSetup.add(new KeyValuePair<ISpellPart, byte[]>(part, new byte[0]));
        }
        ItemStack stack = SpellUtils.instance.createSpellStack(shapeGroupSetup, curRecipeSetup);
        stack.stackTagCompound.setString("suggestedName", currentSpellName);
        player.inventory.addItemStackToInventory(stack);
    }
}
Also used : KeyValuePair(am2.utility.KeyValuePair) ItemStack(net.minecraft.item.ItemStack) AMDataWriter(am2.network.AMDataWriter)

Example 4 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method matchCurrentRecipe.

private boolean matchCurrentRecipe() {
    ISpellPart part = SpellRecipeManager.instance.getPartByRecipe(currentAddedItems);
    if (part == null)
        return false;
    ArrayList<KeyValuePair<ISpellPart, byte[]>> currentShapeGroupList = getShapeGroupToAddTo();
    if (part instanceof Summon)
        handleSummonShape();
    if (part instanceof Binding)
        handleBindingShape();
    byte[] metaData = new byte[0];
    if (part instanceof ISpellModifier) {
        metaData = ((ISpellModifier) part).getModifierMetadata(currentAddedItems.toArray(new ItemStack[currentAddedItems.size()]));
        if (metaData == null) {
            metaData = new byte[0];
        }
    }
    // we're now creating the body of the spell
    if (currentShapeGroupList == null) {
        spellDef.add(new KeyValuePair<ISpellPart, byte[]>(part, metaData));
    } else {
        currentShapeGroupList.add(new KeyValuePair<ISpellPart, byte[]>(part, metaData));
    }
    return true;
}
Also used : Binding(am2.spell.shapes.Binding) KeyValuePair(am2.utility.KeyValuePair) Summon(am2.spell.components.Summon) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellPart(am2.api.spell.component.interfaces.ISpellPart)

Example 5 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart in project ArsMagica2 by Mithion.

the class TileEntityInscriptionTable method countModifiersInList.

private void countModifiersInList(ArrayList<ISpellPart> currentStage) {
    for (ISpellPart part : currentStage) {
        if (part instanceof ISpellModifier) {
            EnumSet<SpellModifiers> modifiers = ((ISpellModifier) part).getAspectsModified();
            for (SpellModifiers modifier : modifiers) {
                int count = modifierCount.get(modifier) + 1;
                modifierCount.put(modifier, count);
            }
        }
    }
}
Also used : SpellModifiers(am2.api.spell.enums.SpellModifiers)

Aggregations

ItemStack (net.minecraft.item.ItemStack)8 KeyValuePair (am2.utility.KeyValuePair)7 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)6 ArrayList (java.util.ArrayList)5 Block (net.minecraft.block.Block)4 Item (net.minecraft.item.Item)4 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)3 AMDataWriter (am2.network.AMDataWriter)3 Summon (am2.spell.components.Summon)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)2 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 AMVector3 (am2.api.math.AMVector3)1 IPowerNode (am2.api.power.IPowerNode)1 PowerTypes (am2.api.power.PowerTypes)1 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 Affinity (am2.api.spell.enums.Affinity)1 SpellModifiers (am2.api.spell.enums.SpellModifiers)1