Jump to content

How can i close gui at Forge 1.8.8?


Filip4223

Recommended Posts

I am trying to write an Minecraft Forge (1.8.8) mod. It should work like that:

OnGuiOpen: If GUI title is equals to constant string value then close GUI (like ESC). Close event must be respected by server.

 

My code (doesnt work):

 

public class ModEventHandler {
	
	@SubscribeEvent
	public void onGuiOpen(GuiOpenEvent event)
	{
		if(event.gui instanceof GuiContainer) {
			checkGui((GuiContainer) event.gui);
		}
	}

	private void checkGui(GuiContainer gui) {
		
		if(gui.inventorySlots instanceof ContainerChest) {
			ContainerChest _gui = (ContainerChest)gui.inventorySlots;
			
			IChatComponent component = _gui.getLowerChestInventory().getDisplayName();

			String text = component.getUnformattedText();
			
			if(text.contains("Kopanie")) {
				System.out.println("Turning off");
				Minecraft.getMinecraft().thePlayer.closeScreen();
				Minecraft.getMinecraft().displayGuiScreen(null);

				KeyBinding.onTick(Keyboard.KEY_ESCAPE);
				
			}
		}
	}
}

 

Link to comment
Share on other sites

  • Guest locked this topic
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

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