искал как создать gui нашёл только один способ для 1.16.5
ошибки в игре не появляются. Текст просто не выводится.
класс самого Gui:
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import static net.minecraft.client.gui.AbstractGui.drawCenteredString;
import static org.hellomira.coftic.Coftic.LOGGER;
public class Gui extends AbstractGui {
//отображаемый текст
static String text = "Hello Gui!";
public Gui(Minecraft mc, MatrixStack ms) {
super();
LOGGER.info("Gui");
int width = mc.getMainRenderTarget().width;
int height = mc.getMainRenderTarget().height;
drawCenteredString(ms, mc.gui.getFont() , text, width / 2, (height / 2) - 4, 0xFFFFFF);
// 10526880 это цвет текста
}
}
Основной Класс мода:
@Mod("coftic")
public class Coftic {
// Directly reference a log4j logger.
static final Logger LOGGER = LogManager.getLogger();
public Coftic() {
MinecraftForge.EVENT_BUS.register(new RenderGuiHandler());
// Register the setup method for modloading
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
//Там дальше просто методы которые создаются автоматически
private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().options);
}
private void enqueueIMC(final InterModEnqueueEvent event) {
// some example code to dispatch IMC to another mod
InterModComms.sendTo("coftic", "helloworld", () -> {
LOGGER.info("Hello world from the MDK");
return "Hello world";
});
}
private void processIMC(final InterModProcessEvent event) {
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().map(m -> m.getMessageSupplier().get()).collect(Collectors.toList()));
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
@SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
// register a new block here
LOGGER.info("HELLO from Register Block");
}
}
}
Класс для вызова интерфейса:
public class RenderGuiHandler {
@SubscribeEvent
public void onRenderGui(RenderGameOverlayEvent.Post event) {
LOGGER.info("onGui");
if (event.getType() != RenderGameOverlayEvent.ElementType.EXPERIENCE) {
new Gui(Minecraft.getInstance(), event.getMatrixStack()); //рендерим свой интерфейс
return; //в моём случае, если у игрока зарендерилась полоска опыта
}
LOGGER.info("Gui1");
new Gui(Minecraft.getInstance(), event.getMatrixStack()); //рендерим свой интерфейс
}
}
ошибки в игре не появляются. Текст просто не выводится.