Search in sources :

Example 11 with ISkillTreeEntry

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

the class TileEntityInscriptionTable method HandleUpdatePacket.

public void HandleUpdatePacket(byte[] data) {
    if (this.worldObj == null)
        return;
    AMDataReader rdr = new AMDataReader(data);
    switch(rdr.ID) {
        case FULL_UPDATE:
            if (!rdr.getBoolean()) {
                Entity e = this.worldObj.getEntityByID(rdr.getInt());
                if (e instanceof EntityPlayer) {
                    EntityPlayer player = (EntityPlayer) e;
                    this.setInUse(player);
                } else {
                    this.setInUse(null);
                }
            } else {
                this.setInUse(null);
            }
            currentRecipe.clear();
            int partLength = rdr.getInt();
            for (int i = 0; i < partLength; ++i) {
                ISkillTreeEntry part = SkillManager.instance.getSkill(rdr.getInt());
                if (part instanceof ISpellPart)
                    this.currentRecipe.add((ISpellPart) part);
            }
            this.shapeGroups.clear();
            int numGroups = rdr.getInt();
            for (int i = 0; i < numGroups; ++i) {
                ArrayList<ISpellPart> group = new ArrayList<ISpellPart>();
                int[] partData = rdr.getIntArray();
                for (int n : partData) {
                    ISkillTreeEntry part = SkillManager.instance.getSkill(n);
                    if (part instanceof ISpellPart)
                        group.add((ISpellPart) part);
                }
                this.shapeGroups.add(group);
            }
            countModifiers();
            this.currentSpellName = rdr.getString();
            this.currentSpellIsReadOnly = rdr.getBoolean();
            break;
        case MAKE_SPELL:
            int entityID = rdr.getInt();
            EntityPlayer player = (EntityPlayer) worldObj.getEntityByID(entityID);
            if (player != null) {
                createSpellForPlayer(player);
            }
            break;
        case RESET_NAME:
            entityID = rdr.getInt();
            player = (EntityPlayer) worldObj.getEntityByID(entityID);
            if (player != null) {
                ((ContainerInscriptionTable) player.openContainer).resetSpellNameAndIcon();
            }
            break;
    }
}
Also used : S35PacketUpdateTileEntity(net.minecraft.network.play.server.S35PacketUpdateTileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) ContainerInscriptionTable(am2.containers.ContainerInscriptionTable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AMDataReader(am2.network.AMDataReader)

Example 12 with ISkillTreeEntry

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

the class ItemSpellPart method registerIcons.

@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister IIconRegister) {
    ArrayList<Integer> parts = SkillManager.instance.getAllShapes();
    parts.addAll(SkillManager.instance.getAllComponents());
    parts.addAll(SkillManager.instance.getAllModifiers());
    parts.addAll(SkillManager.instance.getAllTalents());
    int count = 0;
    for (Integer i : parts) {
        if (i == null)
            continue;
        ISkillTreeEntry entry = SkillManager.instance.getSkill(i);
        String subfolder = "";
        if (entry instanceof ISpellShape)
            subfolder = "shapes";
        else if (entry instanceof ISpellComponent)
            subfolder = "components";
        else if (entry instanceof ISpellModifier)
            subfolder = "modifiers";
        else
            subfolder = "skills";
        String skillName = SkillManager.instance.getSkillName(entry);
        IIcon IIcon = ResourceManager.RegisterTexture(String.format("spells/%s/%s.png", subfolder, skillName), IIconRegister);
        SpellIconManager.instance.registerIcon(skillName, IIcon);
    }
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) IIcon(net.minecraft.util.IIcon) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) ISpellShape(am2.api.spell.component.interfaces.ISpellShape) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Example 13 with ISkillTreeEntry

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

the class GuiArcaneCompendium method renderItemToolTip.

private void renderItemToolTip(ItemStack stack, int x, int y) {
    try {
        List list = stack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
        CompendiumEntry entry;
        if (stack.getItem() instanceof ItemBlock) {
            ItemBlock item = (ItemBlock) stack.getItem();
            Block block = item.field_150939_a;
            String name = block.getUnlocalizedName().replace("arsmagica2:", "").replace("tile.", "");
            String metaname = name + "@" + stack.getItemDamage();
            entry = ArcaneCompendium.instance.getEntry(metaname);
            if (entry == null)
                entry = ArcaneCompendium.instance.getEntry(name);
        } else {
            if (stack.getItem() == ItemsCommonProxy.spell_component) {
                list.clear();
                ISkillTreeEntry skill = SkillManager.instance.getSkill(stack.getItemDamage());
                if (skill == null)
                    return;
                list.add(SkillManager.instance.getDisplayName(skill));
                entry = ArcaneCompendium.instance.getEntry(SkillManager.instance.getSkillName(skill));
            } else {
                String name = stack.getItem().getUnlocalizedName().replace("item.", "").replace("arsmagica2:", "");
                String metaname = name + "@" + stack.getItemDamage();
                entry = ArcaneCompendium.instance.getEntry(metaname);
                if (entry == null)
                    entry = ArcaneCompendium.instance.getEntry(name);
            }
        }
        for (int k = 0; k < list.size(); ++k) {
            if (k == 0) {
                if (entry != null) {
                    list.set(k, "§2" + (String) list.get(k));
                } else {
                    list.set(k, "§" + stack.getRarity().rarityColor.getFormattingCode() + (String) list.get(k));
                }
            } else {
                list.set(k, EnumChatFormatting.GRAY + (String) list.get(k));
            }
        }
        //split out multiline entries (only entry 0 in this case)
        if (((String) list.get(0)).indexOf('\n') != -1) {
            String s = ((String) list.get(0));
            String colorPrefix = "";
            list.remove(0);
            if (entry != null) {
                colorPrefix = "§2";
            } else {
                colorPrefix = "§" + stack.getRarity().rarityColor.getFormattingCode();
            }
            String[] split = s.split("\n");
            for (int i = split.length - 1; i >= 0; --i) {
                list.add(0, colorPrefix + split[i]);
            }
        }
        FontRenderer font = stack.getItem().getFontRenderer(stack);
        drawHoveringText(list, x, y, (font == null ? this.fontRendererObj : font));
    } catch (Throwable t) {
    }
}
Also used : ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) EntityList(net.minecraft.entity.EntityList) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemBlock(net.minecraft.item.ItemBlock)

Example 14 with ISkillTreeEntry

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

Aggregations

ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)12 SkillTreeEntry (am2.api.SkillTreeEntry)6 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)2 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)2 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)2 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)2 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 ArrayList (java.util.ArrayList)2 Block (net.minecraft.block.Block)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemBlock (net.minecraft.item.ItemBlock)2 MultiblockStructureDefinition (am2.api.blocks.MultiblockStructureDefinition)1 SkillLearnedEvent (am2.api.events.SkillLearnedEvent)1 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 IRitualInteraction (am2.api.spell.component.interfaces.IRitualInteraction)1 ContainerInscriptionTable (am2.containers.ContainerInscriptionTable)1 GuiArcaneCompendium (am2.guis.GuiArcaneCompendium)1 ItemSpellPart (am2.items.ItemSpellPart)1 RecipeArsMagica (am2.items.RecipeArsMagica)1 AMDataReader (am2.network.AMDataReader)1