Search in sources :

Example 6 with PowerTypes

use of am2.api.power.PowerTypes in project ArsMagica2 by Mithion.

the class ClientProxy method drawPowerOnBlockHighlight.

@Override
public void drawPowerOnBlockHighlight(EntityPlayer player, MovingObjectPosition target, float partialTicks) {
    if (AMCore.proxy.getLocalPlayer().getCurrentArmor(3) != null && (AMCore.proxy.getLocalPlayer().getCurrentArmor(3).getItem() == ItemsCommonProxy.magitechGoggles || ArmorHelper.isInfusionPreset(AMCore.proxy.getLocalPlayer().getCurrentArmor(3), GenericImbuement.magitechGoggleIntegration))) {
        TileEntity te = player.worldObj.getTileEntity(target.blockX, target.blockY, target.blockZ);
        if (te != null && te instanceof IPowerNode) {
            AMCore.proxy.setTrackedLocation(new AMVector3(target.blockX, target.blockY, target.blockZ));
        } else {
            AMCore.proxy.setTrackedLocation(AMVector3.zero());
        }
        if (AMCore.proxy.hasTrackedLocationSynced()) {
            PowerNodeEntry data = AMCore.proxy.getTrackedData();
            Block block = player.worldObj.getBlock(target.blockX, target.blockY, target.blockZ);
            float yOff = 0.5f;
            if (data != null) {
                GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
                for (PowerTypes type : ((IPowerNode) te).getValidPowerTypes()) {
                    float pwr = data.getPower(type);
                    float pct = pwr / ((IPowerNode) te).getCapacity() * 100;
                    RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), target.blockX - (player.prevPosX - (player.prevPosX - player.posX) * partialTicks) + 0.5f, target.blockY + yOff - (player.prevPosY - (player.prevPosY - player.posY) * partialTicks) + block.getBlockBoundsMaxY() * 0.8f, target.blockZ - (player.prevPosZ - (player.prevPosZ - player.posZ) * partialTicks) + 0.5f, 0xFFFFFF);
                    yOff += 0.12f;
                }
                GL11.glPopAttrib();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) Block(net.minecraft.block.Block) PowerNodeEntry(am2.power.PowerNodeEntry) IPowerNode(am2.api.power.IPowerNode)

Example 7 with PowerTypes

use of am2.api.power.PowerTypes in project ArsMagica2 by Mithion.

the class TileEntityAMPower method updateEntity.

@Override
public void updateEntity() {
    if (!worldObj.isRemote && this.canRequestPower() && tickCounter++ >= getRequestInterval()) {
        tickCounter = 0;
        PowerTypes[] powerTypes = this.getValidPowerTypes();
        for (PowerTypes type : powerTypes) {
            float amtObtained = PowerNodeRegistry.For(worldObj).requestPower(this, type, this.getChargeRate());
            if (amtObtained > 0)
                PowerNodeRegistry.For(worldObj).insertPower(this, type, amtObtained);
        }
    }
}
Also used : PowerTypes(am2.api.power.PowerTypes)

Example 8 with PowerTypes

use of am2.api.power.PowerTypes in project ArsMagica2 by Mithion.

the class TileEntityInscriptionTable method writeRecipeAndDataToBook.

public ItemStack writeRecipeAndDataToBook(ItemStack bookstack, EntityPlayer player, String title) {
    if (bookstack.getItem() == Items.written_book && this.currentRecipe != null) {
        if (!currentRecipeIsValid().valid)
            return bookstack;
        if (!bookstack.hasTagCompound())
            bookstack.setTagCompound(new NBTTagCompound());
        else if (//don't overwrite a completed spell
        bookstack.getTagCompound().getBoolean("spellFinalized"))
            return bookstack;
        LinkedHashMap<String, Integer> materialsList = new LinkedHashMap<String, Integer>();
        materialsList.put(ItemsCommonProxy.rune.getItemStackDisplayName(new ItemStack(ItemsCommonProxy.rune, 1, ItemsCommonProxy.rune.META_BLANK)), 1);
        ArrayList<ItemStack> componentRecipeList = new ArrayList<ItemStack>();
        int count = 0;
        ArrayList<ISpellPart> allRecipeItems = new ArrayList<ISpellPart>();
        for (ArrayList<ISpellPart> shapeGroup : shapeGroups) {
            if (shapeGroup == null || shapeGroup.size() == 0)
                continue;
            allRecipeItems.addAll(shapeGroup);
        }
        allRecipeItems.addAll(currentRecipe);
        for (ISpellPart part : allRecipeItems) {
            if (part == null) {
                LogHelper.error("Unable to write recipe to book.  Recipe part is null!");
                return bookstack;
            }
            Object[] recipeItems = 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) {
                LogHelper.error("Unable to write recipe to book.  Recipe items are null for part %d!", part.getID());
                return bookstack;
            }
            for (int i = 0; i < recipeItems.length; ++i) {
                Object o = recipeItems[i];
                String materialkey = "";
                int qty = 1;
                ItemStack recipeStack = null;
                if (o instanceof ItemStack) {
                    materialkey = ((ItemStack) o).getDisplayName();
                    recipeStack = (ItemStack) o;
                } else if (o instanceof Item) {
                    recipeStack = new ItemStack((Item) o);
                    materialkey = ((Item) o).getItemStackDisplayName(new ItemStack((Item) o));
                } else if (o instanceof Block) {
                    recipeStack = new ItemStack((Block) o);
                    materialkey = ((Block) o).getLocalizedName();
                } else if (o instanceof String) {
                    if (((String) o).startsWith("P:")) {
                        String s = ((String) o).substring(2);
                        int pfx = SpellRecipeManager.parsePotionMeta(s);
                        recipeStack = new ItemStack(Items.potionitem, 1, pfx);
                        materialkey = recipeStack.getDisplayName();
                    } else if (((String) o).startsWith("E:")) {
                        int[] ids = SpellRecipeManager.ParseEssenceIDs((String) o);
                        materialkey = "Essence (";
                        for (int powerID : ids) {
                            PowerTypes type = PowerTypes.getByID(powerID);
                            materialkey += type.name() + "/";
                        }
                        if (materialkey.equals("Essence (")) {
                            ++i;
                            continue;
                        }
                        o = recipeItems[++i];
                        if (materialkey.startsWith("Essence (")) {
                            materialkey = materialkey.substring(0, materialkey.lastIndexOf("/")) + ")";
                            qty = (Integer) o;
                            int flag = 0;
                            for (int f : ids) {
                                flag |= f;
                            }
                            recipeStack = new ItemStack(ItemsCommonProxy.essence, qty, ItemsCommonProxy.essence.META_MAX + flag);
                        }
                    } else {
                        ArrayList<ItemStack> ores = OreDictionary.getOres((String) o);
                        recipeStack = ores.size() > 0 ? ores.get(1) : null;
                        materialkey = (String) o;
                    }
                }
                if (materialsList.containsKey(materialkey)) {
                    int old = materialsList.get(materialkey);
                    old += qty;
                    materialsList.put(materialkey, old);
                } else {
                    materialsList.put(materialkey, qty);
                }
                if (recipeStack != null)
                    componentRecipeList.add(recipeStack);
            }
        }
        materialsList.put(ItemsCommonProxy.spellParchment.getItemStackDisplayName(new ItemStack(ItemsCommonProxy.spellParchment)), 1);
        StringBuilder sb = new StringBuilder();
        int sgCount = 0;
        int[][] shapeGroupCombos = new int[shapeGroups.size()][];
        for (ArrayList<ISpellPart> shapeGroup : shapeGroups) {
            sb.append("Shape Group " + ++sgCount + "\n\n");
            Iterator<ISpellPart> it = shapeGroup.iterator();
            shapeGroupCombos[sgCount - 1] = SpellPartListToStringBuilder(it, sb, " -");
            sb.append("\n");
        }
        sb.append("Combination:\n\n");
        Iterator<ISpellPart> it = currentRecipe.iterator();
        ArrayList<Integer> outputCombo = new ArrayList<Integer>();
        int[] outputData = SpellPartListToStringBuilder(it, sb, null);
        ArrayList<NBTTagString> pages = Story.splitStoryPartIntoPages(sb.toString());
        sb = new StringBuilder();
        sb.append("\n\nMaterials List:\n\n");
        for (String s : materialsList.keySet()) {
            sb.append(materialsList.get(s) + " x " + s + "\n");
        }
        pages.addAll(Story.splitStoryPartIntoPages(sb.toString()));
        sb = new StringBuilder();
        sb.append("Affinity Breakdown:\n\n");
        it = currentRecipe.iterator();
        HashMap<Affinity, Integer> affinityData = new HashMap<Affinity, Integer>();
        int cpCount = 0;
        while (it.hasNext()) {
            ISpellPart part = it.next();
            if (part instanceof ISpellComponent) {
                EnumSet<Affinity> aff = ((ISpellComponent) part).getAffinity();
                for (Affinity affinity : aff) {
                    int qty = 1;
                    if (affinityData.containsKey(affinity)) {
                        qty = 1 + affinityData.get(affinity);
                    }
                    affinityData.put(affinity, qty);
                }
                cpCount++;
            }
        }
        ValueComparator vc = new ValueComparator(affinityData);
        TreeMap<Affinity, Integer> sorted = new TreeMap<Affinity, Integer>(vc);
        sorted.putAll(affinityData);
        for (Affinity aff : sorted.keySet()) {
            float pct = (float) sorted.get(aff) / (float) cpCount * 100f;
            sb.append(String.format("%s: %.2f%%", aff.toString(), pct));
            sb.append("\n");
        }
        pages.addAll(Story.splitStoryPartIntoPages(sb.toString()));
        Story.WritePartToNBT(bookstack.stackTagCompound, pages);
        bookstack = Story.finalizeStory(bookstack, title, player.getCommandSenderName());
        int[] recipeData = new int[componentRecipeList.size() * 3];
        int idx = 0;
        for (ItemStack stack : componentRecipeList) {
            recipeData[idx++] = Item.getIdFromItem(stack.getItem());
            recipeData[idx++] = stack.stackSize;
            recipeData[idx++] = stack.getItemDamage();
        }
        bookstack.stackTagCompound.setIntArray("spell_combo", recipeData);
        bookstack.stackTagCompound.setIntArray("output_combo", outputData);
        bookstack.stackTagCompound.setInteger("numShapeGroups", shapeGroupCombos.length);
        int index = 0;
        for (int[] sgArray : shapeGroupCombos) {
            bookstack.stackTagCompound.setIntArray("shapeGroupCombo_" + index++, sgArray);
        }
        bookstack.stackTagCompound.setString("spell_mod_version", AMCore.instance.getVersion());
        if (currentSpellName.equals(""))
            currentSpellName = "Spell Recipe";
        bookstack.setStackDisplayName(currentSpellName);
        this.currentRecipe.clear();
        for (ArrayList<ISpellPart> list : shapeGroups) list.clear();
        currentSpellName = "";
        bookstack.stackTagCompound.setBoolean("spellFinalized", true);
        worldObj.playSound(xCoord, yCoord, zCoord, "arsmagica2:misc.inscriptiontable.takebook", 1.0f, 1.0f, true);
        worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
    }
    return bookstack;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) Item(net.minecraft.item.Item) PowerTypes(am2.api.power.PowerTypes) NBTTagString(net.minecraft.nbt.NBTTagString) SpellRecipeItemsEvent(am2.api.events.SpellRecipeItemsEvent) Block(net.minecraft.block.Block) Affinity(am2.api.spell.enums.Affinity) ItemStack(net.minecraft.item.ItemStack)

Example 9 with PowerTypes

use of am2.api.power.PowerTypes in project ArsMagica2 by Mithion.

the class TileEntityCraftingAltar method pickPowerType.

private void pickPowerType(ItemStack stack) {
    if (this.currentMainPowerTypes != PowerTypes.NONE)
        return;
    int flags = stack.getItemDamage() - ItemEssence.META_MAX;
    PowerTypes highestValid = PowerTypes.NONE;
    float amt = 0;
    for (PowerTypes type : PowerTypes.all()) {
        float tmpAmt = PowerNodeRegistry.For(worldObj).getPower(this, type);
        if (tmpAmt > amt)
            highestValid = type;
    }
    this.currentMainPowerTypes = highestValid;
}
Also used : PowerTypes(am2.api.power.PowerTypes)

Example 10 with PowerTypes

use of am2.api.power.PowerTypes in project ArsMagica2 by Mithion.

the class ItemEssence method getItemStackDisplayName.

@Override
public String getItemStackDisplayName(ItemStack stack) {
    int meta = stack.getItemDamage();
    switch(meta) {
        case 0:
            return StatCollector.translateToLocal("item.arsmagica2:arcaneEssence.name");
        case 1:
            return StatCollector.translateToLocal("item.arsmagica2:earthEssence.name");
        case 2:
            return StatCollector.translateToLocal("item.arsmagica2:airEssence.name");
        case 3:
            return StatCollector.translateToLocal("item.arsmagica2:fireEssence.name");
        case 4:
            return StatCollector.translateToLocal("item.arsmagica2:waterEssence.name");
        case 5:
            return StatCollector.translateToLocal("item.arsmagica2:plantEssence.name");
        case 6:
            return StatCollector.translateToLocal("item.arsmagica2:iceEssence.name");
        case 7:
            return StatCollector.translateToLocal("item.arsmagica2:lightningEssence.name");
        case 8:
            return StatCollector.translateToLocal("item.arsmagica2:lifeEssence.name");
        case 9:
            return StatCollector.translateToLocal("item.arsmagica2:enderEssence.name");
        case 10:
            return StatCollector.translateToLocal("item.arsmagica2:pureEssence.name");
        case 11:
            return StatCollector.translateToLocal("item.arsmagica2:highEssenceCore.name");
        case 12:
            return StatCollector.translateToLocal("item.arsmagica2:baseEssenceCore.name");
    }
    int mask = meta - META_MAX;
    String s = "";
    for (PowerTypes type : PowerTypes.all()) {
        if ((mask & type.ID()) == type.ID()) {
            if (s.equals(""))
                s = StatCollector.translateToLocal("item.arsmagica2:rawEssence.name") + " (" + type.name() + ")";
            else
                s += "\n" + StatCollector.translateToLocal("am2.gui.or") + StatCollector.translateToLocal("item.arsmagica2:rawEssence.name") + " (" + type.name() + ")";
        }
    }
    return s;
}
Also used : PowerTypes(am2.api.power.PowerTypes)

Aggregations

PowerTypes (am2.api.power.PowerTypes)15 AMVector3 (am2.api.math.AMVector3)8 IPowerNode (am2.api.power.IPowerNode)6 TileEntity (net.minecraft.tileentity.TileEntity)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 LinkedList (java.util.LinkedList)3 Block (net.minecraft.block.Block)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 PowerNodeEntry (am2.power.PowerNodeEntry)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 Affinity (am2.api.spell.enums.Affinity)1 TileEntityManaBattery (am2.blocks.tileentities.TileEntityManaBattery)1 EntityDummyCaster (am2.entities.EntityDummyCaster)1 AMLineArc (am2.particles.AMLineArc)1 EntityItem (net.minecraft.entity.item.EntityItem)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1