Jump to content

Why is minecraft crashing


MoonManich

Recommended Posts

 

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;
}
}

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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