Search in sources :

Example 1 with KeyValuePair

use of am2.utility.KeyValuePair 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 2 with KeyValuePair

use of am2.utility.KeyValuePair 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 3 with KeyValuePair

use of am2.utility.KeyValuePair in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    NBTTagCompound altarCompound = new NBTTagCompound();
    altarCompound.setBoolean("isCrafting", this.isCrafting);
    altarCompound.setInteger("currentKey", this.currentKey);
    altarCompound.setString("currentSpellName", currentSpellName);
    NBTTagList allAddedItemsList = new NBTTagList();
    for (ItemStack stack : allAddedItems) {
        NBTTagCompound addedItem = new NBTTagCompound();
        stack.writeToNBT(addedItem);
        allAddedItemsList.appendTag(addedItem);
    }
    altarCompound.setTag("allAddedItems", allAddedItemsList);
    NBTTagList currentAddedItemsList = new NBTTagList();
    for (ItemStack stack : currentAddedItems) {
        NBTTagCompound addedItem = new NBTTagCompound();
        stack.writeToNBT(addedItem);
        currentAddedItemsList.appendTag(addedItem);
    }
    altarCompound.setTag("currentAddedItems", currentAddedItemsList);
    if (addedPhylactery != null) {
        NBTTagCompound phylactery = new NBTTagCompound();
        addedPhylactery.writeToNBT(phylactery);
        altarCompound.setTag("phylactery", phylactery);
    }
    if (addedBindingCatalyst != null) {
        NBTTagCompound catalyst = new NBTTagCompound();
        addedBindingCatalyst.writeToNBT(catalyst);
        altarCompound.setTag("catalyst", catalyst);
    }
    NBTTagList shapeGroupData = new NBTTagList();
    for (ArrayList<KeyValuePair<ISpellPart, byte[]>> list : shapeGroups) {
        shapeGroupData.appendTag(ISpellPartListToNBT(list));
    }
    altarCompound.setTag("shapeGroups", shapeGroupData);
    NBTTagCompound spellDefSave = ISpellPartListToNBT(this.spellDef);
    altarCompound.setTag("spellDef", spellDefSave);
    nbttagcompound.setTag("altarData", altarCompound);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) KeyValuePair(am2.utility.KeyValuePair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 4 with KeyValuePair

use of am2.utility.KeyValuePair in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    if (!nbttagcompound.hasKey("altarData"))
        return;
    NBTTagCompound altarCompound = nbttagcompound.getCompoundTag("altarData");
    NBTTagList allAddedItems = altarCompound.getTagList("allAddedItems", Constants.NBT.TAG_COMPOUND);
    NBTTagList currentAddedItems = altarCompound.getTagList("currentAddedItems", Constants.NBT.TAG_COMPOUND);
    this.isCrafting = altarCompound.getBoolean("isCrafting");
    this.currentKey = altarCompound.getInteger("currentKey");
    this.currentSpellName = altarCompound.getString("currentSpellName");
    if (altarCompound.hasKey("phylactery")) {
        NBTTagCompound phylactery = altarCompound.getCompoundTag("phylactery");
        if (phylactery != null)
            this.addedPhylactery = ItemStack.loadItemStackFromNBT(phylactery);
    }
    if (altarCompound.hasKey("catalyst")) {
        NBTTagCompound catalyst = altarCompound.getCompoundTag("catalyst");
        if (catalyst != null)
            this.addedBindingCatalyst = ItemStack.loadItemStackFromNBT(catalyst);
    }
    this.allAddedItems.clear();
    for (int i = 0; i < allAddedItems.tagCount(); ++i) {
        NBTTagCompound addedItem = (NBTTagCompound) allAddedItems.getCompoundTagAt(i);
        if (addedItem == null)
            continue;
        ItemStack stack = ItemStack.loadItemStackFromNBT(addedItem);
        if (stack == null)
            continue;
        this.allAddedItems.add(stack);
    }
    this.currentAddedItems.clear();
    for (int i = 0; i < currentAddedItems.tagCount(); ++i) {
        NBTTagCompound addedItem = (NBTTagCompound) currentAddedItems.getCompoundTagAt(i);
        if (addedItem == null)
            continue;
        ItemStack stack = ItemStack.loadItemStackFromNBT(addedItem);
        if (stack == null)
            continue;
        this.currentAddedItems.add(stack);
    }
    this.spellDef.clear();
    for (ArrayList<KeyValuePair<ISpellPart, byte[]>> groups : shapeGroups) groups.clear();
    NBTTagCompound currentSpellDef = altarCompound.getCompoundTag("spellDef");
    this.spellDef.addAll(NBTToISpellPartList(currentSpellDef));
    NBTTagList currentShapeGroups = altarCompound.getTagList("shapeGroups", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < currentShapeGroups.tagCount(); ++i) {
        NBTTagCompound compound = (NBTTagCompound) currentShapeGroups.getCompoundTagAt(i);
        shapeGroups.get(i).addAll(NBTToISpellPartList(compound));
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) KeyValuePair(am2.utility.KeyValuePair) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 5 with KeyValuePair

use of am2.utility.KeyValuePair in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method NBTToISpellPartList.

private ArrayList<KeyValuePair<ISpellPart, byte[]>> NBTToISpellPartList(NBTTagCompound compound) {
    int[] ids = compound.getIntArray("group_ids");
    ArrayList<KeyValuePair<ISpellPart, byte[]>> list = new ArrayList<KeyValuePair<ISpellPart, byte[]>>();
    for (int i = 0; i < ids.length; ++i) {
        int partID = ids[i];
        ISkillTreeEntry part = SkillManager.instance.getSkill(i);
        byte[] partMeta = compound.getByteArray("meta_" + i);
        if (part instanceof ISpellPart) {
            list.add(new KeyValuePair<ISpellPart, byte[]>((ISpellPart) part, partMeta));
        }
    }
    return list;
}
Also used : KeyValuePair(am2.utility.KeyValuePair) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) ArrayList(java.util.ArrayList) ISpellPart(am2.api.spell.component.interfaces.ISpellPart)

Aggregations

KeyValuePair (am2.utility.KeyValuePair)8 ItemStack (net.minecraft.item.ItemStack)4 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)2 AMDataWriter (am2.network.AMDataWriter)2 Summon (am2.spell.components.Summon)2 ArrayList (java.util.ArrayList)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 AMVector3 (am2.api.math.AMVector3)1 IPowerNode (am2.api.power.IPowerNode)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 Binding (am2.spell.shapes.Binding)1