Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
init
у класса, который наследует от Screen
, вызываешь Screen#addButton
. Должно быть что-то типа такого:@Override
protected void init() {
super.init();
addButton(new Button(x, y, ширина, высота, текст, (Button.IPressable) button -> {
тут то что должно происходить при нажатии на кнопку
}));
}
render
. И потом разными методами рендеришь то, что тебе нужно. Например drawString, renderBackground, fillGradient, blit и т.д.
Minecraft.getInstance().textureManager.bind(ResourceLocation)
и после бинда рендеришь через AbstractGui.blit(matrixStack, x, y, textureXOffset, textureYOffset, width, height, textureChunckSize, textureChunckSize)
public class MainGui extends Screen {
Minecraft mc = Minecraft.getInstance();
private static ResourceLocation body = new ResourceLocation("examplemod", "icons/body.png");
public MainGui() {
super(new StringTextComponent("GUI Title"));
}
@Override
protected void init() {
addButton(new Button(width / 2 - 150, height / 2 - 20, 20, 20, new StringTextComponent("Доп.время"), button -> {
this.mc.player.chat("Test");
}));
;
}
public void render(MatrixStack mw, int q, int w, int e) {
}
public void onGUI(MatrixStack mw, int q, int w, int e) {
this.renderBackground(mw);
this.mc.getTextureManager().bind(body);
int height = mc.getWindow().getHeight();
int wight = mc.getWindow().getWidth();
drawTexture(5.0D, 5.0D, (double) wight / 2 - 6.0D, (double) height / 2 - 5.0D);
GL11.glPushMatrix();
GL11.glEnable(3089);
GL11.glScissor(height / 4, (int) ((double) height / 5.7 * this.getMinecraft().getWindow().getX()), this.width * 10, (int) ((double) wight / 1.73 * this.getMinecraft().getWindow().getY())
);
GL11.glDisable(3089);
GL11.glPopMatrix();
}
public static void drawTexture(double posX, double posY, double width, double height) {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_QUADS);
GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
GL11.glTranslatef((float) posX, (float) posY, 2.0F);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bf = tessellator.getBuilder();
bf.begin(7, DefaultVertexFormats.POSITION_TEX);
bf.vertex(1.0D, 1.0D, 1.0D);
bf.vertex(1.0D, height, 1.0D);
bf.vertex(width, height, 1.0D);
bf.vertex(width, 1.0D, 1.0D);
tessellator.end();
GL11.glDisable(GL11.GL_QUADS);
GL11.glPopMatrix();
}
}
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTick) {
}
@Override
public void render(MatrixStack mw, int q, int w, float e) {
this.renderBackground(mw);
this.mc.getTextureManager().bind(body);
int height = mc.getWindow().getHeight();
int wight = mc.getWindow().getWidth();
AbstractGui.blit(mw, 10, 10, 10, 10, wight / 4, height / 4, 10, 10);
int x = width / 2 - imageWidth / 2
int y = height / 2 - imageHeight / 2
public static Tuple<Integer, Integer> getTextureSize(ResourceLocation textureRL) {
RenderSystem.pushMatrix();
Minecraft.getInstance().getTextureManager().bind(textureRL);
Tuple<Integer, Integer> size = new Tuple<>(GlStateManager._getTexLevelParameter(GL11.GL_TEXTURE_2D,
0, GL11.GL_TEXTURE_WIDTH), GlStateManager._getTexLevelParameter(GL11.GL_TEXTURE_2D, 0, GL11.GL_TEXTURE_HEIGHT));
RenderSystem.popMatrix();
return size;
}
AbstractGui.blit(matrixStack, x, y, 0, 0, imageWidth, imageHeight, imageWidth, imageHeight)
AbstractGui.blit(mw, mc.getWindow().getX(), mc.getWindow().getY(), x, y, wight, height, 500, 500);
int height = mc.getWindow().getHeight();
int wight = mc.getWindow().getWidth();
int x = wight / 2 - getTextureSize(body).getA() / 2;
int y = (height / 2) - getTextureSize(body).getB() / 2;