Search in sources :

Example 1 with BasicAnimation

use of com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation in project Wizardry by TeamWizardry.

the class TileCraftingPlateRenderer method animationLoop.

public void animationLoop(int i, boolean motionInvert) {
    LocationAndAngle locationAndAngle = pop(i);
    if (locationAndAngle == null)
        return;
    CapManager manager = new CapManager(tile.getWizardryCap());
    Vec3d newDest;
    double t = manager.getCap() == null ? 1 : 1 - (manager.getMana() / manager.getMaxMana());
    double radius = RandUtil.nextDouble(5, 8) * t;
    locationAndAngle.angle += RandUtil.nextDouble(-1.5, 1.5);
    double x = MathHelper.cos((float) locationAndAngle.angle) * radius;
    double z = MathHelper.sin((float) locationAndAngle.angle) * radius;
    newDest = new Vec3d(x, (2 + (RandUtil.nextFloat() * 7)) * t, z);
    BasicAnimation<LocationAndAngle> anim = new BasicAnimation<>(locationAndAngle, "location");
    anim.setTo(newDest);
    anim.setDuration((float) (RandUtil.nextDouble(50, 100) * (tile.suckingCooldown <= 0 ? MathHelper.clamp(t * 2, 0, 1) : t)));
    anim.setEasing(!manager.isManaEmpty() ? Easing.easeInOutQuint : Easing.easeInOutSine);
    anim.setCompletion(() -> animationLoop(i, !motionInvert));
    animator.add(anim);
}
Also used : CapManager(com.teamwizardry.wizardry.api.capability.CapManager) BasicAnimation(com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with BasicAnimation

use of com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation in project Wizardry by TeamWizardry.

the class RenderCodex method doRender.

private void doRender(EnumHandSide side, ItemStack stack) {
    Minecraft mc = Minecraft.getMinecraft();
    boolean isGuiOpen = mc.currentScreen instanceof GuiBook;
    boolean rightHand = side == EnumHandSide.RIGHT;
    boolean hasSpell = ItemNBTHelper.getBoolean(stack, "has_spell", false);
    final String openingTagRight = "openingCooldownRight";
    final String openingTagLeft = "openingCooldownLeft";
    final String openingTag = rightHand ? openingTagRight : openingTagLeft;
    if (isGuiOpen || hasSpell) {
        if (!animatingFields.contains(openingTag)) {
            animatingFields.add(openingTag);
            BasicAnimation<RenderCodex> anim = new BasicAnimation<>(INSTANCE, openingTag);
            anim.setTo(10);
            anim.setDuration(20);
            anim.setEasing(Easing.easeOutCubic);
            anim.setCompletion(() -> {
                if (animatingFields.contains(openingTag))
                    animatingFields.remove(openingTag);
            });
            animator.add(anim);
        }
    } else {
        if (!animatingFields.contains(openingTag)) {
            animatingFields.add(openingTag);
            BasicAnimation<RenderCodex> anim = new BasicAnimation<>(INSTANCE, openingTag);
            anim.setTo(0);
            anim.setDuration(20);
            anim.setEasing(Easing.easeOutCubic);
            anim.setCompletion(() -> {
                if (animatingFields.contains(openingTag))
                    animatingFields.remove(openingTag);
            });
            animator.add(anim);
        }
    }
    animateIdle("idleXRight");
    animateIdle("idleYRight");
    animateIdle("idleZRight");
    animateIdle("idleXLeft");
    animateIdle("idleYLeft");
    animateIdle("idleZLeft");
    GlStateManager.pushMatrix();
    GlStateManager.color(1F, 1F, 1F);
    double flip = rightHand ? 1 : -1;
    float openingCooldown = rightHand ? openingCooldownRight : openingCooldownLeft;
    float idleX = rightHand ? idleXRight : idleXLeft;
    float idleY = rightHand ? idleYRight : idleYLeft;
    float idleZ = rightHand ? idleZRight : idleZLeft;
    // X axis is Z axis
    // Z axis is X axis
    // Everything is reversed
    GlStateManager.translate(0.3F + 0.02F * openingCooldown + (openingCooldown / 50.0) + ((10 - openingCooldown) / 50.0F) + (rightHand ? -0.1F : 0), 0.475F + 0.01F * openingCooldown + (!rightHand ? 0.02F : 0) + ((10 - openingCooldown) / 100.0F), -0.2F - (rightHand ? 0.035F : 0.01F) * openingCooldown + (flip * openingCooldown / 50.0) + (!rightHand ? ((openingCooldown / 10.0F) * 0.08F - 0.03F) : 0));
    // 87.5 rotates from facing the book's spine to the cover facing the player
    // Rotates around book spine
    GlStateManager.rotate((rightHand ? 87.5F : ((openingCooldown / 10.0F) * -20 + 90)) + openingCooldown * (rightHand ? 8 : 12) + (idleY * 5f), 0F, 1F, 0F);
    // Rotates around the CENTER of the book's spine horizontally.
    // IE: Transverse section of the book.
    // Point ur hand horizontally and slide it horizontally.
    // Will rotate the book backwards as it opens, adding a 3d effect
    GlStateManager.rotate(idleZ * 5f, 0F, 0F, 1F);
    mc.renderEngine.bindTexture(texture);
    model.render(null, 0F, 0F, pageFlipCooldownRight, openingCooldown / 12F, 0F, 1F / 16F);
    FontRenderer font = Minecraft.getMinecraft().fontRenderer;
    boolean prevFlag = font.getUnicodeFlag();
    GlStateManager.rotate(180F, 0F, 0F, 1F);
    if (openingCooldown < 3) {
        font.setUnicodeFlag(false);
        GlStateManager.pushMatrix();
        GlStateManager.disableLighting();
        GlStateManager.translate(-0.30F, -0.24F, -0.07F);
        GlStateManager.scale(0.003F, 0.003F, -0.003F);
        // Yes. I'm nudging it. This is how horrible this gl state is.
        GlStateManager.translate(-2, 0, 0);
        // Below logo
        GlStateManager.translate(0, 70 - font.FONT_HEIGHT, 0);
        String[] title = LibrarianLib.PROXY.translate("wizardry.book.title").split(" ");
        for (String aTitle : title) {
            GlStateManager.translate(0, font.FONT_HEIGHT, 0);
            String titleText = font.trimStringToWidth(aTitle, 80);
            int width = font.getStringWidth(titleText);
            int max = 80;
            double x = max / 2.0 - width / 2.0;
            GlStateManager.translate(x, 0, 0);
            font.drawString(titleText, 0, 0, 0x00FFFF);
            GlStateManager.translate(-x, 0, 0);
        }
        GlStateManager.translate(0, font.FONT_HEIGHT, 0);
        String subtitle = font.trimStringToWidth(LibrarianLib.PROXY.translate("wizardry.book.subtitle"), 80);
        double scale = 2.6;
        GlStateManager.translate((80F - font.getStringWidth(subtitle)) * scale, 0F, 0F);
        GlStateManager.scale(0.6F, 0.6F, 0.6F);
        font.drawString(TextFormatting.ITALIC + subtitle, 0, 0, 0x00FFFF);
        GlStateManager.enableLighting();
        GlStateManager.popMatrix();
    }
    // You're welcome.
    if (hasSpell && openingCooldown > 6) {
        font.setUnicodeFlag(true);
        // LEFT PAGE
        {
            GlStateManager.pushMatrix();
            GlStateManager.rotate(60, 0, 1, 0);
            GlStateManager.translate(0, 0.1, 0);
            GlStateManager.translate(-0.30F, -0.24F, -0.07F);
            GlStateManager.scale(0.003F, 0.003F, -0.003F);
            GlStateManager.translate(-10, -30, -5);
            String[] lines = getSpellStructureLines(stack);
            for (int i = 0; i < lines.length; i++) font.drawString(lines[i], 0, i * font.FONT_HEIGHT, 0x00);
            GlStateManager.popMatrix();
        }
        // RIGHT PAGE
        {
            GlStateManager.pushMatrix();
            GlStateManager.rotate(120, 0, 1, 0);
            GlStateManager.translate(0, 0.1, 0);
            GlStateManager.translate(-0.30F, -0.24F, -0.07F);
            GlStateManager.scale(0.003F, 0.003F, -0.003F);
            GlStateManager.translate(120, -25, 0);
            // Translate a little extra bit to fit the recipe cozily
            GlStateManager.translate(-5, -5, 0);
            int row = 0;
            int column = 0;
            List<ItemStack> inventory = getSpellInventory(stack);
            for (int i = 0; i < inventory.size(); i++) {
                ItemStack recipeStack = inventory.get(i);
                if (recipeStack.isEmpty())
                    continue;
                GlStateManager.pushMatrix();
                GlStateManager.translate(column * 32, row * 16, -150);
                renderItemStack(recipeStack);
                GlStateManager.popMatrix();
                if (i != inventory.size() - 1 && column < 3) {
                    GlStateManager.pushMatrix();
                    GlStateManager.translate(32 + column * 32, row * 16 + 13, 0);
                    GlStateManager.rotate(180, 0, 0, 1);
                    GlStateManager.color(0, 1f, 1f, 1f);
                    GlStateManager.disableLighting();
                    arrowSprite.bind();
                    arrowSprite.draw(0, 0, 0, 16, 8);
                    GlStateManager.popMatrix();
                }
                if (++column >= 3) {
                    column = 0;
                    row++;
                }
            }
            GlStateManager.popMatrix();
        }
    }
    font.setUnicodeFlag(prevFlag);
    GlStateManager.popMatrix();
}
Also used : BasicAnimation(com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation) GuiBook(com.teamwizardry.wizardry.client.gui.book.GuiBook) Minecraft(net.minecraft.client.Minecraft) ArrayList(java.util.ArrayList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BasicAnimation (com.teamwizardry.librarianlib.features.animator.animations.BasicAnimation)2 CapManager (com.teamwizardry.wizardry.api.capability.CapManager)1 GuiBook (com.teamwizardry.wizardry.client.gui.book.GuiBook)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Minecraft (net.minecraft.client.Minecraft)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 Vec3d (net.minecraft.util.math.Vec3d)1