Начинающий
- Статус
- Оффлайн
- Регистрация
- 13 Май 2025
- Сообщения
- 71
- Реакции
- 1
- Выберите загрузчик игры
- Прочие моды
Java:
package i.chuppachups.deadcore.Other.RenderOverlay.mainmenu;
import i.chuppachups.deadcode.Main.Ready;
import i.chuppachups.deadcode.Other.Utility.Helper.SoundPlayer;
import i.chuppachups.deadcode.Other.Utility.Rendering.ColorHelper.ColorUtility;
import i.chuppachups.deadcode.Other.Utility.Rendering.FontRender.Normal.ClientFonts;
import i.chuppachups.deadcode.Other.Utility.Rendering.RenderHelper.RenderUtility;
import i.chuppachups.deadcode.Other.Utility.Helper.ClientUtility;
import i.chuppachups.deadcode.Other.Utility.Math.MathUtility;
import i.chuppachups.deadcode.Other.Utility.Math.Vector2i;
import i.chuppachups.deadcode.Other.Helper.blaze3d.matrix.MatrixStack;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.*;
import net.minecraft.util.text.ITextComponent;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static i.chuppachups.deadcode.Other.Utility.Helper.IMinecraft.mc;
public class MainScreen extends Screen {
public MainScreen() {
super(ITextComponent.getTextComponentOrEmpty(""));
}
private final List<Button> buttons = new ArrayList<>();
private static final int CLOSE_SIZE = 20;
private static final int CLOSE_PADDING = 5;
private boolean closeHovered = false;
@Override
public void init(Minecraft minecraft, int width, int height) {
super.init(minecraft, width, height);
float offset = 4f;
float fullWidth = 200f;
float halfWidth = 90f;
float heightButton = 24f;
float centerX = width / 2f;
float col1X = centerX - 88 - offset;
float col2X = centerX - fullWidth / 2;
float col3X = centerX - fullWidth / 2;
float yStart = height / 2f - (heightButton * 2 + offset) / 2f;
buttons.clear();
buttons.add(new Button(col2X, yStart, halfWidth + 8, heightButton, "Singleplayer", () -> mc.displayGuiScreen(new WorldSelectionScreen(this))));
buttons.add(new Button(col1X + halfWidth + offset , yStart, halfWidth + 8, heightButton, "Multiplayer", () -> mc.displayGuiScreen(new MultiplayerScreen(this))));
buttons.add(new Button(col2X, yStart + 34, fullWidth, heightButton, "Alt Manager", () -> mc.displayGuiScreen(Ready.getInst().getAltScreen())));
buttons.add(new Button(col3X, yStart + 68, fullWidth, heightButton, "Options", () -> mc.displayGuiScreen(new OptionsScreen(this, mc.gameSettings))));
}
@Override
public void resize(Minecraft minecraft, int width, int height) {
super.resize(minecraft, width, height);
this.init(minecraft, width, height);
}
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
super.render(matrixStack, mouseX, mouseY, partialTicks);
mc.gameRenderer.setupOverlayRendering(2);
MainWindow mainWindow = mc.getMainWindow();
int windowWidth = mainWindow.getScaledWidth();
int windowHeight = mainWindow.getScaledHeight();
// Background
RenderUtility.drawRoundedRect(0, 0, windowWidth, windowHeight, 0, ColorUtility.rgba(21, 21, 21, 255));
RenderUtility.drawSimpleRectOutline(windowWidth / 2f - 140, windowHeight / 2f - 90, 280, 180, 0.6f, new Color(255, 255, 255, 255).getRGB());
ClientFonts.deadcode1[75].drawCenteredString(matrixStack, "DEADCODE", windowWidth / 2f, windowHeight / 2f - 70, -1);
Vector2i fixed = ClientUtility.getMouse(mouseX, mouseY);
drawButtons(matrixStack, fixed.getX(), fixed.getY(), partialTicks);
int closeX = windowWidth - CLOSE_SIZE - CLOSE_PADDING ;
int closeY = CLOSE_PADDING;
closeHovered = MathUtility.isHovered(mouseX, mouseY, 608, 160f, CLOSE_SIZE, CLOSE_SIZE);
int bgColor = closeHovered ? Color.RED.getRGB() : Color.WHITE.getRGB();
RenderUtility.drawRoundedRect(608, 160, 16, 16,0, bgColor);
String cross = "X";
int fontSize = 22;
ClientFonts.msBold[fontSize].drawCenteredString(matrixStack, cross,
606.5f + CLOSE_SIZE / 2f,
160f + (CLOSE_SIZE - ClientFonts.msBold[fontSize].getFontHeight()) / 2f,
closeHovered ? Color.WHITE.getRGB() : Color.BLACK.getRGB());
mc.gameRenderer.setupOverlayRendering();
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (button == 0) {
MainWindow mainWindow = mc.getMainWindow();
int windowWidth = mainWindow.getScaledWidth();
int closeX = windowWidth - CLOSE_SIZE - CLOSE_PADDING;
int closeY = CLOSE_PADDING;
if (MathUtility.isHovered((int) mouseX, (int) mouseY, closeX, closeY, CLOSE_SIZE, CLOSE_SIZE)) {
mc.shutdownMinecraftApplet();
return true;
}
for (Button b : buttons) {
b.click((int) mouseX, (int) mouseY, button);
}
}
return super.mouseClicked(mouseX, mouseY, button);
}
private void drawButtons(MatrixStack stack, int mX, int mY, float pt) {
buttons.forEach(b -> b.render(stack, mX, mY, pt));
}
private class Button {
private final float x, y, width, height;
private final String text;
private final Runnable action;
private boolean isGlitching = false;
private int glitchCharIndex = 0;
private int glitchCharFrame = 0;
private final int glitchCharFramesMax = 5;
private long lastGlitchTime = 0;
private final long glitchInterval = 10;
private boolean wasHoveredLastFrame = false;
public Button(float x, float y, float width, float height, String text, Runnable action) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.text = text;
this.action = action;
}
public void render(MatrixStack stack, int mouseX, int mouseY, float pt) {
float offset = 1.5f;
float textY = (float) (y + 2 + height / 2 - ClientFonts.deadcode[22].getFontHeight() / 2);
boolean hovered = MathUtility.isHovered(mouseX, mouseY, x, y, width, height);
if (hovered && !wasHoveredLastFrame) {
isGlitching = true;
glitchCharIndex = 0;
glitchCharFrame = 0;
lastGlitchTime = System.currentTimeMillis();
}
wasHoveredLastFrame = hovered;
String renderText = text;
if (isGlitching) {
long now = System.currentTimeMillis();
if (now - lastGlitchTime >= glitchInterval) {
lastGlitchTime = now;
glitchCharFrame++;
if (glitchCharFrame >= glitchCharFramesMax) {
glitchCharFrame = 0;
glitchCharIndex++;
}
if (glitchCharIndex >= text.length()) {
isGlitching = false;
glitchCharIndex = 0;
glitchCharFrame = 0;
}
}
renderText = buildGlitchText(text, glitchCharIndex, glitchCharFrame, glitchCharFramesMax);
}
int borderColor = hovered ? Color.BLUE.getRGB() : new Color(225, 255, 255, 255).getRGB();
int textColor = hovered ? Color.GREEN.getRGB() : ColorUtility.rgba(255, 255, 255, 255);
RenderUtility.drawSimpleRectOutline(x, y, width, height, 0.8f, borderColor);
ClientFonts.deadcode[27].drawCenteredString(stack, renderText, x + width / 2f, textY, textColor);
}
public void click(int mouseX, int mouseY, int button) {
if (MathUtility.isHovered(mouseX, mouseY, x, y, width, height)) {
action.run();
SoundPlayer.playSound("buttonclick.wav", .1f);
}
}
private String buildGlitchText(String base, int glitchIndex, int glitchFrame, int maxFrames) {
StringBuilder sb = new StringBuilder();
int length = base.length();
for (int i = 0; i < length; i++) {
if (i < glitchIndex) {
sb.append(base.charAt(i));
} else if (i == glitchIndex) {
if (glitchFrame == 0) {
sb.append(base.charAt(i));
} else {
sb.append(randomChar());
}
} else {
sb.append(base.charAt(i));
}
}
return sb.toString();
}
private char randomChar() {
return (char) (33 + (int) (Math.random() * 30));
}
}
}
fonts
Пожалуйста, авторизуйтесь для просмотра ссылки.
Последнее редактирование: