My code:
package com.example.examplemod;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.inventory.InventoryScreen;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import java.nio.charset.StandardCharsets;
public class CustomGui extends Screen {
private String option1Text = new String("Как мы тут оказались?".getBytes(), StandardCharsets.UTF_8);
private String option2Text = new String("Что за лаборатория ФьючерТек".getBytes(), StandardCharsets.UTF_8);
private String option3Text = new String("Какой сейчас год?".getBytes(), StandardCharsets.UTF_8);
public CustomGui() {
super(new StringTextComponent("Custom Menu"));
}
private static final ResourceLocation background = new ResourceLocation("custommenu", "textures/gui/background.png");
@Override
protected void init() {
super.init();
}
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
renderBackground(matrixStack);
// Draw the background texture
Minecraft.getInstance().getTextureManager().bind(background);
int backgroundWidth = 200;
int backgroundHeight = 100;
int xOffset = (width - backgroundWidth) / 2;
int yOffset = (height - backgroundHeight) / 2;
// Prevent the background texture from repeating
blit(matrixStack, 0, 0, backgroundWidth, backgroundHeight, backgroundWidth, backgroundHeight);
// int barHeight = 130;
// int margin = 70;
// fill(matrixStack, 0, height - barHeight - margin, width, height - margin, 0x80000000);
int textWidth = font.width(option1Text);
int textHeight = font.lineHeight;
int textSpacing = 2;
drawCenteredString(matrixStack, font, new String("Они только очнулись, подожди..".getBytes(), StandardCharsets.UTF_8), width / 2, height / 2 - 50, 0xff00ff00); // Зеленый текст
drawString(matrixStack, font, option1Text, width / 2 - textWidth / 2, height / 2 - textHeight - textSpacing, isMouseOverOption(mouseX,mouseY,1)?0xffffff00:0xff00ff00);
drawString(matrixStack, font, option2Text,width/2-textWidth/2,height/2,isMouseOverOption(mouseX,mouseY,2)?0xffffff00:0xff00ff00);
drawString(matrixStack, font, option3Text,width/2-textWidth/2,height/2+textHeight+textSpacing,isMouseOverOption(mouseX,mouseY,3)?0xffffff00:0xff00ff00);
// Отображение персонажа игрока справа
LivingEntity player = Minecraft.getInstance().player;
int size = (int) (height * .15); // Уменьшение размера персонажа
InventoryScreen.renderEntityInInventory(width - (width / 4), height / 2 + (height / 4), size,(float)(width-(width/4))-mouseX,(float)(height/2+(height/4))-mouseY-50 , player);
// Обрезание ног персонажа
fill(matrixStack,width-(width/4)-size/2,height/2+(height/4),width-(width/4)+size/2,height,size==64?0xff000000:0);
}
private boolean isMouseOverOption(double mouseX,double mouseY,int option){
int textWidth=font.width(option1Text);
int textHeight=font.lineHeight;
int textSpacing=2;
if(mouseX>=width/2-textWidth/2&&mouseX<=width/2+textWidth/2){
if(option==1&&mouseY>=height/2-textHeight-textSpacing&&mouseY<=height/2-textSpacing){
return true;
}else if(option==2&&mouseY>=height/2&&mouseY<=height/2+textHeight){
return true;
}else if(option==3&&mouseY>=height/2+textHeight+textSpacing&&mouseY<=height/2+textHeight*2+textSpacing){
return true;
}
}
return false;
}
@Override
public boolean mouseClicked(double mouseX,double mouseY,int button){
int textWidth=font.width(option1Text);
int textHeight=font.lineHeight;
int textSpacing=2;
if(mouseX>=width/2-textWidth/2&&mouseX<=width/2+textWidth/2){
if(mouseY>=height/2-textHeight-textSpacing&&mouseY<=height/2-textSpacing){
// Действия при выборе варианта "Stop it,it's annoying"
Minecraft.getInstance().setScreen(null);
return true;
}else if(mouseY>=height/2&&mouseY<=height/2+textHeight){
// Действия при выборе варианта "Behave as if you're my boss"
Minecraft.getInstance().setScreen(null);
return true;
}else if(mouseY>=height/2+textHeight+textSpacing&&mouseY<=height/2+textHeight*2+textSpacing){
// Действия при выборе варианта "You should show more respect than just poking"
Minecraft.getInstance().setScreen(null);
return true;
}
}
return super.mouseClicked(mouseX,mouseY,button);
}
@Override
public boolean isPauseScreen() {
return false;
}
}