Search in sources :

Example 1 with ModuleInstanceModifier

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier 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 ModuleInstanceModifier

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier 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 ModuleInstanceModifier

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

the class CommonWorktableModule method serializeNBT.

@Override
public NBTTagCompound serializeNBT() {
    NBTTagCompound compound = new NBTTagCompound();
    if (hash != -1) {
        compound.setInteger("hash", hash);
    }
    if (module != null)
        compound.setString("module", module.getNBTKey());
    if (pos != null) {
        compound.setDouble("x", pos.getX());
        compound.setDouble("y", pos.getY());
    }
    if (linksTo != null)
        compound.setTag("linksTo", linksTo.serializeNBT());
    NBTTagCompound modifierNBT = new NBTTagCompound();
    for (ModuleInstanceModifier modifier : modifiers.keySet()) {
        int count = modifiers.get(modifier);
        modifierNBT.setInteger(modifier.getNBTKey(), count);
    }
    compound.setTag("modifiers", modifierNBT);
    return compound;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)

Example 4 with ModuleInstanceModifier

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

the class WorktableGui method load.

public void load() {
    TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(pos);
    if (tile instanceof TileMagiciansWorktable) {
        if (((TileMagiciansWorktable) tile).commonModules != null) {
            Set<CommonWorktableModule> commonModules = ((TileMagiciansWorktable) tile).getCommonModules();
            for (CommonWorktableModule commonHead : commonModules) {
                if (commonHead != null) {
                    // ADDED HERE
                    CommonWorktableModule commonModule = commonHead;
                    TableModule lastModule = new TableModule(this, commonHead.module, true, false);
                    lastModule.setPos(commonHead.pos);
                    while (commonModule != null) {
                        lastModule.radius = 10;
                        lastModule.textRadius = 0;
                        paper.add(lastModule);
                        DragMixin drag = new DragMixin(lastModule, vec2d -> vec2d);
                        drag.setDragOffset(new Vec2d(6, 6));
                        for (ModuleInstanceModifier modifier : commonModule.modifiers.keySet()) {
                            lastModule.setData(Integer.class, modifier.getNBTKey(), commonModule.modifiers.get(modifier));
                        }
                        if (commonModule.linksTo != null) {
                            if (commonModule.linksTo.module != null) {
                                TableModule childModule = new TableModule(this, commonModule.linksTo.module, true, false);
                                childModule.setPos(commonModule.linksTo.pos);
                                lastModule.setLinksTo(childModule);
                                lastModule = childModule;
                            } else {
                                // If a module was removed from the mod, try and clear the table.
                                // This doesn't clear the whole table, but it's good enough.
                                ((TileMagiciansWorktable) tile).setCommonModules(new NBTTagList());
                                syncToServer();
                                Minecraft.getMinecraft().player.sendMessage(new TextComponentString(TextFormatting.RED + "wizardry.table.no_component_error"));
                                return;
                            }
                        }
                        commonModule = commonModule.linksTo;
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) TileMagiciansWorktable(com.teamwizardry.wizardry.common.tile.TileMagiciansWorktable) CommonWorktableModule(com.teamwizardry.wizardry.api.spell.CommonWorktableModule) DragMixin(com.teamwizardry.librarianlib.features.gui.mixin.DragMixin) Vec2d(com.teamwizardry.librarianlib.features.math.Vec2d) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 5 with ModuleInstanceModifier

use of com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier 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)

Aggregations

ModuleInstanceModifier (com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)10 ModuleInstance (com.teamwizardry.wizardry.api.spell.module.ModuleInstance)7 Vec2d (com.teamwizardry.librarianlib.features.math.Vec2d)5 CommonWorktableModule (com.teamwizardry.wizardry.api.spell.CommonWorktableModule)3 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 DragMixin (com.teamwizardry.librarianlib.features.gui.mixin.DragMixin)2 AttributeModifier (com.teamwizardry.wizardry.api.spell.attribute.AttributeModifier)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 LibrarianLib (com.teamwizardry.librarianlib.core.LibrarianLib)1 Easing (com.teamwizardry.librarianlib.features.animator.Easing)1 EnumMouseButton (com.teamwizardry.librarianlib.features.gui.EnumMouseButton)1 ComponentSprite (com.teamwizardry.librarianlib.features.gui.components.ComponentSprite)1