Подпишитесь на наш Telegram-канал, чтобы всегда быть в курсе важных обновлений! Перейти

Часть функционала AltManager 3.1

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
7 Фев 2024
Сообщения
45
Реакции
0
Выберите загрузчик игры
  1. OptiFine
Делал под банкой пиваса, не обсирайте пж, вторая работа с немного гпт
Код:
Expand Collapse Copy
/*
 * Decompiled with CFR 0.153-SNAPSHOT (d6f6758-dirty).
 */
package ru.vorkis.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import ru.vorkis.Rogalik;
import ru.vorkis.ui.MainScreen;
import ru.vorkis.ui.alt.Account;
import ru.vorkis.ui.alt.AltConfig;
import ru.vorkis.utils.ClientUtil;
import ru.vorkis.utils.IMinecraft;
import ru.vorkis.utils.math.MathUtility;
import ru.vorkis.utils.math.ScaleMath;
import ru.vorkis.utils.math.Vec2i;
import ru.vorkis.utils.render.ColorUtility;
import ru.vorkis.utils.render.RenderUtility;
import ru.vorkis.utils.render.Scissor;
import ru.vorkis.utils.render.ShaderUtility;
import ru.vorkis.utils.render.StencilUtility;
import ru.vorkis.utils.render.font.Fonts;

public class AltManager extends Screen {
    public ArrayList<Account> accounts = new ArrayList();
    boolean accountMenu = false;
    public float scroll;
    public float scrollAn;
    public boolean hoveredFirst;
    public boolean hoveredFirst2;
    public boolean hoveredFirst3;
    public boolean hoveredFirst4;
    public float hoveredFirstAn;
    public float hoveredFirstAn2;
    public float hoveredFirstAn3;
    public float hoveredFirstAn4;
    private String altName = "";
    private boolean typing;
    private static final Long openTime = System.currentTimeMillis();

    private final int BACKGROUND_COLOR = ColorUtility.rgba(15, 10, 25, 255);
    private final int PANEL_COLOR = ColorUtility.rgba(25, 20, 45, 255);
    private final int ACCENT_COLOR = ColorUtility.rgba(120, 80, 220, 255);
    private final int ACCENT_HOVER = ColorUtility.rgba(140, 100, 240, 255);
    private final int TEXT_COLOR = ColorUtility.rgba(220, 220, 255, 255);
    private final int INPUT_BG = ColorUtility.rgba(35, 30, 55, 255);
    private final int INPUT_BORDER = ColorUtility.rgba(80, 60, 140, 255);

    public AltManager() {
        super(new StringTextComponent("Альт-менеджер"));
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    public boolean mouseReleased(double mouseX, double mouseY, int button) {
        return super.mouseReleased(mouseX, mouseY, button);
    }

    @Override
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
        if (this.accountMenu && this.typing) {
            if (keyCode == 259) {
                if (!this.altName.isEmpty()) {
                    this.altName = this.altName.substring(0, this.altName.length() - 1);
                }
                return true;
            }
            if (keyCode == 257) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }
            if (keyCode == 256) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }
        }

        if (keyCode == 256 && !this.accountMenu) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }

        return super.keyPressed(keyCode, scanCode, modifiers);
    }

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (this.accountMenu && this.typing && this.altName.length() < 16) {
            if (Character.isLetterOrDigit(codePoint) || codePoint == '_') {
                this.altName += Character.toString(codePoint);
            }
            return true;
        }
        return super.charTyped(codePoint, modifiers);
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        Vec2i fixed = ScaleMath.getMouse((int)mouseX, (int)mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();
        MainWindow mainWindow = IMinecraft.mc.getMainWindow();

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float inputX = menuX + 20.0f;
            float inputY = menuY + 50.0f;
            float inputWidth = menuWidth - 40.0f;
            float inputHeight = 30.0f;


            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            float closeX = menuX + menuWidth - 25.0f;
            float closeY = menuY + 5.0f;
            float closeSize = 20.0f;

            if (MathUtility.isHovered(mouseX, mouseY, inputX, inputY, inputWidth, inputHeight)) {
                this.typing = true;
                return true;
            }

            if (MathUtility.isHovered(mouseX, mouseY, buttonX, buttonY, buttonWidth, buttonHeight)) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }


            if (MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeSize, closeSize)) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }


            if (!MathUtility.isHovered(mouseX, mouseY, menuX, menuY, menuWidth, menuHeight)) {
                this.accountMenu = false;
                this.typing = false;
                return true;
            }

            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accountMenu = true;
            this.typing = false;
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }


        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Iterator<Account> iterator = this.accounts.iterator();
        while (iterator.hasNext()) {
            Account alt = iterator.next();
            float acY = altY + 23.0f + iter * 20.0f;
            if (MathUtility.isHovered(mouseX, mouseY, altX, acY,
                    Fonts.sfMedium.getWidth(alt.accountName, 9.0f) + 50.0f, 18.0f)) {
                if (button == 0) {
                    IMinecraft.mc.session = new Session(alt.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
                return true;
            }
            iter += 1.0f;
        }

        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public void init(Minecraft minecraft, int width, int height) {
        super.init(minecraft, width, height);
    }

    @Override
    public void tick() {
        super.tick();
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        this.scroll += (float)(delta * 2.0);
        this.scroll = MathHelper.clamp(this.scroll,
                Math.min(-this.accounts.size() + 17.0f, 0.0f), 0.0f);
        return true;
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.scrollAn = MathUtility.lerp(this.scrollAn, this.scroll, 8.0f);

        MainWindow mainWindow = IMinecraft.mc.getMainWindow();


        updateHoverStates(mouseX, mouseY, mainWindow);


        updateHoverAnimations();


        renderBackground(matrixStack, mainWindow);


        renderMainInterface(matrixStack, mainWindow);


        renderAccountList(matrixStack, mainWindow);


        if (this.accountMenu) {
            renderAddAccountMenu(matrixStack, mainWindow, mouseX, mouseY);
        }
    }

    private void updateHoverStates(int mouseX, int mouseY, MainWindow mainWindow) {
        this.hoveredFirst = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst2 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst3 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            this.hoveredFirst4 = MathUtility.isHovered(mouseX, mouseY,
                    buttonX, buttonY, buttonWidth, buttonHeight);
        } else {
            this.hoveredFirst4 = false;
        }
    }

    private void updateHoverAnimations() {
        this.hoveredFirstAn = MathUtility.lerp(this.hoveredFirstAn, this.hoveredFirst ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn2 = MathUtility.lerp(this.hoveredFirstAn2, this.hoveredFirst2 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn3 = MathUtility.lerp(this.hoveredFirstAn3, this.hoveredFirst3 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn4 = MathUtility.lerp(this.hoveredFirstAn4, this.hoveredFirst4 ? 1.0f : 0.0f, 10.0f);
    }

    private void renderBackground(MatrixStack matrixStack, MainWindow mainWindow) {
        IMinecraft.mc.gameRenderer.setupOverlayRendering(2);
        int windowWidth = ClientUtil.calc(mainWindow.getScaledWidth());
        int windowHeight = ClientUtil.calc(mainWindow.getScaledHeight());


        ShaderUtility.BACKGROUND_SHADER.attach();
        ShaderUtility.BACKGROUND_SHADER.setUniform("time", (float)(System.currentTimeMillis() - openTime) / 1000.0f);
        ShaderUtility.BACKGROUND_SHADER.setUniform("resolution", (float)windowWidth * 2.0f, (float)windowHeight * 2.0f);
        ShaderUtility.BACKGROUND_SHADER.drawQuads(0.0f, 0.0f, windowWidth, windowHeight);
        ShaderUtility.BACKGROUND_SHADER.detach();
    }

    private void renderMainInterface(MatrixStack matrixStack, MainWindow mainWindow) {
        float fontSize = MathHelper.clamp(mainWindow.getScaledWidth() / 75, 8.0f, 12.0f);

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, mainWindow.getScaledHeight() / 12,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.2f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.15f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 10.0f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );


        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.95f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Добавить", this.hoveredFirstAn, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.22f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Случайный", this.hoveredFirstAn2, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 1.783f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Назад", this.hoveredFirstAn3, fontSize);


        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.7f,
                mainWindow.getScaledWidth() / 3, 2.0f, 0.0f, ACCENT_COLOR
        );


        Fonts.sfbold.drawCenteredText(matrixStack, "Альт-менеджер",
                (float)mainWindow.getScaledWidth() / 2.0f,
                (float)mainWindow.getScaledHeight() / 10.0f,
                TEXT_COLOR, mainWindow.getScaledWidth() / 45.0f
        );
    }

    private void renderButton(MatrixStack matrixStack, MainWindow mainWindow,
                              float x, float y, String text, float hoverAnim, float fontSize) {
        int buttonColor = ColorUtility.interpolateColor(ACCENT_COLOR, ACCENT_HOVER, hoverAnim);

        RenderUtility.drawGradientRound(x, y,
                mainWindow.getScaledWidth() / 10, (float)mainWindow.getScaledHeight() / 12.0f,
                6.0f, buttonColor, buttonColor, buttonColor, buttonColor
        );

        Fonts.sfbold.drawCenteredText(matrixStack, text,
                x + (mainWindow.getScaledWidth() / 20.0f),
                y + ((float)mainWindow.getScaledHeight() / 12.0f) / 2.5f,
                TEXT_COLOR, fontSize
        );
    }

    private void renderAccountList(MatrixStack matrixStack, MainWindow mainWindow) {
        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Scissor.push();

        Scissor.setFromComponentCoordinates(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.5f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.35f
        );

        for (Account alt : this.accounts) {
            float acY = altY + 15.0f + iter * 20.0f;


            if (acY + 18.0f < mainWindow.getScaledHeight() / 6.5f ||
                    acY > (float)mainWindow.getScaledHeight() / 1.35f + (float)mainWindow.getScaledHeight() / 6.5f) {
                iter += 1.0f;
                continue;
            }

            renderAccountEntry(matrixStack, alt, altX, acY);
            iter += 1.0f;
        }

        Scissor.pop();
    }

    private void renderAccountEntry(MatrixStack matrixStack, Account alt, float x, float y) {
        boolean isCurrent = IMinecraft.mc.session.getUsername().equals(alt.accountName);
        int textColor = isCurrent ? ACCENT_HOVER : TEXT_COLOR;


        RenderUtility.drawGradientRound(x + 5.0f, y,
                (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 10.0f, 18.0f,
                4.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG
        );


        if (isCurrent) {
            RenderUtility.drawGradientRound(x + 4.0f, y - 1.0f,
                    (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 8.0f, 20.0f,
                    5.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR
            );
        }


        StencilUtility.initStencilToWrite();
        RenderUtility.drawGradientRound(x + 12.5f, y + 2.0f, 14.0f, 14.0f, 3.0f, -1);
        StencilUtility.readStencilBuffer(1);
        IMinecraft.mc.getTextureManager().bindTexture(alt.skin);
        AbstractGui.drawScaledCustomSizeModalRect(x + 12.5f, y + 2.0f, 8.0f, 8.0f, 8.0f, 8.0f, 14.0f, 14.0f, 64.0f, 64.0f);
        StencilUtility.uninitStencilBuffer();


        Fonts.sfMedium.drawText(matrixStack, alt.accountName, x + 32.0f, y + 6.0f, textColor, 8.0f);
    }

    private void renderAddAccountMenu(MatrixStack matrixStack, MainWindow mainWindow, int mouseX, int mouseY) {

        RenderUtilitys.drawRect(0, 0, mainWindow.getScaledWidth(), mainWindow.getScaledHeight(),
                ColorUtility.rgba(0, 0, 0, 150));


        float menuWidth = mainWindow.getScaledWidth() / 3.0f;
        float menuHeight = mainWindow.getScaledHeight() / 3.5f;
        float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
        float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;


        RenderUtility.drawGradientRound(menuX, menuY, menuWidth, menuHeight,
                12.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR);


        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить аккаунт",
                menuX + menuWidth / 2.0f, menuY + 20.0f, TEXT_COLOR, 12.0f);


        float inputWidth = menuWidth - 40.0f;
        float inputHeight = 30.0f;
        float inputX = menuX + 20.0f;
        float inputY = menuY + 50.0f;


        RenderUtility.drawGradientRound(inputX, inputY, inputWidth, inputHeight,
                6.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG);


        if (this.typing) {
            RenderUtility.drawGradientRound(inputX - 1.0f, inputY - 1.0f, inputWidth + 2.0f, inputHeight + 2.0f,
                    7.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR);
        }


        String displayText = this.altName.isEmpty() && !this.typing ? "Введите ник..." : this.altName;
        int textColor = this.altName.isEmpty() && !this.typing ?
                ColorUtility.rgba(150, 150, 180, 255) : TEXT_COLOR;


        Scissor.push();
        Scissor.setFromComponentCoordinates(inputX + 5.0f, inputY, inputWidth - 10.0f, inputHeight);

        Fonts.sfMedium.drawText(matrixStack, displayText,
                inputX + 8.0f, inputY + 9.0f, textColor, 9.0f);


        if (this.typing && System.currentTimeMillis() % 1000L > 500L) {
            float textWidth = Fonts.sfMedium.getWidth(this.altName, 9.0f);
            RenderUtilitys.drawRect(inputX + 8.0f + textWidth, inputY + 7.0f,
                    1.0f, inputHeight - 14.0f, ACCENT_COLOR);
        }

        Scissor.pop();


        float buttonWidth = menuWidth - 40.0f;
        float buttonHeight = 35.0f;
        float buttonX = menuX + 20.0f;
        float buttonY = menuY + menuHeight - 50.0f;

        int addButtonColor = this.hoveredFirstAn4 > 0.1f ? ACCENT_HOVER : ACCENT_COLOR;

        RenderUtility.drawGradientRound(buttonX, buttonY, buttonWidth, buttonHeight,
                8.0f, addButtonColor, addButtonColor, addButtonColor, addButtonColor);

        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить",
                buttonX + buttonWidth / 2.0f, buttonY + 12.0f, TEXT_COLOR, 10.0f);


        float closeButtonSize = 20.0f;
        float closeX = menuX + menuWidth - closeButtonSize - 5.0f;
        float closeY = menuY + 5.0f;

        boolean closeHovered = MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeButtonSize, closeButtonSize);

        if (closeHovered) {
            RenderUtility.drawGradientRound(closeX, closeY, closeButtonSize, closeButtonSize,
                    10.0f, ColorUtility.rgba(200, 50, 50, 255), ColorUtility.rgba(200, 50, 50, 255));
        }

        Fonts.sfbold.drawCenteredText(matrixStack, "×",
                closeX + closeButtonSize / 2.0f, closeY + 4.0f, TEXT_COLOR, 14.0f);
    }
}


drawRect:
Expand Collapse Copy
  public static void drawRect(float x, float y, float width, float height, int color) {
        float right = x + width;
        float bottom = y + height;

        float red = (float)(color >> 16 & 255) / 255.0F;
        float green = (float)(color >> 8 & 255) / 255.0F;
        float blue = (float)(color & 255) / 255.0F;
        float alpha = (float)(color >> 24 & 255) / 255.0F;

        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferBuilder = tessellator.getBuffer();

        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();

        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
        bufferBuilder.pos(x, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, y, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(x, y, 0.0D).color(red, green, blue, alpha).endVertex();
        tessellator.draw();

        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }

    /**
     * Рисует обводку прямоугольника
     * @param x левая координата
     * @param y верхняя координата
     * @param width ширина
     * @param height высота
     * @param lineWidth толщина линии
     * @param color цвет в формате RGBA
     */
    public static void drawRectOutline(float x, float y, float width, float height, float lineWidth, int color) {
        drawRect(x, y, width, lineWidth, color);
        drawRect(x + width - lineWidth, y, lineWidth, height, color);
        drawRect(x, y + height - lineWidth, width, lineWidth, color);
        drawRect(x, y, lineWidth, height, color);
    }
}
 

Вложения

  • Снимок экрана 2025-10-23 201137.png
    Снимок экрана 2025-10-23 201137.png
    703.5 KB · Просмотры: 437
  • Снимок экрана 2025-10-23 201148.png
    Снимок экрана 2025-10-23 201148.png
    498.9 KB · Просмотры: 429
Делал под банкой пиваса, не обсирайте пж, вторая работа с немного гпт
Код:
Expand Collapse Copy
/*
 * Decompiled with CFR 0.153-SNAPSHOT (d6f6758-dirty).
 */
package ru.vorkis.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import ru.vorkis.Rogalik;
import ru.vorkis.ui.MainScreen;
import ru.vorkis.ui.alt.Account;
import ru.vorkis.ui.alt.AltConfig;
import ru.vorkis.utils.ClientUtil;
import ru.vorkis.utils.IMinecraft;
import ru.vorkis.utils.math.MathUtility;
import ru.vorkis.utils.math.ScaleMath;
import ru.vorkis.utils.math.Vec2i;
import ru.vorkis.utils.render.ColorUtility;
import ru.vorkis.utils.render.RenderUtility;
import ru.vorkis.utils.render.Scissor;
import ru.vorkis.utils.render.ShaderUtility;
import ru.vorkis.utils.render.StencilUtility;
import ru.vorkis.utils.render.font.Fonts;

public class AltManager extends Screen {
    public ArrayList<Account> accounts = new ArrayList();
    boolean accountMenu = false;
    public float scroll;
    public float scrollAn;
    public boolean hoveredFirst;
    public boolean hoveredFirst2;
    public boolean hoveredFirst3;
    public boolean hoveredFirst4;
    public float hoveredFirstAn;
    public float hoveredFirstAn2;
    public float hoveredFirstAn3;
    public float hoveredFirstAn4;
    private String altName = "";
    private boolean typing;
    private static final Long openTime = System.currentTimeMillis();

    private final int BACKGROUND_COLOR = ColorUtility.rgba(15, 10, 25, 255);
    private final int PANEL_COLOR = ColorUtility.rgba(25, 20, 45, 255);
    private final int ACCENT_COLOR = ColorUtility.rgba(120, 80, 220, 255);
    private final int ACCENT_HOVER = ColorUtility.rgba(140, 100, 240, 255);
    private final int TEXT_COLOR = ColorUtility.rgba(220, 220, 255, 255);
    private final int INPUT_BG = ColorUtility.rgba(35, 30, 55, 255);
    private final int INPUT_BORDER = ColorUtility.rgba(80, 60, 140, 255);

    public AltManager() {
        super(new StringTextComponent("Альт-менеджер"));
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    public boolean mouseReleased(double mouseX, double mouseY, int button) {
        return super.mouseReleased(mouseX, mouseY, button);
    }

    @Override
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
        if (this.accountMenu && this.typing) {
            if (keyCode == 259) {
                if (!this.altName.isEmpty()) {
                    this.altName = this.altName.substring(0, this.altName.length() - 1);
                }
                return true;
            }
            if (keyCode == 257) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }
            if (keyCode == 256) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }
        }

        if (keyCode == 256 && !this.accountMenu) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }

        return super.keyPressed(keyCode, scanCode, modifiers);
    }

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (this.accountMenu && this.typing && this.altName.length() < 16) {
            if (Character.isLetterOrDigit(codePoint) || codePoint == '_') {
                this.altName += Character.toString(codePoint);
            }
            return true;
        }
        return super.charTyped(codePoint, modifiers);
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        Vec2i fixed = ScaleMath.getMouse((int)mouseX, (int)mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();
        MainWindow mainWindow = IMinecraft.mc.getMainWindow();

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float inputX = menuX + 20.0f;
            float inputY = menuY + 50.0f;
            float inputWidth = menuWidth - 40.0f;
            float inputHeight = 30.0f;


            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            float closeX = menuX + menuWidth - 25.0f;
            float closeY = menuY + 5.0f;
            float closeSize = 20.0f;

            if (MathUtility.isHovered(mouseX, mouseY, inputX, inputY, inputWidth, inputHeight)) {
                this.typing = true;
                return true;
            }

            if (MathUtility.isHovered(mouseX, mouseY, buttonX, buttonY, buttonWidth, buttonHeight)) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }


            if (MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeSize, closeSize)) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }


            if (!MathUtility.isHovered(mouseX, mouseY, menuX, menuY, menuWidth, menuHeight)) {
                this.accountMenu = false;
                this.typing = false;
                return true;
            }

            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accountMenu = true;
            this.typing = false;
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }


        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Iterator<Account> iterator = this.accounts.iterator();
        while (iterator.hasNext()) {
            Account alt = iterator.next();
            float acY = altY + 23.0f + iter * 20.0f;
            if (MathUtility.isHovered(mouseX, mouseY, altX, acY,
                    Fonts.sfMedium.getWidth(alt.accountName, 9.0f) + 50.0f, 18.0f)) {
                if (button == 0) {
                    IMinecraft.mc.session = new Session(alt.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
                return true;
            }
            iter += 1.0f;
        }

        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public void init(Minecraft minecraft, int width, int height) {
        super.init(minecraft, width, height);
    }

    @Override
    public void tick() {
        super.tick();
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        this.scroll += (float)(delta * 2.0);
        this.scroll = MathHelper.clamp(this.scroll,
                Math.min(-this.accounts.size() + 17.0f, 0.0f), 0.0f);
        return true;
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.scrollAn = MathUtility.lerp(this.scrollAn, this.scroll, 8.0f);

        MainWindow mainWindow = IMinecraft.mc.getMainWindow();


        updateHoverStates(mouseX, mouseY, mainWindow);


        updateHoverAnimations();


        renderBackground(matrixStack, mainWindow);


        renderMainInterface(matrixStack, mainWindow);


        renderAccountList(matrixStack, mainWindow);


        if (this.accountMenu) {
            renderAddAccountMenu(matrixStack, mainWindow, mouseX, mouseY);
        }
    }

    private void updateHoverStates(int mouseX, int mouseY, MainWindow mainWindow) {
        this.hoveredFirst = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst2 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst3 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            this.hoveredFirst4 = MathUtility.isHovered(mouseX, mouseY,
                    buttonX, buttonY, buttonWidth, buttonHeight);
        } else {
            this.hoveredFirst4 = false;
        }
    }

    private void updateHoverAnimations() {
        this.hoveredFirstAn = MathUtility.lerp(this.hoveredFirstAn, this.hoveredFirst ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn2 = MathUtility.lerp(this.hoveredFirstAn2, this.hoveredFirst2 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn3 = MathUtility.lerp(this.hoveredFirstAn3, this.hoveredFirst3 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn4 = MathUtility.lerp(this.hoveredFirstAn4, this.hoveredFirst4 ? 1.0f : 0.0f, 10.0f);
    }

    private void renderBackground(MatrixStack matrixStack, MainWindow mainWindow) {
        IMinecraft.mc.gameRenderer.setupOverlayRendering(2);
        int windowWidth = ClientUtil.calc(mainWindow.getScaledWidth());
        int windowHeight = ClientUtil.calc(mainWindow.getScaledHeight());


        ShaderUtility.BACKGROUND_SHADER.attach();
        ShaderUtility.BACKGROUND_SHADER.setUniform("time", (float)(System.currentTimeMillis() - openTime) / 1000.0f);
        ShaderUtility.BACKGROUND_SHADER.setUniform("resolution", (float)windowWidth * 2.0f, (float)windowHeight * 2.0f);
        ShaderUtility.BACKGROUND_SHADER.drawQuads(0.0f, 0.0f, windowWidth, windowHeight);
        ShaderUtility.BACKGROUND_SHADER.detach();
    }

    private void renderMainInterface(MatrixStack matrixStack, MainWindow mainWindow) {
        float fontSize = MathHelper.clamp(mainWindow.getScaledWidth() / 75, 8.0f, 12.0f);

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, mainWindow.getScaledHeight() / 12,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.2f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.15f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 10.0f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );


        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.95f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Добавить", this.hoveredFirstAn, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.22f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Случайный", this.hoveredFirstAn2, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 1.783f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Назад", this.hoveredFirstAn3, fontSize);


        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.7f,
                mainWindow.getScaledWidth() / 3, 2.0f, 0.0f, ACCENT_COLOR
        );


        Fonts.sfbold.drawCenteredText(matrixStack, "Альт-менеджер",
                (float)mainWindow.getScaledWidth() / 2.0f,
                (float)mainWindow.getScaledHeight() / 10.0f,
                TEXT_COLOR, mainWindow.getScaledWidth() / 45.0f
        );
    }

    private void renderButton(MatrixStack matrixStack, MainWindow mainWindow,
                              float x, float y, String text, float hoverAnim, float fontSize) {
        int buttonColor = ColorUtility.interpolateColor(ACCENT_COLOR, ACCENT_HOVER, hoverAnim);

        RenderUtility.drawGradientRound(x, y,
                mainWindow.getScaledWidth() / 10, (float)mainWindow.getScaledHeight() / 12.0f,
                6.0f, buttonColor, buttonColor, buttonColor, buttonColor
        );

        Fonts.sfbold.drawCenteredText(matrixStack, text,
                x + (mainWindow.getScaledWidth() / 20.0f),
                y + ((float)mainWindow.getScaledHeight() / 12.0f) / 2.5f,
                TEXT_COLOR, fontSize
        );
    }

    private void renderAccountList(MatrixStack matrixStack, MainWindow mainWindow) {
        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Scissor.push();

        Scissor.setFromComponentCoordinates(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.5f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.35f
        );

        for (Account alt : this.accounts) {
            float acY = altY + 15.0f + iter * 20.0f;


            if (acY + 18.0f < mainWindow.getScaledHeight() / 6.5f ||
                    acY > (float)mainWindow.getScaledHeight() / 1.35f + (float)mainWindow.getScaledHeight() / 6.5f) {
                iter += 1.0f;
                continue;
            }

            renderAccountEntry(matrixStack, alt, altX, acY);
            iter += 1.0f;
        }

        Scissor.pop();
    }

    private void renderAccountEntry(MatrixStack matrixStack, Account alt, float x, float y) {
        boolean isCurrent = IMinecraft.mc.session.getUsername().equals(alt.accountName);
        int textColor = isCurrent ? ACCENT_HOVER : TEXT_COLOR;


        RenderUtility.drawGradientRound(x + 5.0f, y,
                (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 10.0f, 18.0f,
                4.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG
        );


        if (isCurrent) {
            RenderUtility.drawGradientRound(x + 4.0f, y - 1.0f,
                    (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 8.0f, 20.0f,
                    5.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR
            );
        }


        StencilUtility.initStencilToWrite();
        RenderUtility.drawGradientRound(x + 12.5f, y + 2.0f, 14.0f, 14.0f, 3.0f, -1);
        StencilUtility.readStencilBuffer(1);
        IMinecraft.mc.getTextureManager().bindTexture(alt.skin);
        AbstractGui.drawScaledCustomSizeModalRect(x + 12.5f, y + 2.0f, 8.0f, 8.0f, 8.0f, 8.0f, 14.0f, 14.0f, 64.0f, 64.0f);
        StencilUtility.uninitStencilBuffer();


        Fonts.sfMedium.drawText(matrixStack, alt.accountName, x + 32.0f, y + 6.0f, textColor, 8.0f);
    }

    private void renderAddAccountMenu(MatrixStack matrixStack, MainWindow mainWindow, int mouseX, int mouseY) {

        RenderUtilitys.drawRect(0, 0, mainWindow.getScaledWidth(), mainWindow.getScaledHeight(),
                ColorUtility.rgba(0, 0, 0, 150));


        float menuWidth = mainWindow.getScaledWidth() / 3.0f;
        float menuHeight = mainWindow.getScaledHeight() / 3.5f;
        float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
        float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;


        RenderUtility.drawGradientRound(menuX, menuY, menuWidth, menuHeight,
                12.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR);


        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить аккаунт",
                menuX + menuWidth / 2.0f, menuY + 20.0f, TEXT_COLOR, 12.0f);


        float inputWidth = menuWidth - 40.0f;
        float inputHeight = 30.0f;
        float inputX = menuX + 20.0f;
        float inputY = menuY + 50.0f;


        RenderUtility.drawGradientRound(inputX, inputY, inputWidth, inputHeight,
                6.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG);


        if (this.typing) {
            RenderUtility.drawGradientRound(inputX - 1.0f, inputY - 1.0f, inputWidth + 2.0f, inputHeight + 2.0f,
                    7.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR);
        }


        String displayText = this.altName.isEmpty() && !this.typing ? "Введите ник..." : this.altName;
        int textColor = this.altName.isEmpty() && !this.typing ?
                ColorUtility.rgba(150, 150, 180, 255) : TEXT_COLOR;


        Scissor.push();
        Scissor.setFromComponentCoordinates(inputX + 5.0f, inputY, inputWidth - 10.0f, inputHeight);

        Fonts.sfMedium.drawText(matrixStack, displayText,
                inputX + 8.0f, inputY + 9.0f, textColor, 9.0f);


        if (this.typing && System.currentTimeMillis() % 1000L > 500L) {
            float textWidth = Fonts.sfMedium.getWidth(this.altName, 9.0f);
            RenderUtilitys.drawRect(inputX + 8.0f + textWidth, inputY + 7.0f,
                    1.0f, inputHeight - 14.0f, ACCENT_COLOR);
        }

        Scissor.pop();


        float buttonWidth = menuWidth - 40.0f;
        float buttonHeight = 35.0f;
        float buttonX = menuX + 20.0f;
        float buttonY = menuY + menuHeight - 50.0f;

        int addButtonColor = this.hoveredFirstAn4 > 0.1f ? ACCENT_HOVER : ACCENT_COLOR;

        RenderUtility.drawGradientRound(buttonX, buttonY, buttonWidth, buttonHeight,
                8.0f, addButtonColor, addButtonColor, addButtonColor, addButtonColor);

        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить",
                buttonX + buttonWidth / 2.0f, buttonY + 12.0f, TEXT_COLOR, 10.0f);


        float closeButtonSize = 20.0f;
        float closeX = menuX + menuWidth - closeButtonSize - 5.0f;
        float closeY = menuY + 5.0f;

        boolean closeHovered = MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeButtonSize, closeButtonSize);

        if (closeHovered) {
            RenderUtility.drawGradientRound(closeX, closeY, closeButtonSize, closeButtonSize,
                    10.0f, ColorUtility.rgba(200, 50, 50, 255), ColorUtility.rgba(200, 50, 50, 255));
        }

        Fonts.sfbold.drawCenteredText(matrixStack, "×",
                closeX + closeButtonSize / 2.0f, closeY + 4.0f, TEXT_COLOR, 14.0f);
    }
}


drawRect:
Expand Collapse Copy
  public static void drawRect(float x, float y, float width, float height, int color) {
        float right = x + width;
        float bottom = y + height;

        float red = (float)(color >> 16 & 255) / 255.0F;
        float green = (float)(color >> 8 & 255) / 255.0F;
        float blue = (float)(color & 255) / 255.0F;
        float alpha = (float)(color >> 24 & 255) / 255.0F;

        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferBuilder = tessellator.getBuffer();

        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();

        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
        bufferBuilder.pos(x, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, y, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(x, y, 0.0D).color(red, green, blue, alpha).endVertex();
        tessellator.draw();

        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }

    /**
     * Рисует обводку прямоугольника
     * @param x левая координата
     * @param y верхняя координата
     * @param width ширина
     * @param height высота
     * @param lineWidth толщина линии
     * @param color цвет в формате RGBA
     */
    public static void drawRectOutline(float x, float y, float width, float height, float lineWidth, int color) {
        drawRect(x, y, width, lineWidth, color);
        drawRect(x + width - lineWidth, y, lineWidth, height, color);
        drawRect(x, y + height - lineWidth, width, lineWidth, color);
        drawRect(x, y, lineWidth, height, color);
    }
}
Норм
 
Делал под банкой пиваса, не обсирайте пж, вторая работа с немного гпт
Код:
Expand Collapse Copy
/*
 * Decompiled with CFR 0.153-SNAPSHOT (d6f6758-dirty).
 */
package ru.vorkis.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import ru.vorkis.Rogalik;
import ru.vorkis.ui.MainScreen;
import ru.vorkis.ui.alt.Account;
import ru.vorkis.ui.alt.AltConfig;
import ru.vorkis.utils.ClientUtil;
import ru.vorkis.utils.IMinecraft;
import ru.vorkis.utils.math.MathUtility;
import ru.vorkis.utils.math.ScaleMath;
import ru.vorkis.utils.math.Vec2i;
import ru.vorkis.utils.render.ColorUtility;
import ru.vorkis.utils.render.RenderUtility;
import ru.vorkis.utils.render.Scissor;
import ru.vorkis.utils.render.ShaderUtility;
import ru.vorkis.utils.render.StencilUtility;
import ru.vorkis.utils.render.font.Fonts;

public class AltManager extends Screen {
    public ArrayList<Account> accounts = new ArrayList();
    boolean accountMenu = false;
    public float scroll;
    public float scrollAn;
    public boolean hoveredFirst;
    public boolean hoveredFirst2;
    public boolean hoveredFirst3;
    public boolean hoveredFirst4;
    public float hoveredFirstAn;
    public float hoveredFirstAn2;
    public float hoveredFirstAn3;
    public float hoveredFirstAn4;
    private String altName = "";
    private boolean typing;
    private static final Long openTime = System.currentTimeMillis();

    private final int BACKGROUND_COLOR = ColorUtility.rgba(15, 10, 25, 255);
    private final int PANEL_COLOR = ColorUtility.rgba(25, 20, 45, 255);
    private final int ACCENT_COLOR = ColorUtility.rgba(120, 80, 220, 255);
    private final int ACCENT_HOVER = ColorUtility.rgba(140, 100, 240, 255);
    private final int TEXT_COLOR = ColorUtility.rgba(220, 220, 255, 255);
    private final int INPUT_BG = ColorUtility.rgba(35, 30, 55, 255);
    private final int INPUT_BORDER = ColorUtility.rgba(80, 60, 140, 255);

    public AltManager() {
        super(new StringTextComponent("Альт-менеджер"));
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    public boolean mouseReleased(double mouseX, double mouseY, int button) {
        return super.mouseReleased(mouseX, mouseY, button);
    }

    @Override
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
        if (this.accountMenu && this.typing) {
            if (keyCode == 259) {
                if (!this.altName.isEmpty()) {
                    this.altName = this.altName.substring(0, this.altName.length() - 1);
                }
                return true;
            }
            if (keyCode == 257) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }
            if (keyCode == 256) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }
        }

        if (keyCode == 256 && !this.accountMenu) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }

        return super.keyPressed(keyCode, scanCode, modifiers);
    }

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (this.accountMenu && this.typing && this.altName.length() < 16) {
            if (Character.isLetterOrDigit(codePoint) || codePoint == '_') {
                this.altName += Character.toString(codePoint);
            }
            return true;
        }
        return super.charTyped(codePoint, modifiers);
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        Vec2i fixed = ScaleMath.getMouse((int)mouseX, (int)mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();
        MainWindow mainWindow = IMinecraft.mc.getMainWindow();

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float inputX = menuX + 20.0f;
            float inputY = menuY + 50.0f;
            float inputWidth = menuWidth - 40.0f;
            float inputHeight = 30.0f;


            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            float closeX = menuX + menuWidth - 25.0f;
            float closeY = menuY + 5.0f;
            float closeSize = 20.0f;

            if (MathUtility.isHovered(mouseX, mouseY, inputX, inputY, inputWidth, inputHeight)) {
                this.typing = true;
                return true;
            }

            if (MathUtility.isHovered(mouseX, mouseY, buttonX, buttonY, buttonWidth, buttonHeight)) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }


            if (MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeSize, closeSize)) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }


            if (!MathUtility.isHovered(mouseX, mouseY, menuX, menuY, menuWidth, menuHeight)) {
                this.accountMenu = false;
                this.typing = false;
                return true;
            }

            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accountMenu = true;
            this.typing = false;
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }


        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Iterator<Account> iterator = this.accounts.iterator();
        while (iterator.hasNext()) {
            Account alt = iterator.next();
            float acY = altY + 23.0f + iter * 20.0f;
            if (MathUtility.isHovered(mouseX, mouseY, altX, acY,
                    Fonts.sfMedium.getWidth(alt.accountName, 9.0f) + 50.0f, 18.0f)) {
                if (button == 0) {
                    IMinecraft.mc.session = new Session(alt.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
                return true;
            }
            iter += 1.0f;
        }

        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public void init(Minecraft minecraft, int width, int height) {
        super.init(minecraft, width, height);
    }

    @Override
    public void tick() {
        super.tick();
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        this.scroll += (float)(delta * 2.0);
        this.scroll = MathHelper.clamp(this.scroll,
                Math.min(-this.accounts.size() + 17.0f, 0.0f), 0.0f);
        return true;
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.scrollAn = MathUtility.lerp(this.scrollAn, this.scroll, 8.0f);

        MainWindow mainWindow = IMinecraft.mc.getMainWindow();


        updateHoverStates(mouseX, mouseY, mainWindow);


        updateHoverAnimations();


        renderBackground(matrixStack, mainWindow);


        renderMainInterface(matrixStack, mainWindow);


        renderAccountList(matrixStack, mainWindow);


        if (this.accountMenu) {
            renderAddAccountMenu(matrixStack, mainWindow, mouseX, mouseY);
        }
    }

    private void updateHoverStates(int mouseX, int mouseY, MainWindow mainWindow) {
        this.hoveredFirst = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst2 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst3 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            this.hoveredFirst4 = MathUtility.isHovered(mouseX, mouseY,
                    buttonX, buttonY, buttonWidth, buttonHeight);
        } else {
            this.hoveredFirst4 = false;
        }
    }

    private void updateHoverAnimations() {
        this.hoveredFirstAn = MathUtility.lerp(this.hoveredFirstAn, this.hoveredFirst ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn2 = MathUtility.lerp(this.hoveredFirstAn2, this.hoveredFirst2 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn3 = MathUtility.lerp(this.hoveredFirstAn3, this.hoveredFirst3 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn4 = MathUtility.lerp(this.hoveredFirstAn4, this.hoveredFirst4 ? 1.0f : 0.0f, 10.0f);
    }

    private void renderBackground(MatrixStack matrixStack, MainWindow mainWindow) {
        IMinecraft.mc.gameRenderer.setupOverlayRendering(2);
        int windowWidth = ClientUtil.calc(mainWindow.getScaledWidth());
        int windowHeight = ClientUtil.calc(mainWindow.getScaledHeight());


        ShaderUtility.BACKGROUND_SHADER.attach();
        ShaderUtility.BACKGROUND_SHADER.setUniform("time", (float)(System.currentTimeMillis() - openTime) / 1000.0f);
        ShaderUtility.BACKGROUND_SHADER.setUniform("resolution", (float)windowWidth * 2.0f, (float)windowHeight * 2.0f);
        ShaderUtility.BACKGROUND_SHADER.drawQuads(0.0f, 0.0f, windowWidth, windowHeight);
        ShaderUtility.BACKGROUND_SHADER.detach();
    }

    private void renderMainInterface(MatrixStack matrixStack, MainWindow mainWindow) {
        float fontSize = MathHelper.clamp(mainWindow.getScaledWidth() / 75, 8.0f, 12.0f);

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, mainWindow.getScaledHeight() / 12,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.2f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.15f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 10.0f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );


        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.95f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Добавить", this.hoveredFirstAn, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.22f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Случайный", this.hoveredFirstAn2, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 1.783f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Назад", this.hoveredFirstAn3, fontSize);


        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.7f,
                mainWindow.getScaledWidth() / 3, 2.0f, 0.0f, ACCENT_COLOR
        );


        Fonts.sfbold.drawCenteredText(matrixStack, "Альт-менеджер",
                (float)mainWindow.getScaledWidth() / 2.0f,
                (float)mainWindow.getScaledHeight() / 10.0f,
                TEXT_COLOR, mainWindow.getScaledWidth() / 45.0f
        );
    }

    private void renderButton(MatrixStack matrixStack, MainWindow mainWindow,
                              float x, float y, String text, float hoverAnim, float fontSize) {
        int buttonColor = ColorUtility.interpolateColor(ACCENT_COLOR, ACCENT_HOVER, hoverAnim);

        RenderUtility.drawGradientRound(x, y,
                mainWindow.getScaledWidth() / 10, (float)mainWindow.getScaledHeight() / 12.0f,
                6.0f, buttonColor, buttonColor, buttonColor, buttonColor
        );

        Fonts.sfbold.drawCenteredText(matrixStack, text,
                x + (mainWindow.getScaledWidth() / 20.0f),
                y + ((float)mainWindow.getScaledHeight() / 12.0f) / 2.5f,
                TEXT_COLOR, fontSize
        );
    }

    private void renderAccountList(MatrixStack matrixStack, MainWindow mainWindow) {
        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Scissor.push();

        Scissor.setFromComponentCoordinates(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.5f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.35f
        );

        for (Account alt : this.accounts) {
            float acY = altY + 15.0f + iter * 20.0f;


            if (acY + 18.0f < mainWindow.getScaledHeight() / 6.5f ||
                    acY > (float)mainWindow.getScaledHeight() / 1.35f + (float)mainWindow.getScaledHeight() / 6.5f) {
                iter += 1.0f;
                continue;
            }

            renderAccountEntry(matrixStack, alt, altX, acY);
            iter += 1.0f;
        }

        Scissor.pop();
    }

    private void renderAccountEntry(MatrixStack matrixStack, Account alt, float x, float y) {
        boolean isCurrent = IMinecraft.mc.session.getUsername().equals(alt.accountName);
        int textColor = isCurrent ? ACCENT_HOVER : TEXT_COLOR;


        RenderUtility.drawGradientRound(x + 5.0f, y,
                (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 10.0f, 18.0f,
                4.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG
        );


        if (isCurrent) {
            RenderUtility.drawGradientRound(x + 4.0f, y - 1.0f,
                    (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 8.0f, 20.0f,
                    5.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR
            );
        }


        StencilUtility.initStencilToWrite();
        RenderUtility.drawGradientRound(x + 12.5f, y + 2.0f, 14.0f, 14.0f, 3.0f, -1);
        StencilUtility.readStencilBuffer(1);
        IMinecraft.mc.getTextureManager().bindTexture(alt.skin);
        AbstractGui.drawScaledCustomSizeModalRect(x + 12.5f, y + 2.0f, 8.0f, 8.0f, 8.0f, 8.0f, 14.0f, 14.0f, 64.0f, 64.0f);
        StencilUtility.uninitStencilBuffer();


        Fonts.sfMedium.drawText(matrixStack, alt.accountName, x + 32.0f, y + 6.0f, textColor, 8.0f);
    }

    private void renderAddAccountMenu(MatrixStack matrixStack, MainWindow mainWindow, int mouseX, int mouseY) {

        RenderUtilitys.drawRect(0, 0, mainWindow.getScaledWidth(), mainWindow.getScaledHeight(),
                ColorUtility.rgba(0, 0, 0, 150));


        float menuWidth = mainWindow.getScaledWidth() / 3.0f;
        float menuHeight = mainWindow.getScaledHeight() / 3.5f;
        float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
        float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;


        RenderUtility.drawGradientRound(menuX, menuY, menuWidth, menuHeight,
                12.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR);


        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить аккаунт",
                menuX + menuWidth / 2.0f, menuY + 20.0f, TEXT_COLOR, 12.0f);


        float inputWidth = menuWidth - 40.0f;
        float inputHeight = 30.0f;
        float inputX = menuX + 20.0f;
        float inputY = menuY + 50.0f;


        RenderUtility.drawGradientRound(inputX, inputY, inputWidth, inputHeight,
                6.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG);


        if (this.typing) {
            RenderUtility.drawGradientRound(inputX - 1.0f, inputY - 1.0f, inputWidth + 2.0f, inputHeight + 2.0f,
                    7.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR);
        }


        String displayText = this.altName.isEmpty() && !this.typing ? "Введите ник..." : this.altName;
        int textColor = this.altName.isEmpty() && !this.typing ?
                ColorUtility.rgba(150, 150, 180, 255) : TEXT_COLOR;


        Scissor.push();
        Scissor.setFromComponentCoordinates(inputX + 5.0f, inputY, inputWidth - 10.0f, inputHeight);

        Fonts.sfMedium.drawText(matrixStack, displayText,
                inputX + 8.0f, inputY + 9.0f, textColor, 9.0f);


        if (this.typing && System.currentTimeMillis() % 1000L > 500L) {
            float textWidth = Fonts.sfMedium.getWidth(this.altName, 9.0f);
            RenderUtilitys.drawRect(inputX + 8.0f + textWidth, inputY + 7.0f,
                    1.0f, inputHeight - 14.0f, ACCENT_COLOR);
        }

        Scissor.pop();


        float buttonWidth = menuWidth - 40.0f;
        float buttonHeight = 35.0f;
        float buttonX = menuX + 20.0f;
        float buttonY = menuY + menuHeight - 50.0f;

        int addButtonColor = this.hoveredFirstAn4 > 0.1f ? ACCENT_HOVER : ACCENT_COLOR;

        RenderUtility.drawGradientRound(buttonX, buttonY, buttonWidth, buttonHeight,
                8.0f, addButtonColor, addButtonColor, addButtonColor, addButtonColor);

        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить",
                buttonX + buttonWidth / 2.0f, buttonY + 12.0f, TEXT_COLOR, 10.0f);


        float closeButtonSize = 20.0f;
        float closeX = menuX + menuWidth - closeButtonSize - 5.0f;
        float closeY = menuY + 5.0f;

        boolean closeHovered = MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeButtonSize, closeButtonSize);

        if (closeHovered) {
            RenderUtility.drawGradientRound(closeX, closeY, closeButtonSize, closeButtonSize,
                    10.0f, ColorUtility.rgba(200, 50, 50, 255), ColorUtility.rgba(200, 50, 50, 255));
        }

        Fonts.sfbold.drawCenteredText(matrixStack, "×",
                closeX + closeButtonSize / 2.0f, closeY + 4.0f, TEXT_COLOR, 14.0f);
    }
}


drawRect:
Expand Collapse Copy
  public static void drawRect(float x, float y, float width, float height, int color) {
        float right = x + width;
        float bottom = y + height;

        float red = (float)(color >> 16 & 255) / 255.0F;
        float green = (float)(color >> 8 & 255) / 255.0F;
        float blue = (float)(color & 255) / 255.0F;
        float alpha = (float)(color >> 24 & 255) / 255.0F;

        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferBuilder = tessellator.getBuffer();

        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();

        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
        bufferBuilder.pos(x, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, y, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(x, y, 0.0D).color(red, green, blue, alpha).endVertex();
        tessellator.draw();

        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }

    /**
     * Рисует обводку прямоугольника
     * @param x левая координата
     * @param y верхняя координата
     * @param width ширина
     * @param height высота
     * @param lineWidth толщина линии
     * @param color цвет в формате RGBA
     */
    public static void drawRectOutline(float x, float y, float width, float height, float lineWidth, int color) {
        drawRect(x, y, width, lineWidth, color);
        drawRect(x + width - lineWidth, y, lineWidth, height, color);
        drawRect(x, y + height - lineWidth, width, lineWidth, color);
        drawRect(x, y, lineWidth, height, color);
    }
}
Годно
 
1761326705452.png
 
Делал под банкой пиваса, не обсирайте пж, вторая работа с немного гпт
Код:
Expand Collapse Copy
/*
 * Decompiled with CFR 0.153-SNAPSHOT (d6f6758-dirty).
 */
package ru.vorkis.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import ru.vorkis.Rogalik;
import ru.vorkis.ui.MainScreen;
import ru.vorkis.ui.alt.Account;
import ru.vorkis.ui.alt.AltConfig;
import ru.vorkis.utils.ClientUtil;
import ru.vorkis.utils.IMinecraft;
import ru.vorkis.utils.math.MathUtility;
import ru.vorkis.utils.math.ScaleMath;
import ru.vorkis.utils.math.Vec2i;
import ru.vorkis.utils.render.ColorUtility;
import ru.vorkis.utils.render.RenderUtility;
import ru.vorkis.utils.render.Scissor;
import ru.vorkis.utils.render.ShaderUtility;
import ru.vorkis.utils.render.StencilUtility;
import ru.vorkis.utils.render.font.Fonts;

public class AltManager extends Screen {
    public ArrayList<Account> accounts = new ArrayList();
    boolean accountMenu = false;
    public float scroll;
    public float scrollAn;
    public boolean hoveredFirst;
    public boolean hoveredFirst2;
    public boolean hoveredFirst3;
    public boolean hoveredFirst4;
    public float hoveredFirstAn;
    public float hoveredFirstAn2;
    public float hoveredFirstAn3;
    public float hoveredFirstAn4;
    private String altName = "";
    private boolean typing;
    private static final Long openTime = System.currentTimeMillis();

    private final int BACKGROUND_COLOR = ColorUtility.rgba(15, 10, 25, 255);
    private final int PANEL_COLOR = ColorUtility.rgba(25, 20, 45, 255);
    private final int ACCENT_COLOR = ColorUtility.rgba(120, 80, 220, 255);
    private final int ACCENT_HOVER = ColorUtility.rgba(140, 100, 240, 255);
    private final int TEXT_COLOR = ColorUtility.rgba(220, 220, 255, 255);
    private final int INPUT_BG = ColorUtility.rgba(35, 30, 55, 255);
    private final int INPUT_BORDER = ColorUtility.rgba(80, 60, 140, 255);

    public AltManager() {
        super(new StringTextComponent("Альт-менеджер"));
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    public boolean mouseReleased(double mouseX, double mouseY, int button) {
        return super.mouseReleased(mouseX, mouseY, button);
    }

    @Override
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
        if (this.accountMenu && this.typing) {
            if (keyCode == 259) {
                if (!this.altName.isEmpty()) {
                    this.altName = this.altName.substring(0, this.altName.length() - 1);
                }
                return true;
            }
            if (keyCode == 257) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }
            if (keyCode == 256) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }
        }

        if (keyCode == 256 && !this.accountMenu) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }

        return super.keyPressed(keyCode, scanCode, modifiers);
    }

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (this.accountMenu && this.typing && this.altName.length() < 16) {
            if (Character.isLetterOrDigit(codePoint) || codePoint == '_') {
                this.altName += Character.toString(codePoint);
            }
            return true;
        }
        return super.charTyped(codePoint, modifiers);
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        Vec2i fixed = ScaleMath.getMouse((int)mouseX, (int)mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();
        MainWindow mainWindow = IMinecraft.mc.getMainWindow();

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float inputX = menuX + 20.0f;
            float inputY = menuY + 50.0f;
            float inputWidth = menuWidth - 40.0f;
            float inputHeight = 30.0f;


            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            float closeX = menuX + menuWidth - 25.0f;
            float closeY = menuY + 5.0f;
            float closeSize = 20.0f;

            if (MathUtility.isHovered(mouseX, mouseY, inputX, inputY, inputWidth, inputHeight)) {
                this.typing = true;
                return true;
            }

            if (MathUtility.isHovered(mouseX, mouseY, buttonX, buttonY, buttonWidth, buttonHeight)) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }


            if (MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeSize, closeSize)) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }


            if (!MathUtility.isHovered(mouseX, mouseY, menuX, menuY, menuWidth, menuHeight)) {
                this.accountMenu = false;
                this.typing = false;
                return true;
            }

            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accountMenu = true;
            this.typing = false;
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }


        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Iterator<Account> iterator = this.accounts.iterator();
        while (iterator.hasNext()) {
            Account alt = iterator.next();
            float acY = altY + 23.0f + iter * 20.0f;
            if (MathUtility.isHovered(mouseX, mouseY, altX, acY,
                    Fonts.sfMedium.getWidth(alt.accountName, 9.0f) + 50.0f, 18.0f)) {
                if (button == 0) {
                    IMinecraft.mc.session = new Session(alt.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
                return true;
            }
            iter += 1.0f;
        }

        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public void init(Minecraft minecraft, int width, int height) {
        super.init(minecraft, width, height);
    }

    @Override
    public void tick() {
        super.tick();
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        this.scroll += (float)(delta * 2.0);
        this.scroll = MathHelper.clamp(this.scroll,
                Math.min(-this.accounts.size() + 17.0f, 0.0f), 0.0f);
        return true;
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.scrollAn = MathUtility.lerp(this.scrollAn, this.scroll, 8.0f);

        MainWindow mainWindow = IMinecraft.mc.getMainWindow();


        updateHoverStates(mouseX, mouseY, mainWindow);


        updateHoverAnimations();


        renderBackground(matrixStack, mainWindow);


        renderMainInterface(matrixStack, mainWindow);


        renderAccountList(matrixStack, mainWindow);


        if (this.accountMenu) {
            renderAddAccountMenu(matrixStack, mainWindow, mouseX, mouseY);
        }
    }

    private void updateHoverStates(int mouseX, int mouseY, MainWindow mainWindow) {
        this.hoveredFirst = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst2 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst3 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            this.hoveredFirst4 = MathUtility.isHovered(mouseX, mouseY,
                    buttonX, buttonY, buttonWidth, buttonHeight);
        } else {
            this.hoveredFirst4 = false;
        }
    }

    private void updateHoverAnimations() {
        this.hoveredFirstAn = MathUtility.lerp(this.hoveredFirstAn, this.hoveredFirst ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn2 = MathUtility.lerp(this.hoveredFirstAn2, this.hoveredFirst2 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn3 = MathUtility.lerp(this.hoveredFirstAn3, this.hoveredFirst3 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn4 = MathUtility.lerp(this.hoveredFirstAn4, this.hoveredFirst4 ? 1.0f : 0.0f, 10.0f);
    }

    private void renderBackground(MatrixStack matrixStack, MainWindow mainWindow) {
        IMinecraft.mc.gameRenderer.setupOverlayRendering(2);
        int windowWidth = ClientUtil.calc(mainWindow.getScaledWidth());
        int windowHeight = ClientUtil.calc(mainWindow.getScaledHeight());


        ShaderUtility.BACKGROUND_SHADER.attach();
        ShaderUtility.BACKGROUND_SHADER.setUniform("time", (float)(System.currentTimeMillis() - openTime) / 1000.0f);
        ShaderUtility.BACKGROUND_SHADER.setUniform("resolution", (float)windowWidth * 2.0f, (float)windowHeight * 2.0f);
        ShaderUtility.BACKGROUND_SHADER.drawQuads(0.0f, 0.0f, windowWidth, windowHeight);
        ShaderUtility.BACKGROUND_SHADER.detach();
    }

    private void renderMainInterface(MatrixStack matrixStack, MainWindow mainWindow) {
        float fontSize = MathHelper.clamp(mainWindow.getScaledWidth() / 75, 8.0f, 12.0f);

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, mainWindow.getScaledHeight() / 12,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.2f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.15f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 10.0f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );


        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.95f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Добавить", this.hoveredFirstAn, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.22f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Случайный", this.hoveredFirstAn2, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 1.783f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Назад", this.hoveredFirstAn3, fontSize);


        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.7f,
                mainWindow.getScaledWidth() / 3, 2.0f, 0.0f, ACCENT_COLOR
        );


        Fonts.sfbold.drawCenteredText(matrixStack, "Альт-менеджер",
                (float)mainWindow.getScaledWidth() / 2.0f,
                (float)mainWindow.getScaledHeight() / 10.0f,
                TEXT_COLOR, mainWindow.getScaledWidth() / 45.0f
        );
    }

    private void renderButton(MatrixStack matrixStack, MainWindow mainWindow,
                              float x, float y, String text, float hoverAnim, float fontSize) {
        int buttonColor = ColorUtility.interpolateColor(ACCENT_COLOR, ACCENT_HOVER, hoverAnim);

        RenderUtility.drawGradientRound(x, y,
                mainWindow.getScaledWidth() / 10, (float)mainWindow.getScaledHeight() / 12.0f,
                6.0f, buttonColor, buttonColor, buttonColor, buttonColor
        );

        Fonts.sfbold.drawCenteredText(matrixStack, text,
                x + (mainWindow.getScaledWidth() / 20.0f),
                y + ((float)mainWindow.getScaledHeight() / 12.0f) / 2.5f,
                TEXT_COLOR, fontSize
        );
    }

    private void renderAccountList(MatrixStack matrixStack, MainWindow mainWindow) {
        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Scissor.push();

        Scissor.setFromComponentCoordinates(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.5f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.35f
        );

        for (Account alt : this.accounts) {
            float acY = altY + 15.0f + iter * 20.0f;


            if (acY + 18.0f < mainWindow.getScaledHeight() / 6.5f ||
                    acY > (float)mainWindow.getScaledHeight() / 1.35f + (float)mainWindow.getScaledHeight() / 6.5f) {
                iter += 1.0f;
                continue;
            }

            renderAccountEntry(matrixStack, alt, altX, acY);
            iter += 1.0f;
        }

        Scissor.pop();
    }

    private void renderAccountEntry(MatrixStack matrixStack, Account alt, float x, float y) {
        boolean isCurrent = IMinecraft.mc.session.getUsername().equals(alt.accountName);
        int textColor = isCurrent ? ACCENT_HOVER : TEXT_COLOR;


        RenderUtility.drawGradientRound(x + 5.0f, y,
                (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 10.0f, 18.0f,
                4.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG
        );


        if (isCurrent) {
            RenderUtility.drawGradientRound(x + 4.0f, y - 1.0f,
                    (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 8.0f, 20.0f,
                    5.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR
            );
        }


        StencilUtility.initStencilToWrite();
        RenderUtility.drawGradientRound(x + 12.5f, y + 2.0f, 14.0f, 14.0f, 3.0f, -1);
        StencilUtility.readStencilBuffer(1);
        IMinecraft.mc.getTextureManager().bindTexture(alt.skin);
        AbstractGui.drawScaledCustomSizeModalRect(x + 12.5f, y + 2.0f, 8.0f, 8.0f, 8.0f, 8.0f, 14.0f, 14.0f, 64.0f, 64.0f);
        StencilUtility.uninitStencilBuffer();


        Fonts.sfMedium.drawText(matrixStack, alt.accountName, x + 32.0f, y + 6.0f, textColor, 8.0f);
    }

    private void renderAddAccountMenu(MatrixStack matrixStack, MainWindow mainWindow, int mouseX, int mouseY) {

        RenderUtilitys.drawRect(0, 0, mainWindow.getScaledWidth(), mainWindow.getScaledHeight(),
                ColorUtility.rgba(0, 0, 0, 150));


        float menuWidth = mainWindow.getScaledWidth() / 3.0f;
        float menuHeight = mainWindow.getScaledHeight() / 3.5f;
        float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
        float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;


        RenderUtility.drawGradientRound(menuX, menuY, menuWidth, menuHeight,
                12.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR);


        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить аккаунт",
                menuX + menuWidth / 2.0f, menuY + 20.0f, TEXT_COLOR, 12.0f);


        float inputWidth = menuWidth - 40.0f;
        float inputHeight = 30.0f;
        float inputX = menuX + 20.0f;
        float inputY = menuY + 50.0f;


        RenderUtility.drawGradientRound(inputX, inputY, inputWidth, inputHeight,
                6.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG);


        if (this.typing) {
            RenderUtility.drawGradientRound(inputX - 1.0f, inputY - 1.0f, inputWidth + 2.0f, inputHeight + 2.0f,
                    7.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR);
        }


        String displayText = this.altName.isEmpty() && !this.typing ? "Введите ник..." : this.altName;
        int textColor = this.altName.isEmpty() && !this.typing ?
                ColorUtility.rgba(150, 150, 180, 255) : TEXT_COLOR;


        Scissor.push();
        Scissor.setFromComponentCoordinates(inputX + 5.0f, inputY, inputWidth - 10.0f, inputHeight);

        Fonts.sfMedium.drawText(matrixStack, displayText,
                inputX + 8.0f, inputY + 9.0f, textColor, 9.0f);


        if (this.typing && System.currentTimeMillis() % 1000L > 500L) {
            float textWidth = Fonts.sfMedium.getWidth(this.altName, 9.0f);
            RenderUtilitys.drawRect(inputX + 8.0f + textWidth, inputY + 7.0f,
                    1.0f, inputHeight - 14.0f, ACCENT_COLOR);
        }

        Scissor.pop();


        float buttonWidth = menuWidth - 40.0f;
        float buttonHeight = 35.0f;
        float buttonX = menuX + 20.0f;
        float buttonY = menuY + menuHeight - 50.0f;

        int addButtonColor = this.hoveredFirstAn4 > 0.1f ? ACCENT_HOVER : ACCENT_COLOR;

        RenderUtility.drawGradientRound(buttonX, buttonY, buttonWidth, buttonHeight,
                8.0f, addButtonColor, addButtonColor, addButtonColor, addButtonColor);

        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить",
                buttonX + buttonWidth / 2.0f, buttonY + 12.0f, TEXT_COLOR, 10.0f);


        float closeButtonSize = 20.0f;
        float closeX = menuX + menuWidth - closeButtonSize - 5.0f;
        float closeY = menuY + 5.0f;

        boolean closeHovered = MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeButtonSize, closeButtonSize);

        if (closeHovered) {
            RenderUtility.drawGradientRound(closeX, closeY, closeButtonSize, closeButtonSize,
                    10.0f, ColorUtility.rgba(200, 50, 50, 255), ColorUtility.rgba(200, 50, 50, 255));
        }

        Fonts.sfbold.drawCenteredText(matrixStack, "×",
                closeX + closeButtonSize / 2.0f, closeY + 4.0f, TEXT_COLOR, 14.0f);
    }
}


drawRect:
Expand Collapse Copy
  public static void drawRect(float x, float y, float width, float height, int color) {
        float right = x + width;
        float bottom = y + height;

        float red = (float)(color >> 16 & 255) / 255.0F;
        float green = (float)(color >> 8 & 255) / 255.0F;
        float blue = (float)(color & 255) / 255.0F;
        float alpha = (float)(color >> 24 & 255) / 255.0F;

        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferBuilder = tessellator.getBuffer();

        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();

        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
        bufferBuilder.pos(x, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, y, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(x, y, 0.0D).color(red, green, blue, alpha).endVertex();
        tessellator.draw();

        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }

    /**
     * Рисует обводку прямоугольника
     * @param x левая координата
     * @param y верхняя координата
     * @param width ширина
     * @param height высота
     * @param lineWidth толщина линии
     * @param color цвет в формате RGBA
     */
    public static void drawRectOutline(float x, float y, float width, float height, float lineWidth, int color) {
        drawRect(x, y, width, lineWidth, color);
        drawRect(x + width - lineWidth, y, lineWidth, height, color);
        drawRect(x, y + height - lineWidth, width, lineWidth, color);
        drawRect(x, y, lineWidth, height, color);
    }
}
уродливо шо пизда
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
все криво, шрифт не подходит, а так мб сойдет, если цвета заменить еще и формы
 
Делал под банкой пиваса, не обсирайте пж, вторая работа с немного гпт
Код:
Expand Collapse Copy
/*
 * Decompiled with CFR 0.153-SNAPSHOT (d6f6758-dirty).
 */
package ru.vorkis.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import java.util.ArrayList;
import java.util.Iterator;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import ru.vorkis.Rogalik;
import ru.vorkis.ui.MainScreen;
import ru.vorkis.ui.alt.Account;
import ru.vorkis.ui.alt.AltConfig;
import ru.vorkis.utils.ClientUtil;
import ru.vorkis.utils.IMinecraft;
import ru.vorkis.utils.math.MathUtility;
import ru.vorkis.utils.math.ScaleMath;
import ru.vorkis.utils.math.Vec2i;
import ru.vorkis.utils.render.ColorUtility;
import ru.vorkis.utils.render.RenderUtility;
import ru.vorkis.utils.render.Scissor;
import ru.vorkis.utils.render.ShaderUtility;
import ru.vorkis.utils.render.StencilUtility;
import ru.vorkis.utils.render.font.Fonts;

public class AltManager extends Screen {
    public ArrayList<Account> accounts = new ArrayList();
    boolean accountMenu = false;
    public float scroll;
    public float scrollAn;
    public boolean hoveredFirst;
    public boolean hoveredFirst2;
    public boolean hoveredFirst3;
    public boolean hoveredFirst4;
    public float hoveredFirstAn;
    public float hoveredFirstAn2;
    public float hoveredFirstAn3;
    public float hoveredFirstAn4;
    private String altName = "";
    private boolean typing;
    private static final Long openTime = System.currentTimeMillis();

    private final int BACKGROUND_COLOR = ColorUtility.rgba(15, 10, 25, 255);
    private final int PANEL_COLOR = ColorUtility.rgba(25, 20, 45, 255);
    private final int ACCENT_COLOR = ColorUtility.rgba(120, 80, 220, 255);
    private final int ACCENT_HOVER = ColorUtility.rgba(140, 100, 240, 255);
    private final int TEXT_COLOR = ColorUtility.rgba(220, 220, 255, 255);
    private final int INPUT_BG = ColorUtility.rgba(35, 30, 55, 255);
    private final int INPUT_BORDER = ColorUtility.rgba(80, 60, 140, 255);

    public AltManager() {
        super(new StringTextComponent("Альт-менеджер"));
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    public boolean mouseReleased(double mouseX, double mouseY, int button) {
        return super.mouseReleased(mouseX, mouseY, button);
    }

    @Override
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
        if (this.accountMenu && this.typing) {
            if (keyCode == 259) {
                if (!this.altName.isEmpty()) {
                    this.altName = this.altName.substring(0, this.altName.length() - 1);
                }
                return true;
            }
            if (keyCode == 257) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }
            if (keyCode == 256) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }
        }

        if (keyCode == 256 && !this.accountMenu) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }

        return super.keyPressed(keyCode, scanCode, modifiers);
    }

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (this.accountMenu && this.typing && this.altName.length() < 16) {
            if (Character.isLetterOrDigit(codePoint) || codePoint == '_') {
                this.altName += Character.toString(codePoint);
            }
            return true;
        }
        return super.charTyped(codePoint, modifiers);
    }

    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        Vec2i fixed = ScaleMath.getMouse((int)mouseX, (int)mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();
        MainWindow mainWindow = IMinecraft.mc.getMainWindow();

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float inputX = menuX + 20.0f;
            float inputY = menuY + 50.0f;
            float inputWidth = menuWidth - 40.0f;
            float inputHeight = 30.0f;


            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            float closeX = menuX + menuWidth - 25.0f;
            float closeY = menuY + 5.0f;
            float closeSize = 20.0f;

            if (MathUtility.isHovered(mouseX, mouseY, inputX, inputY, inputWidth, inputHeight)) {
                this.typing = true;
                return true;
            }

            if (MathUtility.isHovered(mouseX, mouseY, buttonX, buttonY, buttonWidth, buttonHeight)) {
                if (!this.altName.isEmpty()) {
                    this.accounts.add(new Account(this.altName));
                    AltConfig.updateFile();
                    this.altName = "";
                    this.accountMenu = false;
                }
                this.typing = false;
                return true;
            }


            if (MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeSize, closeSize)) {
                this.accountMenu = false;
                this.typing = false;
                this.altName = "";
                return true;
            }


            if (!MathUtility.isHovered(mouseX, mouseY, menuX, menuY, menuWidth, menuHeight)) {
                this.accountMenu = false;
                this.typing = false;
                return true;
            }

            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accountMenu = true;
            this.typing = false;
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            this.accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
            return true;
        }


        if (MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f)) {
            IMinecraft.mc.displayGuiScreen(new MainScreen());
            return true;
        }


        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Iterator<Account> iterator = this.accounts.iterator();
        while (iterator.hasNext()) {
            Account alt = iterator.next();
            float acY = altY + 23.0f + iter * 20.0f;
            if (MathUtility.isHovered(mouseX, mouseY, altX, acY,
                    Fonts.sfMedium.getWidth(alt.accountName, 9.0f) + 50.0f, 18.0f)) {
                if (button == 0) {
                    IMinecraft.mc.session = new Session(alt.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
                return true;
            }
            iter += 1.0f;
        }

        return super.mouseClicked(mouseX, mouseY, button);
    }

    @Override
    public void init(Minecraft minecraft, int width, int height) {
        super.init(minecraft, width, height);
    }

    @Override
    public void tick() {
        super.tick();
    }

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        this.scroll += (float)(delta * 2.0);
        this.scroll = MathHelper.clamp(this.scroll,
                Math.min(-this.accounts.size() + 17.0f, 0.0f), 0.0f);
        return true;
    }

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        this.scrollAn = MathUtility.lerp(this.scrollAn, this.scroll, 8.0f);

        MainWindow mainWindow = IMinecraft.mc.getMainWindow();


        updateHoverStates(mouseX, mouseY, mainWindow);


        updateHoverAnimations();


        renderBackground(matrixStack, mainWindow);


        renderMainInterface(matrixStack, mainWindow);


        renderAccountList(matrixStack, mainWindow);


        if (this.accountMenu) {
            renderAddAccountMenu(matrixStack, mainWindow, mouseX, mouseY);
        }
    }

    private void updateHoverStates(int mouseX, int mouseY, MainWindow mainWindow) {
        this.hoveredFirst = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.95f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst2 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 2.22f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        this.hoveredFirst3 = MathUtility.isHovered(mouseX, mouseY,
                (float)mainWindow.getScaledWidth() / 1.783f,
                (float)mainWindow.getScaledHeight() / 1.14f,
                (float)(mainWindow.getScaledWidth() / 10),
                (float)mainWindow.getScaledHeight() / 12.0f);

        if (this.accountMenu) {
            float menuWidth = mainWindow.getScaledWidth() / 3.0f;
            float menuHeight = mainWindow.getScaledHeight() / 3.5f;
            float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
            float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;

            float buttonX = menuX + 20.0f;
            float buttonY = menuY + menuHeight - 50.0f;
            float buttonWidth = menuWidth - 40.0f;
            float buttonHeight = 35.0f;

            this.hoveredFirst4 = MathUtility.isHovered(mouseX, mouseY,
                    buttonX, buttonY, buttonWidth, buttonHeight);
        } else {
            this.hoveredFirst4 = false;
        }
    }

    private void updateHoverAnimations() {
        this.hoveredFirstAn = MathUtility.lerp(this.hoveredFirstAn, this.hoveredFirst ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn2 = MathUtility.lerp(this.hoveredFirstAn2, this.hoveredFirst2 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn3 = MathUtility.lerp(this.hoveredFirstAn3, this.hoveredFirst3 ? 1.0f : 0.0f, 10.0f);
        this.hoveredFirstAn4 = MathUtility.lerp(this.hoveredFirstAn4, this.hoveredFirst4 ? 1.0f : 0.0f, 10.0f);
    }

    private void renderBackground(MatrixStack matrixStack, MainWindow mainWindow) {
        IMinecraft.mc.gameRenderer.setupOverlayRendering(2);
        int windowWidth = ClientUtil.calc(mainWindow.getScaledWidth());
        int windowHeight = ClientUtil.calc(mainWindow.getScaledHeight());


        ShaderUtility.BACKGROUND_SHADER.attach();
        ShaderUtility.BACKGROUND_SHADER.setUniform("time", (float)(System.currentTimeMillis() - openTime) / 1000.0f);
        ShaderUtility.BACKGROUND_SHADER.setUniform("resolution", (float)windowWidth * 2.0f, (float)windowHeight * 2.0f);
        ShaderUtility.BACKGROUND_SHADER.drawQuads(0.0f, 0.0f, windowWidth, windowHeight);
        ShaderUtility.BACKGROUND_SHADER.detach();
    }

    private void renderMainInterface(MatrixStack matrixStack, MainWindow mainWindow) {
        float fontSize = MathHelper.clamp(mainWindow.getScaledWidth() / 75, 8.0f, 12.0f);

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, mainWindow.getScaledHeight() / 12,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.2f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );

        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.15f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 10.0f,
                8.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR
        );


        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.95f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Добавить", this.hoveredFirstAn, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 2.22f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Случайный", this.hoveredFirstAn2, fontSize);

        renderButton(matrixStack, mainWindow,
                (float)mainWindow.getScaledWidth() / 1.783f, (float)mainWindow.getScaledHeight() / 1.14f,
                "Назад", this.hoveredFirstAn3, fontSize);


        RenderUtility.drawGradientRound(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.7f,
                mainWindow.getScaledWidth() / 3, 2.0f, 0.0f, ACCENT_COLOR
        );


        Fonts.sfbold.drawCenteredText(matrixStack, "Альт-менеджер",
                (float)mainWindow.getScaledWidth() / 2.0f,
                (float)mainWindow.getScaledHeight() / 10.0f,
                TEXT_COLOR, mainWindow.getScaledWidth() / 45.0f
        );
    }

    private void renderButton(MatrixStack matrixStack, MainWindow mainWindow,
                              float x, float y, String text, float hoverAnim, float fontSize) {
        int buttonColor = ColorUtility.interpolateColor(ACCENT_COLOR, ACCENT_HOVER, hoverAnim);

        RenderUtility.drawGradientRound(x, y,
                mainWindow.getScaledWidth() / 10, (float)mainWindow.getScaledHeight() / 12.0f,
                6.0f, buttonColor, buttonColor, buttonColor, buttonColor
        );

        Fonts.sfbold.drawCenteredText(matrixStack, text,
                x + (mainWindow.getScaledWidth() / 20.0f),
                y + ((float)mainWindow.getScaledHeight() / 12.0f) / 2.5f,
                TEXT_COLOR, fontSize
        );
    }

    private void renderAccountList(MatrixStack matrixStack, MainWindow mainWindow) {
        float altX = (float)mainWindow.getScaledWidth() / 3.0f;
        float altY = mainWindow.getScaledHeight() / 8;
        float iter = this.scrollAn;

        Scissor.push();

        Scissor.setFromComponentCoordinates(
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 6.5f,
                mainWindow.getScaledWidth() / 3, (float)mainWindow.getScaledHeight() / 1.35f
        );

        for (Account alt : this.accounts) {
            float acY = altY + 15.0f + iter * 20.0f;


            if (acY + 18.0f < mainWindow.getScaledHeight() / 6.5f ||
                    acY > (float)mainWindow.getScaledHeight() / 1.35f + (float)mainWindow.getScaledHeight() / 6.5f) {
                iter += 1.0f;
                continue;
            }

            renderAccountEntry(matrixStack, alt, altX, acY);
            iter += 1.0f;
        }

        Scissor.pop();
    }

    private void renderAccountEntry(MatrixStack matrixStack, Account alt, float x, float y) {
        boolean isCurrent = IMinecraft.mc.session.getUsername().equals(alt.accountName);
        int textColor = isCurrent ? ACCENT_HOVER : TEXT_COLOR;


        RenderUtility.drawGradientRound(x + 5.0f, y,
                (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 10.0f, 18.0f,
                4.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG
        );


        if (isCurrent) {
            RenderUtility.drawGradientRound(x + 4.0f, y - 1.0f,
                    (float)IMinecraft.mc.getMainWindow().getScaledWidth() / 3 - 8.0f, 20.0f,
                    5.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR
            );
        }


        StencilUtility.initStencilToWrite();
        RenderUtility.drawGradientRound(x + 12.5f, y + 2.0f, 14.0f, 14.0f, 3.0f, -1);
        StencilUtility.readStencilBuffer(1);
        IMinecraft.mc.getTextureManager().bindTexture(alt.skin);
        AbstractGui.drawScaledCustomSizeModalRect(x + 12.5f, y + 2.0f, 8.0f, 8.0f, 8.0f, 8.0f, 14.0f, 14.0f, 64.0f, 64.0f);
        StencilUtility.uninitStencilBuffer();


        Fonts.sfMedium.drawText(matrixStack, alt.accountName, x + 32.0f, y + 6.0f, textColor, 8.0f);
    }

    private void renderAddAccountMenu(MatrixStack matrixStack, MainWindow mainWindow, int mouseX, int mouseY) {

        RenderUtilitys.drawRect(0, 0, mainWindow.getScaledWidth(), mainWindow.getScaledHeight(),
                ColorUtility.rgba(0, 0, 0, 150));


        float menuWidth = mainWindow.getScaledWidth() / 3.0f;
        float menuHeight = mainWindow.getScaledHeight() / 3.5f;
        float menuX = (mainWindow.getScaledWidth() - menuWidth) / 2.0f;
        float menuY = (mainWindow.getScaledHeight() - menuHeight) / 2.0f;


        RenderUtility.drawGradientRound(menuX, menuY, menuWidth, menuHeight,
                12.0f, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR, PANEL_COLOR);


        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить аккаунт",
                menuX + menuWidth / 2.0f, menuY + 20.0f, TEXT_COLOR, 12.0f);


        float inputWidth = menuWidth - 40.0f;
        float inputHeight = 30.0f;
        float inputX = menuX + 20.0f;
        float inputY = menuY + 50.0f;


        RenderUtility.drawGradientRound(inputX, inputY, inputWidth, inputHeight,
                6.0f, INPUT_BG, INPUT_BG, INPUT_BG, INPUT_BG);


        if (this.typing) {
            RenderUtility.drawGradientRound(inputX - 1.0f, inputY - 1.0f, inputWidth + 2.0f, inputHeight + 2.0f,
                    7.0f, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR, ACCENT_COLOR);
        }


        String displayText = this.altName.isEmpty() && !this.typing ? "Введите ник..." : this.altName;
        int textColor = this.altName.isEmpty() && !this.typing ?
                ColorUtility.rgba(150, 150, 180, 255) : TEXT_COLOR;


        Scissor.push();
        Scissor.setFromComponentCoordinates(inputX + 5.0f, inputY, inputWidth - 10.0f, inputHeight);

        Fonts.sfMedium.drawText(matrixStack, displayText,
                inputX + 8.0f, inputY + 9.0f, textColor, 9.0f);


        if (this.typing && System.currentTimeMillis() % 1000L > 500L) {
            float textWidth = Fonts.sfMedium.getWidth(this.altName, 9.0f);
            RenderUtilitys.drawRect(inputX + 8.0f + textWidth, inputY + 7.0f,
                    1.0f, inputHeight - 14.0f, ACCENT_COLOR);
        }

        Scissor.pop();


        float buttonWidth = menuWidth - 40.0f;
        float buttonHeight = 35.0f;
        float buttonX = menuX + 20.0f;
        float buttonY = menuY + menuHeight - 50.0f;

        int addButtonColor = this.hoveredFirstAn4 > 0.1f ? ACCENT_HOVER : ACCENT_COLOR;

        RenderUtility.drawGradientRound(buttonX, buttonY, buttonWidth, buttonHeight,
                8.0f, addButtonColor, addButtonColor, addButtonColor, addButtonColor);

        Fonts.sfbold.drawCenteredText(matrixStack, "Добавить",
                buttonX + buttonWidth / 2.0f, buttonY + 12.0f, TEXT_COLOR, 10.0f);


        float closeButtonSize = 20.0f;
        float closeX = menuX + menuWidth - closeButtonSize - 5.0f;
        float closeY = menuY + 5.0f;

        boolean closeHovered = MathUtility.isHovered(mouseX, mouseY, closeX, closeY, closeButtonSize, closeButtonSize);

        if (closeHovered) {
            RenderUtility.drawGradientRound(closeX, closeY, closeButtonSize, closeButtonSize,
                    10.0f, ColorUtility.rgba(200, 50, 50, 255), ColorUtility.rgba(200, 50, 50, 255));
        }

        Fonts.sfbold.drawCenteredText(matrixStack, "×",
                closeX + closeButtonSize / 2.0f, closeY + 4.0f, TEXT_COLOR, 14.0f);
    }
}


drawRect:
Expand Collapse Copy
  public static void drawRect(float x, float y, float width, float height, int color) {
        float right = x + width;
        float bottom = y + height;

        float red = (float)(color >> 16 & 255) / 255.0F;
        float green = (float)(color >> 8 & 255) / 255.0F;
        float blue = (float)(color & 255) / 255.0F;
        float alpha = (float)(color >> 24 & 255) / 255.0F;

        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferBuilder = tessellator.getBuffer();

        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();

        bufferBuilder.begin(7, DefaultVertexFormats.POSITION_COLOR);
        bufferBuilder.pos(x, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, bottom, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(right, y, 0.0D).color(red, green, blue, alpha).endVertex();
        bufferBuilder.pos(x, y, 0.0D).color(red, green, blue, alpha).endVertex();
        tessellator.draw();

        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }

    /**
     * Рисует обводку прямоугольника
     * @param x левая координата
     * @param y верхняя координата
     * @param width ширина
     * @param height высота
     * @param lineWidth толщина линии
     * @param color цвет в формате RGBA
     */
    public static void drawRectOutline(float x, float y, float width, float height, float lineWidth, int color) {
        drawRect(x, y, width, lineWidth, color);
        drawRect(x + width - lineWidth, y, lineWidth, height, color);
        drawRect(x, y + height - lineWidth, width, lineWidth, color);
        drawRect(x, y, lineWidth, height, color);
    }
}
кривовато но доделать и пойдет
 
Назад
Сверху Снизу