Пытаюсь отрендерить картинку позади кнопок но почему то перекрывает кнопки(База Zenith Recode).
Java:
package zenith.zov.client.screens.main;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import zenith.zov.Zenith;
import zenith.zov.base.font.Font;
import zenith.zov.base.font.Fonts;
import zenith.zov.base.theme.Theme;
import zenith.zov.utility.render.display.Render2DUtil;
import zenith.zov.utility.render.display.base.BorderRadius;
import zenith.zov.utility.render.display.base.CustomDrawContext;
import zenith.zov.utility.render.display.base.color.ColorRGBA;
import zenith.zov.utility.render.display.base.color.ColorUtil;
import java.awt.*;
import java.util.function.Function;
import static zenith.zov.utility.interfaces.IMinecraft.mc;
@SuppressWarnings("All")
public class MainMenu extends Screen {
private Button singleplayerButton;
private Button multiplayerButton;
private Button altmanagerButton;
private CombinedButton optionsQuitButton;
private final String title = "Govno";
private int shakeTime = 0;
private float shakeOffsetY = 0f;
private static final float TEXT_SHIFT_X = 0f;
Font bold = Fonts.INTER_SEMIBOLD.getFont(7);
Font medium = Fonts.INTER_MEDIUM.getFont(7);
private static final Identifier BACKGROUND =
Identifier.of("zenith", "gui/mainmenu_bg.png");
public MainMenu() {
super(Text.literal("Custom Main Menu"));
}
@Override
protected void init() {
int buttonWidth = 150;
int buttonHeight = 25;
singleplayerButton = new Button("Singleplayer", 0, 0, buttonWidth, buttonHeight);
multiplayerButton = new Button("Multiplayer", 0, 0, buttonWidth, buttonHeight);
altmanagerButton = new Button("AltManager", 0, 0, buttonWidth, buttonHeight);
optionsQuitButton = new CombinedButton(0, 0, buttonWidth, buttonHeight, "Options", "Quit");
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
context.getMatrices().push();
context.getMatrices().translate(0, 0, -5);
context.drawTexture(RenderLayer::getGuiTexturedOverlay,
BACKGROUND,
0, 0, 0, 0, width, height, width, height
);
context.getMatrices().pop();
if (shakeTime > 0) {
shakeTime--;
shakeOffsetY = (float) (Math.sin(shakeTime * 0.5) * 3);
} else shakeOffsetY = 0;
Theme theme = Zenith.getInstance().getThemeManager().getCurrentTheme();
float titleWidth = Fonts.INTER_SEMIBOLD.getWidth(title, 7);
float titleX = (width - titleWidth) / 2f;
float titleY = height / 5f + shakeOffsetY;
CustomDrawContext cdc = new CustomDrawContext(mc.getBufferBuilders().getEntityVertexConsumers());
cdc.drawText(bold, title, titleX, titleY, theme.getBackgroundColor());
int buttonWidth = 150;
int buttonHeight = 25;
int spacing = 12;
float startY = height / 5f + 54 + spacing * 2;
int centerX = width / 2 - buttonWidth / 2;
singleplayerButton.set(centerX, (int) startY);
multiplayerButton.set(centerX, (int) (startY + buttonHeight + spacing));
altmanagerButton.set(centerX, (int) (startY + 2 * (buttonHeight + spacing)));
optionsQuitButton.x = centerX;
optionsQuitButton.y = (int) (startY + 3 * (buttonHeight + spacing));
optionsQuitButton.width = buttonWidth;
singleplayerButton.render(context, mouseX, mouseY, delta);
multiplayerButton.render(context, mouseX, mouseY, delta);
altmanagerButton.render(context, mouseX, mouseY, delta);
optionsQuitButton.render(context, mouseX, mouseY, delta);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (singleplayerButton.isHovered(mouseX, mouseY)) {
client.setScreen(new SelectWorldScreen(this));
return true;
}
if (multiplayerButton.isHovered(mouseX, mouseY)) {
client.setScreen(new MultiplayerScreen(this));
return true;
}
if (optionsQuitButton.isOptionHovered(mouseX, mouseY)) {
client.setScreen(new OptionsScreen(this, client.options));
return true;
}
if (optionsQuitButton.isQuitHovered(mouseX, mouseY)) {
client.scheduleStop();
return true;
}
return super.mouseClicked(mouseX, mouseY, button);
}
private class Button {
final String name;
int x, y, width, height;
float hoverAnim = 0f;
float scale = 1f;
Button(String name, int x, int y, int w, int h) {
this.name = name;
this.x = x;
this.y = y;
this.width = w;
this.height = h;
}
void set(int x, int y) {
this.x = x;
this.y = y;
}
void render(DrawContext ctx, int mx, int my, float delta) {
boolean hovered = isHovered(mx, my);
hoverAnim += hovered ? 0.04f : -0.04f;
hoverAnim = Math.max(0, Math.min(1, hoverAnim));
scale = hovered ? 1.02f : 1f;
int bg = ColorUtil.blend(
new Color(35, 35, 35).getRGB(),
new Color(55, 55, 55).getRGB(),
hoverAnim
);
ctx.getMatrices().push();
ctx.getMatrices().translate(x + width / 2f, y + height / 2f, 0);
ctx.getMatrices().scale(scale, scale, 1);
ctx.getMatrices().translate(-(x + width / 2f), -(y + height / 2f), 0);
CustomDrawContext cdc = new CustomDrawContext(mc.getBufferBuilders().getEntityVertexConsumers());
cdc.drawRoundedRect(x, y, width, height, new BorderRadius(4, 4, 4, 4), new ColorRGBA(bg));
cdc.drawRoundedBorder(x, y, width, height, 0.1f, new BorderRadius(4, 4, 4 ,4),
new ColorRGBA(60, 60, 60, 180));
float textWidth = Fonts.INTER_MEDIUM.getWidth(name, 7);
float textX = x + (width - textWidth) / 2f + TEXT_SHIFT_X;
float textY = y + (height - 9) / 2f + 2;
cdc.drawText(medium, name, textX, textY, new ColorRGBA(Color.WHITE.getRGB()));
ctx.getMatrices().pop();
}
boolean isHovered(double mx, double my) {
return mx >= x && mx <= x + width && my >= y && my <= y + height;
}
}
private class CombinedButton {
int x, y, width, height;
final String leftName, rightName;
float leftAnim = 0f, rightAnim = 0f;
CombinedButton(int x, int y, int w, int h, String l, String r) {
this.x = x;
this.y = y;
this.width = w;
this.height = h;
this.leftName = l;
this.rightName = r;
}
void render(DrawContext ctx, int mx, int my, float delta) {
int half = width / 2 - 2;
drawHalf(ctx, x, leftName, isOptionHovered(mx, my), true);
drawHalf(ctx, x + half + 4, rightName, isQuitHovered(mx, my), false);
}
void drawHalf(DrawContext ctx, int bx, String text, boolean hovered, boolean left) {
float anim = hovered ? 1f : 0f;
int bg = ColorUtil.blend(
new Color(35, 35, 35).getRGB(),
new Color(55, 55, 55).getRGB(),
anim
);
CustomDrawContext cdc = new CustomDrawContext(mc.getBufferBuilders().getEntityVertexConsumers());
cdc.drawRoundedRect(bx, y, width / 2 - 4, height, new BorderRadius(4, 4, 4, 4), new ColorRGBA(bg));
cdc.drawRoundedBorder(bx, y, width / 2 - 4, height, 0.1f,
new BorderRadius(4, 4, 4, 4), new ColorRGBA(60, 60, 60, 180));
float tw = Fonts.INTER_MEDIUM.getWidth(text, 7);
float tx = bx + ((width / 2f - 4) - tw) / 2f + TEXT_SHIFT_X;
float ty = y + (height - 12) / 2f + 2;
cdc.drawText(medium, text, tx, ty, new ColorRGBA(Color.WHITE.getRGB()));
}
boolean isOptionHovered(double mx, double my) {
return mx >= x && mx <= x + width / 2 && my >= y && my <= y + height;
}
boolean isQuitHovered(double mx, double my) {
return mx >= x + width / 2 && mx <= x + width && my >= y && my <= y + height;
}
}
@Override
public boolean shouldCloseOnEsc() {
return false;
}
}