Search in sources :

Example 1 with ModuleInstance

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.

the class SpellBuilder method toSpell.

private List<SpellRing> toSpell(List<ItemStack> inventory, double constructorFriendlyThing) {
    List<SpellRing> spellList = new ArrayList<>();
    Set<List<SpellRing>> spellChains = new HashSet<>();
    List<List<ItemStack>> lines = brancher(inventory, SpellUtils.CODE_LINE_BREAK);
    // Spell chain from multiple chains
    for (List<ItemStack> line : lines) {
        // List is made of all modules that aren't modifiers for this spellData chain.
        Deque<SpellRing> uncompressedChain = new ArrayDeque<>();
        // Step through each item in line. If modifier, add to lastModule, if not, add to compiled.
        for (ItemStack stack : line) {
            ModuleInstance module = ModuleRegistry.INSTANCE.getModule(stack);
            if (module == null)
                continue;
            if (module instanceof ModuleInstanceModifier) {
                if (!uncompressedChain.isEmpty()) {
                    for (int i = 0; i < stack.getCount(); i++) {
                        SpellRing lastRing = uncompressedChain.peekLast();
                        lastRing.addModifier((ModuleInstanceModifier) module);
                    }
                }
            } else {
                for (int i = 0; i < stack.getCount(); i++) {
                    SpellRing ring = new SpellRing(module);
                    uncompressedChain.add(ring);
                }
            }
        }
        spellChains.add(new ArrayList<>(uncompressedChain));
    }
    // We now have a code line of modules. link them as children in order.
    for (List<SpellRing> rings : spellChains) {
        if (rings.isEmpty())
            continue;
        Deque<SpellRing> deque = new ArrayDeque<>(rings);
        SpellRing ringHead = deque.pop();
        SpellRing lastRing = ringHead;
        while (!deque.isEmpty()) {
            SpellRing child = deque.pop();
            lastRing.setChildRing(child);
            child.setParentRing(lastRing);
            lastRing = child;
        }
        spellList.add(ringHead);
    }
    for (SpellRing ring : spellList) {
        SpellRing chainEnd = ring;
        while (chainEnd != null) {
            if (chainEnd.getChildRing() == null) {
                if (chainEnd.getModule() != null) {
                    chainEnd.setPrimaryColor(chainEnd.getModule().getPrimaryColor());
                    chainEnd.setSecondaryColor(chainEnd.getModule().getSecondaryColor());
                }
                chainEnd.updateColorChain();
            }
            chainEnd.processModifiers();
            chainEnd = chainEnd.getChildRing();
        }
    }
    return spellList;
}
Also used : ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier) ItemStack(net.minecraft.item.ItemStack) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance)

Example 2 with ModuleInstance

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.

the class CommonWorktableModule method deserializeNBT.

@Override
public void deserializeNBT(NBTTagCompound nbt) {
    if (nbt.hasKey("module")) {
        module = ModuleInstance.deserialize(nbt.getString("module"));
    }
    if (nbt.hasKey("x") && nbt.hasKey("y")) {
        pos = new Vec2d(nbt.getDouble("x"), nbt.getDouble("y"));
    }
    if (nbt.hasKey("linksTo")) {
        linksTo = deserailize(nbt.getCompoundTag("linksTo"));
    }
    if (nbt.hasKey("modifiers")) {
        modifiers = new HashMap<>();
        for (String base : nbt.getCompoundTag("modifiers").getKeySet()) {
            ModuleInstance module = ModuleRegistry.INSTANCE.getModule(base);
            if (!(module instanceof ModuleInstanceModifier))
                continue;
            int count = nbt.getCompoundTag("modifiers").getInteger(base);
            modifiers.put((ModuleInstanceModifier) module, count);
        }
    }
    if (nbt.hasKey("hash")) {
        hash = nbt.getInteger("hash");
    }
}
Also used : Vec2d(com.teamwizardry.librarianlib.features.math.Vec2d) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)

Example 3 with ModuleInstance

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.

the class WorktableGui method getSpellName.

public String getSpellName() {
    List<List<ModuleInstance>> chains = new ArrayList<>();
    for (TableModule head : getSpellHeads()) {
        List<ModuleInstance> chain = new ArrayList<>();
        TableModule lastModule = head;
        while (lastModule != null) {
            chain.add(lastModule.getModule());
            for (ModuleInstance module : ModuleRegistry.INSTANCE.getModules(ModuleType.MODIFIER)) {
                if (!(module instanceof ModuleInstanceModifier))
                    continue;
                if (!lastModule.hasData(Integer.class, module.getNBTKey()))
                    continue;
                int count = lastModule.getData(Integer.class, module.getNBTKey());
                for (int i = 0; i < count; i++) {
                    chain.add(module);
                }
            }
            lastModule = lastModule.getLinksTo();
        }
        chains.add(chain);
    }
    SpellBuilder builder = new SpellBuilder(SpellUtils.getSpellItems(chains));
    StringBuilder spellNameBuilder = new StringBuilder();
    SpellRing lastRing = null;
    for (SpellRing ring : builder.getSpell()) {
        if (lastRing == null)
            lastRing = ring;
        if (ring != null) {
            if (ring != lastRing)
                spellNameBuilder.append(TextFormatting.GRAY).append(" | ");
            SpellRing tmpRing = ring;
            while (tmpRing != null) {
                spellNameBuilder.append(TextFormatting.YELLOW).append(tmpRing.getModuleReadableName()).append(TextFormatting.GRAY).append("(").append(TextFormatting.BLUE).append(Math.round(tmpRing.getManaDrain(null) * tmpRing.getManaMultiplier())).append(TextFormatting.GRAY).append("/").append(TextFormatting.RED).append(Math.round(tmpRing.getBurnoutFill(null) * tmpRing.getBurnoutMultiplier())).append(TextFormatting.GRAY).append(")");
                tmpRing = tmpRing.getChildRing();
                if (tmpRing != null) {
                    spellNameBuilder.append(TextFormatting.GRAY).append(" > ");
                }
            }
        }
    }
    return spellNameBuilder.toString();
}
Also used : SpellRing(com.teamwizardry.wizardry.api.spell.SpellRing) SpellBuilder(com.teamwizardry.wizardry.api.spell.SpellBuilder) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)

Example 4 with ModuleInstance

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.

the class CommandListModules method execute.

@Override
public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, @NotNull String[] args) {
    notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
    notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module List");
    for (ModuleInstance module : ModuleRegistry.INSTANCE.modules) notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + module.getNBTKey() + TextFormatting.RESET + ": " + TextFormatting.GRAY + module.getReadableName());
    notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
}
Also used : ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance)

Example 5 with ModuleInstance

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstance in project Wizardry by TeamWizardry.

the class SpellUtils method deserializeModuleList.

public static List<List<ModuleInstance>> deserializeModuleList(@Nonnull NBTTagList list) {
    List<List<ModuleInstance>> modules = new ArrayList<>();
    List<ModuleInstance> moduleList = new ArrayList<>();
    for (int i = 0; i < list.tagCount(); i++) {
        NBTBase base = list.get(i);
        if (!(base instanceof NBTTagString))
            continue;
        NBTTagString string = (NBTTagString) base;
        if (string.isEmpty()) {
            if (!moduleList.isEmpty())
                modules.add(moduleList);
            moduleList = new ArrayList<>();
        }
        ModuleInstance module = ModuleInstance.deserialize(string);
        if (module == null)
            continue;
        moduleList.add(module);
    }
    if (!moduleList.isEmpty())
        modules.add(moduleList);
    return modules;
}
Also used : NBTBase(net.minecraft.nbt.NBTBase) ArrayList(java.util.ArrayList) NBTTagString(net.minecraft.nbt.NBTTagString) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance)

Aggregations

ModuleInstance (com.teamwizardry.wizardry.api.spell.module.ModuleInstance)15 ModuleInstanceModifier (com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)7 Vec2d (com.teamwizardry.librarianlib.features.math.Vec2d)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ItemStack (net.minecraft.item.ItemStack)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 FontRenderer (net.minecraft.client.gui.FontRenderer)3 LibrarianLib (com.teamwizardry.librarianlib.core.LibrarianLib)2 BasicAnimation (com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation)2 Keyframe (com.teamwizardry.librarianlib.features.animator.animations.Keyframe)2 KeyframeAnimation (com.teamwizardry.librarianlib.features.animator.animations.KeyframeAnimation)2 ScheduledEventAnimation (com.teamwizardry.librarianlib.features.animator.animations.ScheduledEventAnimation)2 GuiComponent (com.teamwizardry.librarianlib.features.gui.component.GuiComponent)2 GuiComponentEvents (com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents)2 ComponentRect (com.teamwizardry.librarianlib.features.gui.components.ComponentRect)2 ComponentSprite (com.teamwizardry.librarianlib.features.gui.components.ComponentSprite)2 ComponentText (com.teamwizardry.librarianlib.features.gui.components.ComponentText)2 ComponentVoid (com.teamwizardry.librarianlib.features.gui.components.ComponentVoid)2 Sprite (com.teamwizardry.librarianlib.features.sprite.Sprite)2