Search in sources :

Example 1 with CommonWorktableModule

use of com.teamwizardry.wizardry.api.spell.CommonWorktableModule 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 2 with CommonWorktableModule

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

the class TileMagiciansWorktable method getCommonModules.

public Set<CommonWorktableModule> getCommonModules() {
    Set<CommonWorktableModule> commonModules = new HashSet<>();
    if (this.commonModules != null) {
        for (NBTBase base : this.commonModules) {
            if (base instanceof NBTTagCompound) {
                NBTTagCompound compound = (NBTTagCompound) base;
                CommonWorktableModule commonModule = CommonWorktableModule.deserailize(compound);
                if (commonModule.module == null)
                    continue;
                commonModules.add(commonModule);
            }
        }
    }
    return commonModules;
}
Also used : NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CommonWorktableModule(com.teamwizardry.wizardry.api.spell.CommonWorktableModule) HashSet(java.util.HashSet)

Example 3 with CommonWorktableModule

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

the class WorktableGui method syncToServer.

public void syncToServer() {
    Set<CommonWorktableModule> commonModules = new HashSet<>();
    for (TableModule head : getSpellHeads()) {
        TableModule lastModule = head;
        CommonWorktableModule lastCommonModule = new CommonWorktableModule(lastModule.hashCode(), lastModule.getModule(), lastModule.getPos(), null, new HashMap<>());
        commonModules.add(lastCommonModule);
        while (lastModule != null) {
            if (lastModule != head) {
                CommonWorktableModule commonModule = new CommonWorktableModule(lastModule.hashCode(), lastModule.getModule(), lastModule.getPos(), null, new HashMap<>());
                lastCommonModule.setLinksTo(commonModule);
                lastCommonModule = commonModule;
            }
            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());
                lastCommonModule.addModifier((ModuleInstanceModifier) module, count);
            }
            lastModule = lastModule.getLinksTo();
        }
    }
    int dim = Minecraft.getMinecraft().world.provider.getDimension();
    PacketHandler.NETWORK.sendToServer(new PacketSyncWorktable(dim, pos, commonModules));
}
Also used : PacketSyncWorktable(com.teamwizardry.wizardry.common.network.PacketSyncWorktable) CommonWorktableModule(com.teamwizardry.wizardry.api.spell.CommonWorktableModule) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)

Example 4 with CommonWorktableModule

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

the class WorktableGui method playLoadAnimation.

public void playLoadAnimation(Set<CommonWorktableModule> commonModules, @Nullable Runnable finish) {
    animationPlaying = true;
    resetSelectedModule();
    ComponentVoid bookIconMask = new ComponentVoid(0, -100, 180, 100);
    paper.add(bookIconMask);
    Vec2d bookOrigin = new Vec2d((bookIconMask.getSize().getX() / 2.0) - 8, -(bookIconMask.getSize().getY() / 2.0) - 4);
    Runnable itemsRunnable = () -> {
        // PAPER ITEMS ANIMATION
        {
            for (CommonWorktableModule commonHead : commonModules) {
                CommonWorktableModule commonModule = commonHead;
                TableModule lastModule = new TableModule(this, commonHead.module, true, false);
                lastModule.setPos(commonHead.pos);
                while (commonModule != null) {
                    paper.add(lastModule);
                    DragMixin drag = new DragMixin(lastModule, vec2d -> vec2d);
                    drag.setDragOffset(new Vec2d(6, 6));
                    lastModule.setData(Vec2d.class, "true_pos", commonModule.pos);
                    for (ModuleInstanceModifier modifier : commonModule.modifiers.keySet()) {
                        lastModule.setData(Integer.class, modifier.getNBTKey(), commonModule.modifiers.get(modifier));
                    }
                    lastModule.radius = 0;
                    lastModule.textRadius = 0;
                    if (commonModule.linksTo != null) {
                        TableModule childModule = new TableModule(this, commonModule.linksTo.module, true, false);
                        childModule.setPos(bookOrigin);
                        lastModule.setLinksTo(childModule);
                        lastModule = childModule;
                    }
                    commonModule = commonModule.linksTo;
                }
            }
            for (GuiComponent component : paper.getChildren()) {
                if (!(component instanceof TableModule))
                    continue;
                TableModule module = (TableModule) component;
                Vec2d target = module.getData(Vec2d.class, "true_pos");
                if (target == null) {
                    module.invalidate();
                    continue;
                }
                Vec2d randGen = new Vec2d(RandUtil.nextDouble(-100, 100), RandUtil.nextDouble(-100, 100));
                Vec2d random = bookOrigin.add(randGen);
                float delay = RandUtil.nextFloat(0.2f, 0.3f);
                float dur = RandUtil.nextFloat(70, 100);
                ScheduledEventAnimation animSound1 = new ScheduledEventAnimation(dur * delay, () -> Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f));
                KeyframeAnimation<TableModule> animX = new KeyframeAnimation<>(module, "pos.x");
                animX.setDuration(dur);
                animX.setKeyframes(new Keyframe[] { new Keyframe(delay, bookOrigin.getX(), Easing.easeOutQuint), new Keyframe(0.5f, random.getX(), Easing.easeOutQuint), new Keyframe(0.6f, random.getX(), Easing.easeOutQuint), new Keyframe(1f, target.getX(), Easing.easeOutQuint) });
                KeyframeAnimation<TableModule> animY = new KeyframeAnimation<>(module, "pos.y");
                animY.setDuration(dur);
                animY.setKeyframes(new Keyframe[] { new Keyframe(delay, bookOrigin.getY(), Easing.easeOutQuint), new Keyframe(0.5f, random.getY(), Easing.easeOutQuint), new Keyframe(0.6f, random.getY(), Easing.easeOutQuint), new Keyframe(1f, target.getY(), Easing.easeOutQuint) });
                animY.setCompletion(() -> {
                    BasicAnimation<TableModule> animRadius = new BasicAnimation<>(module, "radius");
                    animRadius.setDuration(20);
                    animRadius.setEasing(Easing.easeOutCubic);
                    animRadius.setTo(10);
                    module.add(animRadius);
                    BasicAnimation<TableModule> animText = new BasicAnimation<>(module, "textRadius");
                    animText.setDuration(40);
                    animText.setEasing(Easing.easeOutCubic);
                    animText.setTo(0);
                    module.add(animText);
                });
                module.add(animX, animY, animSound1);
            }
        }
    };
    Runnable runnable = () -> {
        // GRAY BACKGROUND
        {
            ComponentRect grayBackground = new ComponentRect(0, 0, tableComponent.getSize().getXi(), tableComponent.getSize().getYi());
            grayBackground.getColor().setValue(new Color(0.05f, 0.05f, 0.05f, 0f));
            grayBackground.getTransform().setTranslateZ(200);
            grayBackground.BUS.hook(GuiComponentEvents.ComponentTickEvent.class, event -> {
                grayBackground.getColor().setValue(new Color(0.05f, 0.05f, 0.05f, backgroundAlpha));
            });
            // tableComponent.add(grayBackground);
            KeyframeAnimation<WorktableGui> anim = new KeyframeAnimation<>(this, "backgroundAlpha");
            anim.setDuration(100);
            anim.setKeyframes(new Keyframe[] { new Keyframe(0, 0f, Easing.easeInOutQuint), new Keyframe(0.2f, 0.65f, Easing.easeInOutQuint), new Keyframe(0.7f, 0.65f, Easing.easeInOutQuint), new Keyframe(1f, 0f, Easing.easeInOutQuint) });
            anim.setCompletion(grayBackground::invalidate);
        // getMainComponents().add(anim);
        }
        // BOOK PEAK ANIMATION
        {
            ComponentSprite bookIcon = new ComponentSprite(BOOK_ICON, (int) ((bookIconMask.getSize().getX() / 2.0) - 16), (int) (bookIconMask.getSize().getY() + 50), 32, 32);
            bookIconMask.add(bookIcon);
            bookIcon.getTransform().setTranslateZ(200);
            bookIconMask.clipping.setClipToBounds(true);
            bookIconMask.getTransform().setTranslateZ(250);
            final Vec2d originalPos = bookIcon.getPos();
            KeyframeAnimation<ComponentSprite> anim = new KeyframeAnimation<>(bookIcon, "pos.y");
            anim.setDuration(120);
            anim.setKeyframes(new Keyframe[] { new Keyframe(0, originalPos.getY(), Easing.linear), new Keyframe(0.4f, (bookIconMask.getSize().getY() / 2.0) - 25, Easing.easeInBack), new Keyframe(0.5f, (bookIconMask.getSize().getY() / 2.0) - 10, Easing.easeOutBack), new Keyframe(0.8f, (bookIconMask.getSize().getY() / 2.0) - 10, Easing.easeInBack), new Keyframe(1f, originalPos.getY(), Easing.easeInBack) });
            ScheduledEventAnimation animSound = new ScheduledEventAnimation(120 * 0.4f, () -> {
                Minecraft.getMinecraft().player.playSound(ModSounds.WHOOSH, 1f, 1f);
                itemsRunnable.run();
                ScheduledEventAnimation animFinish = new ScheduledEventAnimation(100, () -> {
                    bookIcon.invalidate();
                    if (finish == null)
                        animationPlaying = false;
                    else {
                        finish.run();
                    }
                });
                getMainComponents().add(animFinish);
            });
            bookIcon.add(anim, animSound);
        }
    };
    if (selectedModule != null) {
        selectedModule = null;
        getMainComponents().add(new ScheduledEventAnimation(5, runnable));
    } else
        runnable.run();
}
Also used : BasicAnimation(com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation) GuiComponentEvents(com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) ComponentVoid(com.teamwizardry.librarianlib.features.gui.components.ComponentVoid) GuiComponent(com.teamwizardry.librarianlib.features.gui.component.GuiComponent) CommonWorktableModule(com.teamwizardry.wizardry.api.spell.CommonWorktableModule) DragMixin(com.teamwizardry.librarianlib.features.gui.mixin.DragMixin) ScheduledEventAnimation(com.teamwizardry.librarianlib.features.animator.animations.ScheduledEventAnimation) Vec2d(com.teamwizardry.librarianlib.features.math.Vec2d) ModuleInstanceModifier(com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier) Keyframe(com.teamwizardry.librarianlib.features.animator.animations.Keyframe) KeyframeAnimation(com.teamwizardry.librarianlib.features.animator.animations.KeyframeAnimation) ComponentRect(com.teamwizardry.librarianlib.features.gui.components.ComponentRect)

Example 5 with CommonWorktableModule

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

the class TileMagiciansWorktable method setCommonModules.

public void setCommonModules(@Nonnull Set<CommonWorktableModule> commonModules) {
    NBTTagList commonList = new NBTTagList();
    for (CommonWorktableModule commonModule : commonModules) {
        commonList.appendTag(commonModule.serializeNBT());
    }
    this.commonModules = commonList;
    markDirty();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) CommonWorktableModule(com.teamwizardry.wizardry.api.spell.CommonWorktableModule)

Aggregations

CommonWorktableModule (com.teamwizardry.wizardry.api.spell.CommonWorktableModule)5 ModuleInstanceModifier (com.teamwizardry.wizardry.api.spell.module.ModuleInstanceModifier)3 DragMixin (com.teamwizardry.librarianlib.features.gui.mixin.DragMixin)2 Vec2d (com.teamwizardry.librarianlib.features.math.Vec2d)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 BasicAnimation (com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation)1 Keyframe (com.teamwizardry.librarianlib.features.animator.animations.Keyframe)1 KeyframeAnimation (com.teamwizardry.librarianlib.features.animator.animations.KeyframeAnimation)1 ScheduledEventAnimation (com.teamwizardry.librarianlib.features.animator.animations.ScheduledEventAnimation)1 GuiComponent (com.teamwizardry.librarianlib.features.gui.component.GuiComponent)1 GuiComponentEvents (com.teamwizardry.librarianlib.features.gui.component.GuiComponentEvents)1 ComponentRect (com.teamwizardry.librarianlib.features.gui.components.ComponentRect)1 ComponentSprite (com.teamwizardry.librarianlib.features.gui.components.ComponentSprite)1 ComponentVoid (com.teamwizardry.librarianlib.features.gui.components.ComponentVoid)1 ModuleInstance (com.teamwizardry.wizardry.api.spell.module.ModuleInstance)1 PacketSyncWorktable (com.teamwizardry.wizardry.common.network.PacketSyncWorktable)1 TileMagiciansWorktable (com.teamwizardry.wizardry.common.tile.TileMagiciansWorktable)1 HashSet (java.util.HashSet)1 NBTBase (net.minecraft.nbt.NBTBase)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1