Search in sources :

Example 6 with ISpellPart

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

the class TileEntityInscriptionTable method GetUpdatePacketForServer.

private byte[] GetUpdatePacketForServer() {
    AMDataWriter writer = new AMDataWriter();
    writer.add(FULL_UPDATE);
    writer.add(this.currentPlayerUsing == null);
    if (this.currentPlayerUsing != null)
        writer.add(this.currentPlayerUsing.getEntityId());
    writer.add(this.currentRecipe.size());
    for (int i = 0; i < this.currentRecipe.size(); ++i) {
        ISpellPart part = this.currentRecipe.get(i);
        int id = part.getID();
        if (part instanceof ISpellComponent)
            id += SkillManager.COMPONENT_OFFSET;
        else if (part instanceof ISpellModifier)
            id += SkillManager.MODIFIER_OFFSET;
        writer.add(id);
    }
    writer.add(this.shapeGroups.size());
    for (ArrayList<ISpellPart> shapeGroup : this.shapeGroups) {
        int[] groupData = new int[shapeGroup.size()];
        for (int i = 0; i < shapeGroup.size(); ++i) {
            groupData[i] = SkillManager.instance.getShiftedPartID(shapeGroup.get(i));
        }
        writer.add(groupData);
    }
    writer.add(currentSpellName);
    writer.add(currentSpellIsReadOnly);
    return writer.generate();
}
Also used : AMDataWriter(am2.network.AMDataWriter)

Example 7 with ISpellPart

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

the class GuiArcaneCompendium method getAndAnalyzeRecipe.

private void getAndAnalyzeRecipe() {
    if (renderStack == null)
        return;
    if (renderStack.getItem() == ItemsCommonProxy.essence || renderStack.getItem() == ItemsCommonProxy.deficitCrystal) {
        RecipeArsMagica essenceRecipe = RecipesEssenceRefiner.essenceRefinement().recipeFor(renderStack);
        if (essenceRecipe != null) {
            craftingComponents = essenceRecipe.getRecipeItems();
            recipeHeight = 2;
        } else {
            craftingComponents = null;
        }
    } else if (renderStack.getItem() instanceof ItemSpellPart) {
        ISkillTreeEntry part = SkillManager.instance.getSkill(this.entryName);
        if (part == null)
            return;
        ArrayList<Object> recipe = new ArrayList<Object>();
        if (part instanceof ISpellPart) {
            Object[] recipeItems = ((ISpellPart) part).getRecipeItems();
            SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipeItems);
            MinecraftForge.EVENT_BUS.post(event);
            recipeItems = event.recipeItems;
            if (recipeItems != null) {
                for (int i = 0; i < recipeItems.length; ++i) {
                    Object o = recipeItems[i];
                    boolean matches = false;
                    if (o instanceof ItemStack) {
                        recipe.add(o);
                    } else if (o instanceof Item) {
                        recipe.add(new ItemStack((Item) o));
                    } else if (o instanceof Block) {
                        recipe.add(new ItemStack((Block) o));
                    } else if (o instanceof String) {
                        if (((String) o).startsWith("P:")) {
                            // potion
                            String s = ((String) o).substring(2);
                            int pfx = SpellRecipeManager.parsePotionMeta(s);
                            recipe.add(new ItemStack(Items.potionitem, 1, pfx));
                        } else if (((String) o).startsWith("E:")) {
                            // essence
                            String s = ((String) o);
                            try {
                                int[] types = SpellRecipeManager.ParseEssenceIDs(s);
                                int type = 0;
                                for (int t : types) type |= t;
                                int amount = (Integer) recipeItems[++i];
                                recipe.add(new ItemStack(ItemsCommonProxy.essence, amount, ItemsCommonProxy.essence.META_MAX + type));
                            } catch (Throwable t) {
                                continue;
                            }
                        } else {
                            recipe.add(OreDictionary.getOres((String) o));
                        }
                    }
                }
            }
        }
        craftingComponents = recipe.toArray();
    } else {
        IRecipe recipe = RecipeUtilities.getRecipeFor(renderStack);
        if (recipe != null) {
            renderStack = recipe.getRecipeOutput();
            if (recipe instanceof ShapedRecipes) {
                recipeWidth = ((ShapedRecipes) recipe).recipeWidth;
                recipeHeight = ((ShapedRecipes) recipe).recipeHeight;
                craftingComponents = ((ShapedRecipes) recipe).recipeItems;
            } else if (recipe instanceof ShapedOreRecipe) {
                recipeWidth = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "width");
                recipeHeight = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "height");
                craftingComponents = ((ShapedOreRecipe) recipe).getInput();
            } else if (recipe instanceof ShapelessRecipes) {
                recipeWidth = ((ShapelessRecipes) recipe).getRecipeSize();
                recipeHeight = -1;
                craftingComponents = ((ShapelessRecipes) recipe).recipeItems.toArray();
            } else if (recipe instanceof ShapelessOreRecipe) {
                recipeWidth = ((ShapelessOreRecipe) recipe).getRecipeSize();
                recipeHeight = -1;
                craftingComponents = ((ShapelessOreRecipe) recipe).getInput().toArray();
            } else {
                craftingComponents = null;
            }
        } else {
            craftingComponents = null;
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ItemSpellPart(am2.items.ItemSpellPart) ISpellPart(am2.api.spell.component.interfaces.ISpellPart) RecipeArsMagica(am2.items.RecipeArsMagica) Item(net.minecraft.item.Item) RenderItem(net.minecraft.client.renderer.entity.RenderItem) SpellRecipeItemsEvent(am2.api.events.SpellRecipeItemsEvent) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 8 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart 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 9 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart 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 10 with ISpellPart

use of am2.api.spell.component.interfaces.ISpellPart 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

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