Вопрос Нотификатион expensive 2.0 (решено) дел

Забаненный
Статус
Оффлайн
Регистрация
29 Дек 2023
Сообщения
138
Реакции[?]
1
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Я чуть обновил натифки, почему при исчезании они багаются типо дергаются


Java:
package rarchik.code.common.notification;


import rarchik.code.common.helpers.Helper;
import rarchik.code.common.util.IMinecraft;
import rarchik.code.common.util.anim.Animation;
import rarchik.code.common.util.anim.Direction;
import rarchik.code.common.util.anim.impl.DecelerateAnimation;
import rarchik.code.common.util.render.ColorUtil;
import rarchik.code.common.util.render.MenuColorUtil;
import rarchik.code.common.util.render.RenderUtil;
import rarchik.code.common.util.render.anim.AnimationMath;
import com.mojang.blaze3d.matrix.MatrixStack;
import lombok.Getter;
import lombok.Setter;
import net.minecraft.potion.EffectInstance;
import rarchik.code.common.util.font.Fonts;

import java.util.Comparator;
import java.util.concurrent.CopyOnWriteArrayList;

import static rarchik.code.common.util.IMinecraft.mc;


public class NM {

    private final CopyOnWriteArrayList<Notification> notifications = new CopyOnWriteArrayList<>();

    public void add(String text, String content, int time) {
        notifications.add(new Notification(text, content, time));
    }


    public void draw(MatrixStack stack) {
        int yOffset = 0;
        for (Notification notification : notifications) {

            if (System.currentTimeMillis() - notification.getTime() > (notification.time2 * 1000L) - 300) {
                notification.animation.setDirection(Direction.BACKWARDS);
            } else {
                notification.yAnimation.setDirection(Direction.FORWARDS);
                notification.animation.setDirection(Direction.FORWARDS);
            }
            notification.alpha = (float) notification.animation.getOutput();
            if (System.currentTimeMillis() - notification.getTime() > notification.time2 * 1000L) {
                notification.yAnimation.setDirection(Direction.BACKWARDS);
            }
            if (notification.yAnimation.finished(Direction.BACKWARDS)) {
                notifications.remove(notification);
                continue;
            }
            float x = mc.getMainWindow().scaledWidth() - (Fonts.gilroyBold[14].getWidth(notification.getText()) + 8) - 10;
            float y = mc.getMainWindow().scaledHeight() - 30 -  (mc.player.getActivePotionEffects().stream().sorted(Comparator.comparing(EffectInstance::getDuration)).toList().size() * 16);
            notification.yAnimation.setEndPoint(yOffset);
            notification.yAnimation.setDuration(300);
            y -= (float) (notification.draw(stack) * notification.yAnimation.getOutput());
            notification.setX(x);
            notification.setY(AnimationMath.fast(notification.getY(), y, 15));
            yOffset++;
        }
    }


    private class Notification {
        [USER=270918]@Getter[/USER]
        [USER=1132491]@setter[/USER]
        private float x, y = mc.getMainWindow().scaledHeight() + 15;

        [USER=270918]@Getter[/USER]
        private String text;
        [USER=270918]@Getter[/USER]
        private String content;

        [USER=270918]@Getter[/USER]
        private long time = System.currentTimeMillis();

        public Animation animation = new DecelerateAnimation(500, 1, Direction.FORWARDS);
        public Animation yAnimation = new DecelerateAnimation(500, 1, Direction.FORWARDS);
        float alpha;
        int time2 = 3;

        public Notification(String text, String content, int time) {
            this.text = text;
            this.content = content;
            time2 = time;
        }

        public float draw(MatrixStack stack) {
            float width = Fonts.gilroyBold[14].getWidth(text) + 8;

            int firstColor = RenderUtil.reAlphaInt(Helper.STYLE_MANAGER.getCurrentStyle().getColor(0), (int) (255 * alpha));
            int secondColor = RenderUtil.reAlphaInt(Helper.STYLE_MANAGER.getCurrentStyle().getColor(100), (int) (255 * alpha));
            int thirdColor = RenderUtil.reAlphaInt(Helper.STYLE_MANAGER.getCurrentStyle().getColor(0), (int) (255 * alpha));
            int fourthColor = RenderUtil.reAlphaInt(Helper.STYLE_MANAGER.getCurrentStyle().getColor(100), (int) (255 * alpha));

            if (Helper.FUNCTION_MANAGER.hud2.shadow.get())
                RenderUtil.Render2D.drawShadow(x + 7, y + 13, width + 15, 10, 8, firstColor, secondColor, ColorUtil.getColorStyle(180), ColorUtil.getColorStyle(270));
            RenderUtil.Render2D.drawGradientRound(x + 7 - 0.25f, y + 13 - 0.25f, width + 15 + 0.5f, 10 +0.5f, 3, firstColor, secondColor, ColorUtil.getColorStyle(180), ColorUtil.getColorStyle(270));
            RenderUtil.Render2D.drawRoundedRect(x + 7, y + 13, width + 15, 10, 2, ColorUtil.rgba(30, 30, 30, 255));

            //   Fonts.msMedium[14].drawString(stack, content, x + 4 - 30, y + 5, RenderUtil.reAlphaInt(-1, (int) (255 * alpha)));
            Fonts.msMedium[12].drawString(stack, text, x + 10, y + 17, RenderUtil.reAlphaInt(-1, (int) (255 * alpha)));
            return 15;
        }
    }
}
 
Забаненный
Статус
Оффлайн
Регистрация
19 Май 2020
Сообщения
98
Реакции[?]
13
Поинты[?]
6K
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
решено, просьба не поднимать, тема старая
 
Забаненный
Статус
Оффлайн
Регистрация
29 Дек 2023
Сообщения
138
Реакции[?]
1
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Сверху Снизу