Исходник Мега умная паста AltManager Relake Client expensive 2.0

Начинающий
Статус
Оффлайн
Регистрация
31 Июл 2024
Сообщения
4
Реакции[?]
0
Поинты[?]
0
Приветики, написанный альт менеджер за 2 часа в студии



Java:
package name.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import org.lwjgl.glfw.GLFW;
import name.util.MouseUtil;
import name.util.font.Fonts;
import name.util.render.*;
import name.util.render.animation.AnimationMath;

import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;

import static name.util.IMinecraft.mc;

public class AltManager extends Screen {

    public AltManager() {
        super(new StringTextComponent(""));
    }

    public ArrayList<Account> accounts = new ArrayList<>();

    public float scroll;
    public float scrollAn;

    private String altName = "";
    private boolean typing;

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        scrollAn = AnimationMath.lerp(scrollAn, scroll, 5);

        mc.gameRenderer.setupOverlayRendering(2);
        RenderUtil.Render2D.drawImage(new ResourceLocation("radix/images/backmenu.png"), 0, 0, mc.getMainWindow().scaledWidth(), mc.getMainWindow().scaledHeight(), -1);

        float offset = 6f;
        float width = 250f, height = 270f;
        float x = mc.getMainWindow().getScaledWidth() / 2f - width / 2f, y = mc.getMainWindow().getScaledHeight() / 2f - height / 2f;

        // Квадрат фона
        RenderUtil.Render2D.drawRoundedCorner(x - offset, y - offset, width + offset * 2f, height + offset * 2f, 5f, ColorUtil.rgba(22, 22, 22, 215));

        // Первый заголовок
        Fonts.icons1[22].drawString(matrixStack, "D", x + offset, y + offset + 1f, -1);
        Fonts.gilroyBold[22].drawString(matrixStack, "Добавьте новый аккаунт!", x + offset + Fonts.icons1[16].getWidth("D") + 6f, y + offset, -1);
        Fonts.gilroyBold[12].drawString(matrixStack, "Смени никнейм, и отправляйся в игру!", x + offset, y + offset + 18f, ColorUtil.rgb(180, 180, 180));

        // Квадратик для ввода ника
        RenderUtil.Render2D.drawRoundedCorner(x + offset, y + offset + 25f, width - offset * 2f, 20f, 2f, ColorUtil.rgba(60, 60, 60, 215));
        SmartScissor.push();
        SmartScissor.setFromComponentCoordinates(x + offset, y + offset + 25f, width - offset * 2f, 20f);
        Fonts.msSemiBold[15].drawString(matrixStack, typing ? (altName + (typing ? "|" : "")) : "Тут чота пусто =(", x + offset + 2f, y + offset + 32.5f, ColorUtil.rgb(152, 152, 152));
        SmartScissor.unset();
        SmartScissor.pop();

        // Знак для ввода рандомного ника
        Fonts.msBold[22].drawString(matrixStack, "?", x + width - offset - 12.5f, y + offset + 31f, -1);

        // Второй заголовок
        Fonts.gilroyBold[22].drawString(matrixStack, "Аккаунты:", x + offset, y + offset + 60f, -1);
        Fonts.gilroyBold[12].drawString(matrixStack, "Выбери аккаунт из списка!", x + offset, y + offset + 73f, ColorUtil.rgb(180, 180, 180));

        // Вывод никнеймов
        RenderUtil.Render2D.drawRoundedCorner(x + offset, y + offset + 80f, width - offset * 2f, 177.5f, 2f, ColorUtil.rgba(60, 60, 60, 215));

        // Надпись при пустом листе аккаунтов
        if (accounts.isEmpty()) Fonts.msBold[22].drawCenteredString(matrixStack, "А где...", x + width / 2f, y + offset + 165.75f, -1);

        // Основной функционал для показа аккаунтов
        float size = 0f, iter = scrollAn, offsetAccounts = 0f;
        SmartScissor.push();
        SmartScissor.setFromComponentCoordinates(x + offset, y + offset + 80f, width - offset * 2f, 177.5f);
        for (Account account : accounts) {
            float scrollY = y + iter * 22f;

            RenderUtil.Render2D.drawRoundedRect(x + offset + 2f, scrollY + offset + 82f + offsetAccounts, width - offset * 2f - 4f, 20f, 2f, ColorUtil.rgb(101, 101, 101));

            Fonts.msSemiBold[16].drawString(matrixStack, account.accountName, x + offset + 25f, scrollY + offset + 82f + 8f + offsetAccounts, -1);

            StencilUtil.initStencilToWrite();
            RenderUtil.Render2D.drawRoundedRect(x + offset + 4f + 0.5f, scrollY + offset + 84f + offsetAccounts, 16, 16, 2f, Color.BLACK.getRGB());
            StencilUtil.readStencilBuffer(1);
            mc.getTextureManager().bindTexture(account.skin);
            AbstractGui.drawScaledCustomSizeModalRect(x + offset + 4f + 0.5f, scrollY + offset + 84f + offsetAccounts, 8F, 8F, 8F, 8F, 16, 16, 64, 64);
            StencilUtil.uninitStencilBuffer();

            iter++;
            size++;
        }
        scroll = MathHelper.clamp(scroll, size > 8 ? -size + 4 : 0, 0);
        SmartScissor.unset();
        SmartScissor.pop();

        // Показ текущего ника
        Fonts.gilroyBold[12].drawString(matrixStack, "Ваш ник - " + mc.session.getUsername() + ".", x + offset, y + height - offset / 2, ColorUtil.rgb(180, 180, 180));

        mc.gameRenderer.setupOverlayRendering();
    }

    @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 (keyCode == GLFW.GLFW_KEY_BACKSPACE) {
            if (!altName.isEmpty() && typing)
                altName = altName.substring(0, altName.length() - 1);
        }

        if (keyCode == GLFW.GLFW_KEY_ENTER) {
            if (!altName.isEmpty()) {
                accounts.add(new Account(altName));
                AltConfig.updateFile();
            }
            typing = false;
            altName = "";
        }

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

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (altName.length() <= 20) altName += Character.toString(codePoint);
        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();

        float offset = 6f;
        float width = 250f, height = 270f;
        float x = mc.getMainWindow().getScaledWidth() / 2f - width / 2f, y = mc.getMainWindow().getScaledHeight() / 2f - height / 2f;

        if (RenderUtil.isInRegion(mouseX, mouseY, x + width - offset - 12.5f, y + offset + 31f, Fonts.msBold[22].getWidth("?"), Fonts.msBold[22].getFontHeight())) {
            accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
        }
        if (RenderUtil.isInRegion(mouseX, mouseY, x + offset, y + offset + 25f, width - offset * 2f, 20f) && !RenderUtil.isInRegion(mouseX, mouseY, x + width - offset - 12.5f, y + offset + 31f, Fonts.msBold[22].getWidth("?"), Fonts.msBold[22].getFontHeight())) {
            typing = !typing;
        }

        // Основной функционал позволяющий позволяющий брать/удалять ник
        float iter = scrollAn, offsetAccounts = 0f;
        Iterator<Account> iterator = accounts.iterator();
        while (iterator.hasNext()) {
            Account account = iterator.next();

            float scrollY = y + iter * 22f;

            if (RenderUtil.isInRegion(mouseX, mouseY, x + offset + 2f, scrollY + offset + 82f + offsetAccounts, width - offset * 2f - 4f, 20f)) {
                if (button == 0) {
                    mc.session = new Session(account.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
            }

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

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        Vec2i fixed = ScaleMath.getMouse((int) mouseX, (int) mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();

        // Скролл
        float offset = 6f;
        float width = 250f, height = 270f;
        float x = mc.getMainWindow().getScaledWidth() / 2f - width / 2f, y = mc.getMainWindow().getScaledHeight() / 2f - height / 2f;

        if (MouseUtil.isHovered(mouseX, mouseY, x + offset, y + offset + 80f, width - offset * 2f, 177.5f)) scroll += delta * 1;
        return super.mouseScrolled(mouseX, mouseY, delta);
    }

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

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

    @Override
    public void tick() {
        super.tick();
    }
}
 
Начинающий
Статус
Оффлайн
Регистрация
31 Июл 2024
Сообщения
4
Реакции[?]
0
Поинты[?]
0
Java:
package name.util;

import net.minecraft.entity.Entity;
import net.minecraft.entity.projectile.ProjectileHelper;
import net.minecraft.util.Direction;
import net.minecraft.util.math.*;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;

import java.util.Optional;
import java.util.function.Predicate;

public class MouseUtil implements IMinecraft {
    public static Entity getMouseOver(Entity target,
                                      float yaw,
                                      float pitch,
                                      double distance) {
        RayTraceResult objectMouseOver;
        Entity entity = mc.getRenderViewEntity();

        if (entity != null && mc.world != null) {
            objectMouseOver = null;
            boolean flag = distance > 3;

            Vector3d startVec = entity.getEyePosition(1);
            Vector3d directionVec = getVectorForRotation(pitch, yaw);
            Vector3d endVec = startVec.add(
                    directionVec.x * distance,
                    directionVec.y * distance,
                    directionVec.z * distance
            );

            AxisAlignedBB axisalignedbb = target.getBoundingBox().grow(target.getCollisionBorderSize());

            EntityRayTraceResult entityraytraceresult = rayTraceEntities(entity,
                    startVec,
                    endVec,
                    axisalignedbb,
                    (p_lambda$getMouseOver$0_0_) ->
                            !p_lambda$getMouseOver$0_0_.isSpectator()
                                    && p_lambda$getMouseOver$0_0_.canBeCollidedWith(), distance
            );

            if (entityraytraceresult != null) {
                if (flag && startVec.distanceTo(startVec) > distance) {
                    objectMouseOver = BlockRayTraceResult.createMiss(startVec, null, new BlockPos(startVec));
                }
                if ((distance < distance || objectMouseOver == null)) {
                    objectMouseOver = entityraytraceresult;
                }
            }
            if (objectMouseOver == null) {
                return null;
            }
            if (objectMouseOver instanceof EntityRayTraceResult obj) {
                return obj.getEntity();
            }
        }
        return null;
    }

    public static boolean isHovered(int mouseX, int mouseY, float x,float y, float width, float height) {
        return mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
    }

    public static boolean isHovered(float mouseX, float mouseY, float x,float y, float width, float height) {
        return mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
    }

    public static boolean isHovered(double mouseX, double mouseY, float x,float y, float width, float height) {
        return mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height;
    }

    public static EntityRayTraceResult rayTraceEntities(Entity shooter,
                                                        Vector3d startVec,
                                                        Vector3d endVec,
                                                        AxisAlignedBB boundingBox,
                                                        Predicate<Entity> filter,
                                                        double distance) {
        World world = shooter.world;
        double closestDistance = distance;
        Entity entity = null;
        Vector3d closestHitVec = null;

        for (Entity entity1 : world.getEntitiesInAABBexcluding(shooter, boundingBox, filter)) {
            AxisAlignedBB axisalignedbb = entity1.getBoundingBox().grow(entity1.getCollisionBorderSize());
            Optional<Vector3d> optional = axisalignedbb.rayTrace(startVec, endVec);

            if (axisalignedbb.contains(startVec)) {
                if (closestDistance >= 0.0D) {
                    entity = entity1;
                    closestHitVec = startVec;
                    closestDistance = 0.0D;
                }
            } else if (optional.isPresent()) {
                Vector3d vector3d1 = optional.get();
                double d3 = startVec.distanceTo(optional.get());

                if (d3 < closestDistance || closestDistance == 0.0D) {
                    boolean flag1 = false;

                    if (!flag1 && entity1.getLowestRidingEntity() == shooter.getLowestRidingEntity()) {
                        if (closestDistance == 0.0D) {
                            entity = entity1;
                            closestHitVec = vector3d1;
                        }
                    } else {
                        entity = entity1;
                        closestHitVec = vector3d1;
                        closestDistance = d3;
                    }
                }
            }
        }

        return entity == null ? null : new EntityRayTraceResult(entity, closestHitVec);
    }

    public static RayTraceResult rayTrace(double rayTraceDistance,
                                          float yaw,
                                          float pitch,
                                          Entity entity) {
        Vector3d startVec = mc.player.getEyePosition(1.0F);
        Vector3d directionVec = getVectorForRotation(pitch, yaw);
        Vector3d endVec = startVec.add(
                directionVec.x * rayTraceDistance,
                directionVec.y * rayTraceDistance,
                directionVec.z * rayTraceDistance
        );

        return mc.world.rayTraceBlocks(new RayTraceContext(
                startVec,
                endVec,
                RayTraceContext.BlockMode.OUTLINE,
                RayTraceContext.FluidMode.NONE,
                entity)
        );
    }


    public static RayTraceResult rayTraceResult(double rayTraceDistance,
                                                float yaw,
                                                float pitch,
                                                Entity entity) {

        RayTraceResult object = null;

        if (entity != null && mc.world != null) {
            float partialTicks = mc.getRenderPartialTicks();
            double distance = rayTraceDistance;
            object = rayTrace(rayTraceDistance, yaw, pitch, entity);
            Vector3d vector3d = entity.getEyePosition(partialTicks);
            boolean flag = false;
            double d1 = distance;

            if (mc.playerController.extendedReach()) {
                d1 = 6.0D;
                distance = d1;
            } else {
                if (distance > 3.0D) {
                    flag = true;
                }

                distance = distance;
            }

            d1 = d1 * d1;

            if (object != null) {
                d1 = object.getHitVec().squareDistanceTo(vector3d);
            }

            Vector3d vector3d1 = getVectorForRotation(pitch, yaw);
            Vector3d vector3d2 = vector3d.add(vector3d1.x * distance, vector3d1.y * distance, vector3d1.z * distance);
            float f = 1.0F;
            AxisAlignedBB axisalignedbb = entity.getBoundingBox().expand(vector3d1.scale(distance)).grow(1.0D, 1.0D, 1.0D);
            EntityRayTraceResult entityraytraceresult = ProjectileHelper.rayTraceEntities(entity, vector3d, vector3d2, axisalignedbb, (p_lambda$getMouseOver$0_0_) ->
            {
                return !p_lambda$getMouseOver$0_0_.isSpectator() && p_lambda$getMouseOver$0_0_.canBeCollidedWith();
            }, d1);

            if (entityraytraceresult != null) {
                Entity entity1 = entityraytraceresult.getEntity();
                Vector3d vector3d3 = entityraytraceresult.getHitVec();
                double d2 = vector3d.squareDistanceTo(vector3d3);

                if (flag && d2 > 9.0D) {
                    object = BlockRayTraceResult.createMiss(vector3d3, Direction.getFacingFromVector(vector3d1.x, vector3d1.y, vector3d1.z), new BlockPos(vector3d3));
                } else if (d2 < d1 || object == null) {
                    object = entityraytraceresult;
                }
            }
        }
        return object;
    }


    public static boolean rayTraceWithBlock(double rayTraceDistance,
                                            float yaw,
                                            float pitch,
                                            Entity entity, Entity target) {

        RayTraceResult object = null;

        if (entity != null && mc.world != null) {
            float partialTicks = mc.getRenderPartialTicks();
            double distance = rayTraceDistance;
            object = rayTrace(rayTraceDistance, yaw, pitch, entity);
            Vector3d vector3d = entity.getEyePosition(partialTicks);
            boolean flag = false;
            double d1 = distance;

            if (mc.playerController.extendedReach()) {
                d1 = 6.0D;
                distance = d1;
            } else {
                if (distance > 3.0D) {
                    flag = true;
                }

                distance = distance;
            }

            d1 = d1 * d1;

            if (object != null) {
                d1 = object.getHitVec().squareDistanceTo(vector3d);
            }

            Vector3d vector3d1 = getVectorForRotation(pitch, yaw);
            Vector3d vector3d2 = vector3d.add(vector3d1.x * distance, vector3d1.y * distance, vector3d1.z * distance);
            float f = 1.0F;
            AxisAlignedBB axisalignedbb = entity.getBoundingBox().expand(vector3d1.scale(distance)).grow(1.0D, 1.0D, 1.0D);
            EntityRayTraceResult entityraytraceresult = ProjectileHelper.rayTraceEntities(entity, vector3d, vector3d2, axisalignedbb, (p_lambda$getMouseOver$0_0_) ->
            {
                return !p_lambda$getMouseOver$0_0_.isSpectator() && p_lambda$getMouseOver$0_0_.canBeCollidedWith();
            }, d1);

            if (entityraytraceresult != null) {
                Entity entity1 = entityraytraceresult.getEntity();
                Vector3d vector3d3 = entityraytraceresult.getHitVec();
                double d2 = vector3d.squareDistanceTo(vector3d3);

                if (flag && d2 > 9.0D) {
                    object = BlockRayTraceResult.createMiss(vector3d3, Direction.getFacingFromVector(vector3d1.x, vector3d1.y, vector3d1.z), new BlockPos(vector3d3));
                } else if (d2 < d1 || object == null) {
                    object = entityraytraceresult;
                }
            }
        }
        if (object instanceof EntityRayTraceResult) {
            return ((EntityRayTraceResult) object).getEntity().getEntityId() == target.getEntityId();
        }
        return false;
    }

    public static Vector3d getVectorForRotation(float pitch, float yaw) {
        float yawRadians = -yaw * ((float) Math.PI / 180) - (float) Math.PI;
        float pitchRadians = -pitch * ((float) Math.PI / 180);

        float cosYaw = MathHelper.cos(yawRadians);
        float sinYaw = MathHelper.sin(yawRadians);
        float cosPitch = -MathHelper.cos(pitchRadians);
        float sinPitch = MathHelper.sin(pitchRadians);

        return new Vector3d(sinYaw * cosPitch, sinPitch, cosYaw * cosPitch);
    }

}
 
Начинающий
Статус
Оффлайн
Регистрация
10 Май 2023
Сообщения
576
Реакции[?]
8
Поинты[?]
3K
красиво, но помогите, что означает "drawRoundedCorner" с exp 2.0 в 3.1?


(если я правильно понял это drawRectVerticalW)
 
Новичок
Статус
Оффлайн
Регистрация
30 Июл 2024
Сообщения
1
Реакции[?]
0
Поинты[?]
0
Начинающий
Статус
Оффлайн
Регистрация
31 Июл 2024
Сообщения
4
Реакции[?]
0
Поинты[?]
0
красиво, но помогите, что означает "drawRoundedCorner" с exp 2.0 в 3.1?


(если я правильно понял это drawRectVerticalW)
Просто метод который рисует квадрат с закругленными углами

Java:
public static void drawRoundedCorner(float x,
                                             float y,
                                             float width,
                                             float height,
                                             float radius,
                                             int color) {
            pushMatrix();
            enableBlend();
            ShaderUtil.CORNER_ROUND_SHADER.attach();

            ShaderUtil.CORNER_ROUND_SHADER.setUniform("size", (float) (width * 2), (float) (height * 2));
            ShaderUtil.CORNER_ROUND_SHADER.setUniform("round", radius * 2, radius * 2, radius * 2, radius * 2);

            ShaderUtil.CORNER_ROUND_SHADER.setUniform("smoothness", 0.f, 1.5f);
            ShaderUtil.CORNER_ROUND_SHADER.setUniform("color",
                    getRed(color) / 255f,
                    getGreen(color) / 255f,
                    getBlue(color) / 255f,
                    IntColor.getAlpha(color) / 255f);

            ShaderUtil.CORNER_ROUND_SHADER.drawQuads(x, y, width, height);

            ShaderUtil.CORNER_ROUND_SHADER.detach();
            disableBlend();
            popMatrix();
        }
 
Начинающий
Статус
Оффлайн
Регистрация
22 Сен 2023
Сообщения
43
Реакции[?]
0
Поинты[?]
0
Просто метод который рисует квадрат с закругленными углами

Java:
public static void drawRoundedCorner(float x,
                                             float y,
                                             float width,
                                             float height,
                                             float radius,
                                             int color) {
            pushMatrix();
            enableBlend();
            ShaderUtil.CORNER_ROUND_SHADER.attach();

            ShaderUtil.CORNER_ROUND_SHADER.setUniform("size", (float) (width * 2), (float) (height * 2));
            ShaderUtil.CORNER_ROUND_SHADER.setUniform("round", radius * 2, radius * 2, radius * 2, radius * 2);

            ShaderUtil.CORNER_ROUND_SHADER.setUniform("smoothness", 0.f, 1.5f);
            ShaderUtil.CORNER_ROUND_SHADER.setUniform("color",
                    getRed(color) / 255f,
                    getGreen(color) / 255f,
                    getBlue(color) / 255f,
                    IntColor.getAlpha(color) / 255f);

            ShaderUtil.CORNER_ROUND_SHADER.drawQuads(x, y, width, height);

            ShaderUtil.CORNER_ROUND_SHADER.detach();
            disableBlend();
            popMatrix();
        }
Селф код, переписуй в 1 строчку.
 
Начинающий
Статус
Оффлайн
Регистрация
10 Май 2023
Сообщения
576
Реакции[?]
8
Поинты[?]
3K
Просто метод который рисует квадрат с закругленными углами

Java:
public static void drawRoundedCorner(float x,
                                             float y,
                                             float width,
                                             float height,
                                             float radius,
                                             int color) {
            pushMatrix();
            enableBlend();
            ShaderUtil.CORNER_ROUND_SHADER.attach();

            ShaderUtil.CORNER_ROUND_SHADER.setUniform("size", (float) (width * 2), (float) (height * 2));
            ShaderUtil.CORNER_ROUND_SHADER.setUniform("round", radius * 2, radius * 2, radius * 2, radius * 2);

            ShaderUtil.CORNER_ROUND_SHADER.setUniform("smoothness", 0.f, 1.5f);
            ShaderUtil.CORNER_ROUND_SHADER.setUniform("color",
                    getRed(color) / 255f,
                    getGreen(color) / 255f,
                    getBlue(color) / 255f,
                    IntColor.getAlpha(color) / 255f);

            ShaderUtil.CORNER_ROUND_SHADER.drawQuads(x, y, width, height);

            ShaderUtil.CORNER_ROUND_SHADER.detach();
            disableBlend();
            popMatrix();
        }
нет, типо у меня база 3.1 , у меня немного по другому, я уже все перенес, если не ошибаюсь , это был: drawRoundedRect
 
Начинающий
Статус
Оффлайн
Регистрация
14 Июн 2024
Сообщения
44
Реакции[?]
1
Поинты[?]
1K
f
Приветики, написанный альт менеджер за 2 часа в студии



Java:
package name.ui.alt;

import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Session;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.StringTextComponent;
import org.apache.commons.lang3.RandomStringUtils;
import org.lwjgl.glfw.GLFW;
import name.util.MouseUtil;
import name.util.font.Fonts;
import name.util.render.*;
import name.util.render.animation.AnimationMath;

import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;

import static name.util.IMinecraft.mc;

public class AltManager extends Screen {

    public AltManager() {
        super(new StringTextComponent(""));
    }

    public ArrayList<Account> accounts = new ArrayList<>();

    public float scroll;
    public float scrollAn;

    private String altName = "";
    private boolean typing;

    @Override
    public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
        scrollAn = AnimationMath.lerp(scrollAn, scroll, 5);

        mc.gameRenderer.setupOverlayRendering(2);
        RenderUtil.Render2D.drawImage(new ResourceLocation("radix/images/backmenu.png"), 0, 0, mc.getMainWindow().scaledWidth(), mc.getMainWindow().scaledHeight(), -1);

        float offset = 6f;
        float width = 250f, height = 270f;
        float x = mc.getMainWindow().getScaledWidth() / 2f - width / 2f, y = mc.getMainWindow().getScaledHeight() / 2f - height / 2f;

        // Квадрат фона
        RenderUtil.Render2D.drawRoundedCorner(x - offset, y - offset, width + offset * 2f, height + offset * 2f, 5f, ColorUtil.rgba(22, 22, 22, 215));

        // Первый заголовок
        Fonts.icons1[22].drawString(matrixStack, "D", x + offset, y + offset + 1f, -1);
        Fonts.gilroyBold[22].drawString(matrixStack, "Добавьте новый аккаунт!", x + offset + Fonts.icons1[16].getWidth("D") + 6f, y + offset, -1);
        Fonts.gilroyBold[12].drawString(matrixStack, "Смени никнейм, и отправляйся в игру!", x + offset, y + offset + 18f, ColorUtil.rgb(180, 180, 180));

        // Квадратик для ввода ника
        RenderUtil.Render2D.drawRoundedCorner(x + offset, y + offset + 25f, width - offset * 2f, 20f, 2f, ColorUtil.rgba(60, 60, 60, 215));
        SmartScissor.push();
        SmartScissor.setFromComponentCoordinates(x + offset, y + offset + 25f, width - offset * 2f, 20f);
        Fonts.msSemiBold[15].drawString(matrixStack, typing ? (altName + (typing ? "|" : "")) : "Тут чота пусто =(", x + offset + 2f, y + offset + 32.5f, ColorUtil.rgb(152, 152, 152));
        SmartScissor.unset();
        SmartScissor.pop();

        // Знак для ввода рандомного ника
        Fonts.msBold[22].drawString(matrixStack, "?", x + width - offset - 12.5f, y + offset + 31f, -1);

        // Второй заголовок
        Fonts.gilroyBold[22].drawString(matrixStack, "Аккаунты:", x + offset, y + offset + 60f, -1);
        Fonts.gilroyBold[12].drawString(matrixStack, "Выбери аккаунт из списка!", x + offset, y + offset + 73f, ColorUtil.rgb(180, 180, 180));

        // Вывод никнеймов
        RenderUtil.Render2D.drawRoundedCorner(x + offset, y + offset + 80f, width - offset * 2f, 177.5f, 2f, ColorUtil.rgba(60, 60, 60, 215));

        // Надпись при пустом листе аккаунтов
        if (accounts.isEmpty()) Fonts.msBold[22].drawCenteredString(matrixStack, "А где...", x + width / 2f, y + offset + 165.75f, -1);

        // Основной функционал для показа аккаунтов
        float size = 0f, iter = scrollAn, offsetAccounts = 0f;
        SmartScissor.push();
        SmartScissor.setFromComponentCoordinates(x + offset, y + offset + 80f, width - offset * 2f, 177.5f);
        for (Account account : accounts) {
            float scrollY = y + iter * 22f;

            RenderUtil.Render2D.drawRoundedRect(x + offset + 2f, scrollY + offset + 82f + offsetAccounts, width - offset * 2f - 4f, 20f, 2f, ColorUtil.rgb(101, 101, 101));

            Fonts.msSemiBold[16].drawString(matrixStack, account.accountName, x + offset + 25f, scrollY + offset + 82f + 8f + offsetAccounts, -1);

            StencilUtil.initStencilToWrite();
            RenderUtil.Render2D.drawRoundedRect(x + offset + 4f + 0.5f, scrollY + offset + 84f + offsetAccounts, 16, 16, 2f, Color.BLACK.getRGB());
            StencilUtil.readStencilBuffer(1);
            mc.getTextureManager().bindTexture(account.skin);
            AbstractGui.drawScaledCustomSizeModalRect(x + offset + 4f + 0.5f, scrollY + offset + 84f + offsetAccounts, 8F, 8F, 8F, 8F, 16, 16, 64, 64);
            StencilUtil.uninitStencilBuffer();

            iter++;
            size++;
        }
        scroll = MathHelper.clamp(scroll, size > 8 ? -size + 4 : 0, 0);
        SmartScissor.unset();
        SmartScissor.pop();

        // Показ текущего ника
        Fonts.gilroyBold[12].drawString(matrixStack, "Ваш ник - " + mc.session.getUsername() + ".", x + offset, y + height - offset / 2, ColorUtil.rgb(180, 180, 180));

        mc.gameRenderer.setupOverlayRendering();
    }

    @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 (keyCode == GLFW.GLFW_KEY_BACKSPACE) {
            if (!altName.isEmpty() && typing)
                altName = altName.substring(0, altName.length() - 1);
        }

        if (keyCode == GLFW.GLFW_KEY_ENTER) {
            if (!altName.isEmpty()) {
                accounts.add(new Account(altName));
                AltConfig.updateFile();
            }
            typing = false;
            altName = "";
        }

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

    @Override
    public boolean charTyped(char codePoint, int modifiers) {
        if (altName.length() <= 20) altName += Character.toString(codePoint);
        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();

        float offset = 6f;
        float width = 250f, height = 270f;
        float x = mc.getMainWindow().getScaledWidth() / 2f - width / 2f, y = mc.getMainWindow().getScaledHeight() / 2f - height / 2f;

        if (RenderUtil.isInRegion(mouseX, mouseY, x + width - offset - 12.5f, y + offset + 31f, Fonts.msBold[22].getWidth("?"), Fonts.msBold[22].getFontHeight())) {
            accounts.add(new Account(RandomStringUtils.randomAlphabetic(8)));
            AltConfig.updateFile();
        }
        if (RenderUtil.isInRegion(mouseX, mouseY, x + offset, y + offset + 25f, width - offset * 2f, 20f) && !RenderUtil.isInRegion(mouseX, mouseY, x + width - offset - 12.5f, y + offset + 31f, Fonts.msBold[22].getWidth("?"), Fonts.msBold[22].getFontHeight())) {
            typing = !typing;
        }

        // Основной функционал позволяющий позволяющий брать/удалять ник
        float iter = scrollAn, offsetAccounts = 0f;
        Iterator<Account> iterator = accounts.iterator();
        while (iterator.hasNext()) {
            Account account = iterator.next();

            float scrollY = y + iter * 22f;

            if (RenderUtil.isInRegion(mouseX, mouseY, x + offset + 2f, scrollY + offset + 82f + offsetAccounts, width - offset * 2f - 4f, 20f)) {
                if (button == 0) {
                    mc.session = new Session(account.accountName, "", "", "mojang");
                } else if (button == 1) {
                    iterator.remove();
                    AltConfig.updateFile();
                }
            }

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

    @Override
    public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
        Vec2i fixed = ScaleMath.getMouse((int) mouseX, (int) mouseY);
        mouseX = fixed.getX();
        mouseY = fixed.getY();

        // Скролл
        float offset = 6f;
        float width = 250f, height = 270f;
        float x = mc.getMainWindow().getScaledWidth() / 2f - width / 2f, y = mc.getMainWindow().getScaledHeight() / 2f - height / 2f;

        if (MouseUtil.isHovered(mouseX, mouseY, x + offset, y + offset + 80f, width - offset * 2f, 177.5f)) scroll += delta * 1;
        return super.mouseScrolled(mouseX, mouseY, delta);
    }

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

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

    @Override
    public void tick() {
        super.tick();
    }
}
а почему текста нету еще когда добаю ник ничего не появляется текст ника как я пишу?
 

Вложения

Сверху Снизу