Начинающий
- Статус
- Оффлайн
- Регистрация
- 12 Мар 2026
- Сообщения
- 19
- Реакции
- 0
- Выберите загрузчик игры
- Vanilla
- OptiFine
Всем привет, попытался сделать MainMenu, как в wexside, вроде норм, а вроде калл. Для пастеров пойдет
SS -
Code -
SS -
Code -
MainScreen:
package im.expensive.ui.mainmenu;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import im.expensive.Expensive;
import im.expensive.utils.client.ClientUtil;
import im.expensive.utils.client.IMinecraft;
import im.expensive.utils.client.Vec2i;
import im.expensive.utils.math.MathUtil;
import im.expensive.utils.math.StopWatch;
import im.expensive.utils.render.ColorUtils;
import im.expensive.utils.render.DisplayUtils;
import im.expensive.utils.render.KawaseBlur;
import im.expensive.utils.render.Scissor;
import im.expensive.utils.render.Stencil;
import im.expensive.utils.render.font.Fonts;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.MultiplayerScreen;
import net.minecraft.client.gui.screen.OptionsScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.WorldSelectionScreen;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Session;
import net.minecraft.util.Util;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ThreadLocalRandom;
public class MainScreen extends Screen implements IMinecraft {
public MainScreen() {
super(ITextComponent.getTextComponentOrEmpty(""));
}
private final ResourceLocation backmenu = new ResourceLocation("expensive/images/backmenu.png");
private final ResourceLocation logo = new ResourceLocation("expensive/images/logo.png");
private final List<Button> buttons = new ArrayList<>();
private final List<TextButton> textButtons = new ArrayList<>();
private static final CopyOnWriteArrayList<Particle> particles = new CopyOnWriteArrayList<>();
private final StopWatch stopWatch = new StopWatch();
private static final String PRIVACY_URL = "ваша ссылка";
private static final String TERMS_URL = "ваша ссылка";
private boolean isAltMenuOpen = false;
private String altNameInput = "";
private float scrollAlts = 0;
@Override
public void init(Minecraft minecraft, int width, int height) {
super.init(minecraft, width, height);
float scale = 0.8f;
float btnW = 280f * scale;
float btnH = 34f * scale;
float space = 6 * scale;
for (Particle p : particles) {
p.y = ThreadLocalRandom.current().nextInt(-5, height);
}
float x = ClientUtil.calc(width) / 2f - btnW / 2f;
float y = Math.round(ClientUtil.calc(height) / 2f);
buttons.clear();
textButtons.clear();
buttons.add(new Button(x, y, btnW, btnH, "singleplayer", () -> mc.displayGuiScreen(new WorldSelectionScreen(this))));
y += btnH + space;
buttons.add(new Button(x, y, btnW, btnH, "multiplayer", () -> mc.displayGuiScreen(new MultiplayerScreen(this))));
y += btnH + space;
buttons.add(new Button(x, y, btnW, btnH, "Swap Accounts", () -> isAltMenuOpen = true));
y += btnH + space + (4 * scale);
float txtBtnW = 45f * scale;
float txtBtnH = 15f * scale;
textButtons.add(new TextButton(x, y, txtBtnW, txtBtnH, "Options", () -> mc.displayGuiScreen(new OptionsScreen(this, mc.gameSettings))));
textButtons.add(new TextButton(x + (btnW / 2f) - (txtBtnW / 2f), y, txtBtnW, txtBtnH, "Proxies", () -> {}));
textButtons.add(new TextButton(x + btnW - txtBtnW, y, txtBtnW, txtBtnH, "Exit", mc::shutdownMinecraftApplet));
}
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
if (isAltMenuOpen) {
scrollAlts += delta * 20;
return true;
}
return super.mouseScrolled(mouseX, mouseY, delta);
}
@Override
public void render(MatrixStack stack, int mouseX, int mouseY, float pt) {
super.render(stack, mouseX, mouseY, pt);
if (stopWatch.isReached(100)) {
particles.add(new Particle());
stopWatch.reset();
}
DisplayUtils.drawImage(backmenu, 0, 0, width, height, -1);
mc.gameRenderer.setupOverlayRendering(2);
particles.forEach(p -> p.render(stack));
float headSize = 22f;
float pX = 15f;
float pY = 15f;
Stencil.initStencilToWrite();
RenderSystem.disableTexture();
GL11.glBegin(GL11.GL_POLYGON);
for (int i = 0; i <= 360; i += 2) {
double rad = Math.toRadians(i);
GL11.glVertex2d(pX + headSize / 2f + Math.sin(rad) * (headSize / 2f), pY + headSize / 2f + Math.cos(rad) * (headSize / 2f));
}
GL11.glEnd();
RenderSystem.enableTexture();
Stencil.readStencilBuffer(1);
RenderSystem.color4f(1, 1, 1, 1);
ResourceLocation skin = DefaultPlayerSkin.getDefaultSkin(mc.getSession().getProfile().getId());
mc.getTextureManager().bindTexture(skin);
AbstractGui.blit(stack, (int)pX, (int)pY, (int)headSize, (int)headSize, 8, 8, 8, 8, 64, 64);
AbstractGui.blit(stack, (int)pX, (int)pY, (int)headSize, (int)headSize, 40, 8, 8, 8, 64, 64);
Stencil.uninitStencilBuffer();
float tx = pX + headSize + 8f;
Fonts.montserrat.drawText(stack, "Logged in as", tx, pY + 2, ColorUtils.rgb(120, 120, 130), 8f);
Fonts.montserrat.drawText(stack, mc.getSession().getUsername(), tx, pY + 12, -1, 10f);
float scale = 0.8f;
float cX = ClientUtil.calc(width) / 2f;
float cY = ClientUtil.calc(height) / 2f - 40 * scale;
int lSize = (int)(32 * scale);
DisplayUtils.drawImage(logo, cX - lSize / 2f, cY - 45f * scale, lSize, lSize, -1);
String m1 = "Good time of day, ";
String m2 = mc.getSession().getUsername();
float m1W = Fonts.montserrat.getWidth(m1, 14f * scale);
float tW = m1W + Fonts.montserrat.getWidth(m2, 14f * scale);
float sX = cX - tW / 2f;
Fonts.montserrat.drawText(stack, m1, sX, cY, -1, 14f * scale);
Fonts.montserrat.drawText(stack, m2, sX + m1W, cY, -1, 14f * scale);
cY += 20 * scale;
String s1 = "Welcome to ";
String s2 = "Svintus";
String s3 = ", the best Minecraft client.";
float subW = Fonts.montserrat.getWidth(s1 + s2 + s3, 10f * scale);
float subX = cX - subW / 2f;
Fonts.montserrat.drawText(stack, s1, subX, cY, ColorUtils.rgb(180, 180, 180), 10f * scale);
Fonts.montserrat.drawText(stack, s2, subX + Fonts.montserrat.getWidth(s1, 10f * scale), cY, ColorUtils.rgb(230, 92, 0), 10f * scale);
Fonts.montserrat.drawText(stack, s3, subX + Fonts.montserrat.getWidth(s1 + s2, 10f * scale), cY, ColorUtils.rgb(180, 180, 180), 10f * scale);
KawaseBlur.blur.updateBlur(3, 4);
buttons.forEach(b -> b.render(stack, mouseX, mouseY, pt));
textButtons.forEach(b -> b.render(stack, mouseX, mouseY, pt));
String f1 = "By logging into your account you agree to all of our policies, Including our ";
String f2 = "Privacy Policy";
String f3 = " and ";
String f4 = "Terms of Service";
float fY = ClientUtil.calc(height) - 30 * scale;
float fSX = cX - Fonts.montserrat.getWidth(f1 + f2 + f3 + f4, 8f * scale) / 2f;
float l2X = fSX + Fonts.montserrat.getWidth(f1, 8f * scale);
float l4X = l2X + Fonts.montserrat.getWidth(f2, 8f * scale) + Fonts.montserrat.getWidth(f3, 8f * scale);
boolean hPP = MathUtil.isHovered((float) mouseX, (float) mouseY, l2X, fY, Fonts.montserrat.getWidth(f2, 8f * scale), 10f * scale);
boolean hToU = MathUtil.isHovered((float) mouseX, (float) mouseY, l4X, fY, Fonts.montserrat.getWidth(f4, 8f * scale), 10f * scale);
int hC = ColorUtils.rgb(255, 255, 255);
int lC = ColorUtils.rgb(180, 180, 180);
Fonts.montserrat.drawText(stack, f1, fSX, fY, ColorUtils.rgb(100, 100, 110), 8f * scale);
Fonts.montserrat.drawText(stack, f2, l2X, fY, hPP ? hC : lC, 8f * scale);
Fonts.montserrat.drawText(stack, f3, l2X + Fonts.montserrat.getWidth(f2, 8f * scale), fY, ColorUtils.rgb(100, 100, 110), 8f * scale);
Fonts.montserrat.drawText(stack, f4, l4X, fY, hToU ? hC : lC, 8f * scale);
if (isAltMenuOpen) {
DisplayUtils.drawRect(0, 0, width, height, ColorUtils.rgba(0, 0, 0, 150));
float wW = 220;
float wH = 280;
float wX = ClientUtil.calc(width) / 2f - wW / 2f;
float wY = ClientUtil.calc(height) / 2f - wH / 2f;
DisplayUtils.drawRoundedRect(wX, wY, wW, wH, 8, ColorUtils.rgb(20, 22, 30));
Fonts.montserrat.drawCenteredText(stack, "Account Manager", wX + wW / 2f, wY + 15, -1, 12f);
DisplayUtils.drawRoundedRect(wX + 15, wY + 35, wW - 70, 22, 4, ColorUtils.rgb(30, 33, 44));
String dStr = altNameInput.isEmpty() ? "Nickname..." : altNameInput;
int tC = altNameInput.isEmpty() ? ColorUtils.rgb(120, 120, 130) : -1;
String cur = (System.currentTimeMillis() % 1000 > 500 && !altNameInput.isEmpty()) ? "_" : "";
Fonts.montserrat.drawText(stack, dStr + cur, wX + 22, wY + 42, tC, 10f);
boolean aHov = MathUtil.isHovered((float)mouseX, (float)mouseY, wX + wW - 45, wY + 35, 30, 22);
DisplayUtils.drawRoundedRect(wX + wW - 45, wY + 35, 30, 22, 4, aHov ? ColorUtils.rgb(255, 110, 20) : ColorUtils.rgb(230, 92, 0));
Fonts.montserrat.drawCenteredText(stack, "Add", wX + wW - 30, wY + 42, -1, 9f);
Scissor.push();
Scissor.setFromComponentCoordinates(wX, wY + 65, wW, wH - 75);
float cY_alt = wY + 70 + scrollAlts;
for (Alt alt : Expensive.getInstance().getAltWidget().alts) {
boolean isCur = mc.session.getUsername().equals(alt.name);
boolean rHov = MathUtil.isHovered((float)mouseX, (float)mouseY, wX + 15, cY_alt, wW - 30, 24);
int rCol = isCur ? ColorUtils.rgb(230, 92, 0) : (rHov ? ColorUtils.rgb(40, 44, 58) : ColorUtils.rgb(30, 33, 44));
DisplayUtils.drawRoundedRect(wX + 15, cY_alt, wW - 30, 24, 4, rCol);
Fonts.montserrat.drawText(stack, alt.name, wX + 25, cY_alt + 7, -1, 10f);
boolean dHov = MathUtil.isHovered((float)mouseX, (float)mouseY, wX + wW - 35, cY_alt + 4, 16, 16);
Fonts.montserrat.drawText(stack, "X", wX + wW - 25, cY_alt + 7, dHov ? ColorUtils.rgb(255, 50, 50) : ColorUtils.rgb(180, 50, 50), 10f);
cY_alt += 28;
}
Scissor.unset();
Scissor.pop();
}
mc.gameRenderer.setupOverlayRendering();
}
@Override
public boolean charTyped(char codePoint, int modifiers) {
if (isAltMenuOpen) {
if (Fonts.montserrat.getWidth(altNameInput, 10f) < 130) {
altNameInput += codePoint;
}
return true;
}
return super.charTyped(codePoint, modifiers);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (isAltMenuOpen) {
if (keyCode == GLFW.GLFW_KEY_BACKSPACE && !altNameInput.isEmpty()) {
altNameInput = altNameInput.substring(0, altNameInput.length() - 1);
} else if (keyCode == GLFW.GLFW_KEY_ENTER) {
if (altNameInput.length() >= 3) {
Expensive.getInstance().getAltWidget().alts.add(new Alt(altNameInput));
AltConfig.updateFile();
altNameInput = "";
}
} else if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
isAltMenuOpen = false;
}
return true;
}
return false;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (isAltMenuOpen) {
float wW = 220;
float wH = 280;
float wX = ClientUtil.calc(width) / 2f - wW / 2f;
float wY = ClientUtil.calc(height) / 2f - wH / 2f;
if (!MathUtil.isHovered((float)mouseX, (float)mouseY, wX, wY, wW, wH)) {
isAltMenuOpen = false;
return true;
}
if (MathUtil.isHovered((float)mouseX, (float)mouseY, wX + wW - 45, wY + 35, 30, 22)) {
if (altNameInput.length() >= 3) {
Expensive.getInstance().getAltWidget().alts.add(new Alt(altNameInput));
AltConfig.updateFile();
altNameInput = "";
}
return true;
}
float cY = wY + 70 + scrollAlts;
Alt toRemove = null;
for (Alt alt : Expensive.getInstance().getAltWidget().alts) {
if (mouseY > wY + 65 && mouseY < wY + wH - 10) {
if (MathUtil.isHovered((float)mouseX, (float)mouseY, wX + wW - 35, cY + 4, 16, 16)) {
toRemove = alt;
}
else if (MathUtil.isHovered((float)mouseX, (float)mouseY, wX + 15, cY, wW - 30, 24)) {
mc.session = new Session(alt.name, UUID.randomUUID().toString(), "", "mojang");
AltConfig.updateFile();
}
}
cY += 28;
}
if (toRemove != null) {
Expensive.getInstance().getAltWidget().alts.remove(toRemove);
AltConfig.updateFile();
}
return true;
}
Vec2i fixed = ClientUtil.getMouse((int) mouseX, (int) mouseY);
buttons.forEach(b -> b.click(fixed.getX(), fixed.getY(), button));
textButtons.forEach(b -> b.click(fixed.getX(), fixed.getY(), button));
float scale = 0.8f;
float cX = ClientUtil.calc(width) / 2f;
float fY = ClientUtil.calc(height) - 30 * scale;
String f1 = "By logging into your account you agree to all of our policies, Including our ";
String f2 = "Privacy Policy";
String f3 = " and ";
String f4 = "Terms of Service";
float fSX = cX - Fonts.montserrat.getWidth(f1 + f2 + f3 + f4, 8f * scale) / 2f;
float l2X = fSX + Fonts.montserrat.getWidth(f1, 8f * scale);
float l4X = l2X + Fonts.montserrat.getWidth(f2, 8f * scale) + Fonts.montserrat.getWidth(f3, 8f * scale);
if (MathUtil.isHovered((float) mouseX, (float) mouseY, l2X, fY, Fonts.montserrat.getWidth(f2, 8f * scale), 10f * scale) && button == 0) {
Util.getOSType().openURI(PRIVACY_URL);
} else if (MathUtil.isHovered((float) mouseX, (float) mouseY, l4X, fY, Fonts.montserrat.getWidth(f4, 8f * scale), 10f * scale) && button == 0) {
Util.getOSType().openURI(TERMS_URL);
}
return super.mouseClicked(mouseX, mouseY, button);
}
private class Particle {
private final float x;
private float y;
private float size;
public Particle() {
x = ThreadLocalRandom.current().nextInt(0, mc.getMainWindow().getScaledWidth());
y = 0;
size = 0;
}
public void render(MatrixStack stack) {
size += 0.1f;
GlStateManager.pushMatrix();
GlStateManager.translated((x + Math.sin((System.nanoTime() / 1000000000f)) * 5), y, 0);
GlStateManager.rotatef(size * 20, 0, 0, 1);
GlStateManager.translated(-(x + Math.sin((System.nanoTime() / 1000000000f)) * 5), -y, 0);
float multi = 1 - MathHelper.clamp((y / mc.getMainWindow().getScaledHeight()), 0, 1);
y += 1;
Fonts.damage.drawText(stack, "A", (float) (x + Math.sin((System.nanoTime() / 1000000000f)) * 5), y, -1, MathHelper.clamp(size * multi, 0, 9));
GlStateManager.popMatrix();
if (y >= mc.getMainWindow().getScaledHeight()) {
particles.remove(this);
}
}
}
@AllArgsConstructor
private class Button {
@Getter
private final float x, y, width, height;
private String text;
private Runnable action;
public void render(MatrixStack stack, int mouseX, int mouseY, float pt) {
float s = 0.8f;
int color = ColorUtils.rgb(180, 180, 180);
int bgColor = text.equals("Swap Accounts") ? ColorUtils.rgb(230, 92, 0) : ColorUtils.rgb(30, 33, 44);
if (MathUtil.isHovered((float) mouseX, (float) mouseY, x, y, width, height)) {
color = ColorUtils.rgb(255, 255, 255);
}
DisplayUtils.drawRoundedRect(x, y, width, height, 4f * s, bgColor);
Fonts.montserrat.drawCenteredText(stack, text, x + width / 2f, y + height / 2f - 4f, color, 10f * s);
}
public void click(int mouseX, int mouseY, int button) {
if (MathUtil.isHovered((float) mouseX, (float) mouseY, x, y, width, height) && button == 0) {
action.run();
}
}
}
@AllArgsConstructor
private class TextButton {
private final float x, y, width, height;
private String text;
private Runnable action;
public void render(MatrixStack stack, int mouseX, int mouseY, float pt) {
float s = 0.8f;
int color = MathUtil.isHovered((float) mouseX, (float) mouseY, x, y, width, height) ? ColorUtils.rgb(255, 255, 255) : ColorUtils.rgb(120, 120, 130);
Fonts.montserrat.drawCenteredText(stack, text, x + width / 2f, y + height / 2f - 4f, color, 9f * s);
}
public void click(int mouseX, int mouseY, int button) {
if (MathUtil.isHovered((float) mouseX, (float) mouseY, x, y, width, height) && button == 0) {
action.run();
}
}
}
}