Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

 

When I made the mod, registered everything, and so on, I should open a menu with the choice of the answer to the H key, but when I press it in minecraft itself, it crashes, why?
My main class code:
 

package com.example.examplemod;

import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.lwjgl.glfw.GLFW;

@Mod("custommenu")

@Mod.EventBusSubscriber(Dist.CLIENT)
public class custommenu {
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (event.getKey() == GLFW.GLFW_KEY_H && event.getAction() == GLFW.GLFW_PRESS) {
Minecraft.getInstance().setScreen(new CustomGui());
}
}
}

my second class where the code is written to open the menu:
 

package com.example.examplemod;

import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;
import org.lwjgl.glfw.GLFW;


public class CustomGui extends Screen {
private final ResourceLocation background = new ResourceLocation("custommenu", "textures/gui/background.png");
private Button yesButton;
private Button noButton;
private Button laterButton;

public CustomGui() {
super(null);
}

@Override
protected void init() {
super.init();

yesButton = new Button(width / 2 - 100, height / 2 - 24, 200, 20, new TranslationTextComponent("Да"), button -> {
// Действия при выборе варианта "Да"
Minecraft.getInstance().setScreen(null);
});
noButton = new Button(width / 2 - 100, height / 2, 200, 20, new TranslationTextComponent("Нет"), button -> {
// Действия при выборе варианта "Нет"
Minecraft.getInstance().setScreen(null);
});
laterButton = new Button(width / 2 - 100, height / 2 + 24, 200, 20, new TranslationTextComponent("Позже"), button -> {
// Действия при выборе варианта "Позже"
Minecraft.getInstance().setScreen(null);
});

addButton(yesButton);
addButton(noButton);
addButton(laterButton);
}
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
// Отображение текстуры
Minecraft.getInstance().getTextureManager().bind(background);
blit(matrixStack, 0, 0, 0, 0, width, height);

// Отображение кнопок
super.render(matrixStack, mouseX, mouseY, partialTicks);
}

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
Minecraft.getInstance().setScreen(null);
return true;
} else if (keyCode == GLFW.GLFW_KEY_H) {
// Открываем ваше меню с выбором ответа
Minecraft.getInstance().setScreen(new CustomGui());
return true;
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
public boolean isPauseScreen() {
return false;
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.