Search in sources :

Example 6 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 7 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)

Example 8 with KeyValuePair

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

the class TileEntityCraftingAltar method setCrafting.

private void setCrafting(boolean crafting) {
    this.isCrafting = crafting;
    if (!worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(xCoord);
        writer.add(yCoord);
        writer.add(zCoord);
        writer.add(CRAFTING_CHANGED);
        writer.add(crafting);
        AMNetHandler.INSTANCE.sendPacketToAllClientsNear(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32, AMPacketIDs.CRAFTING_ALTAR_DATA, writer.generate());
    }
    if (crafting) {
        allAddedItems.clear();
        currentAddedItems.clear();
        spellDef.clear();
        for (ArrayList<KeyValuePair<ISpellPart, byte[]>> groups : shapeGroups) groups.clear();
        //find otherworld auras
        IPowerNode[] nodes = PowerNodeRegistry.For(worldObj).getAllNearbyNodes(worldObj, new AMVector3(this), PowerTypes.DARK);
        for (IPowerNode node : nodes) {
            if (node instanceof TileEntityOtherworldAura) {
                ((TileEntityOtherworldAura) node).setActive(true, this);
                break;
            }
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) KeyValuePair(am2.utility.KeyValuePair) AMDataWriter(am2.network.AMDataWriter) IPowerNode(am2.api.power.IPowerNode)

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