H
H
Hello World2019-02-24 13:39:46
Java
Hello World, 2019-02-24 13:39:46

Why is currentScreen always null?

There was a need to write a mod that would automate some things.
I'm using version 1.7.10
I want to get currenScreen but it's null.
Why?

KeyHandler.java
public class KeyHandler {

   @SubscribeEvent
    public void onPlayerInteractEvent(PlayerInteractEvent event)
    {
        final GuiContainer screen = (GuiContainer) Minecraft.getMinecraft().currentScreen;
        if (screen == null){
            mc.thePlayer.addChatComponentMessage(new ChatComponentText("Screen is null :("));
            return;
        }
   }
}
}

Main.java
@Mod(modid = Main.MODID, version = Main.VERSION)
public class Main
{
    public static final String MODID = "Mod";
    public static final String VERSION = "1.0";



    @EventHandler
    public void init(FMLInitializationEvent event)
    {

        FMLCommonHandler.instance().bus().register(new KeyHandler());
        MinecraftForge.EVENT_BUS.register(new KeyHandler());
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question