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

Hi guys,

i created a Gui extending GuiScreen, added a GuiHandler and call player.openGui(...) to open it.

From this post [1.8.9]Mouse not showing up in gui I found out that you can return null in the getServerGuiElement method of the handler. But, since the gui didn't open I searched for a problem and found out that FMLNetworkHandler.openGui only sends a FMLMessage$OpenGui to the client if getServerGuiElement returns a Container. Therefore I just did the following:

	public Object getServerGuiElement(int ID, EntityPlayer player, World world,	int x, int y, int z) {
	if (ID != getGuiID()) {
		System.err.println("Invalid ID: expected " + getGuiID() + ", received " + ID);
	}
	BlockPos pos = new BlockPos(x, y, z);
	if (world.getBlockState(pos).getBlock() instanceof ConYard) {
		System.err.println("return gui");
		return new Container() {
			@Override
			public boolean canInteractWith(EntityPlayer playerIn) {
				return true;
			}
		};
	}

	return null;
}

And it works. My question would be, is there any other way to open a gui without this little work-around?

 

Regards,

McRaichu

 

PS: I started from this tutorial Jabelar's Minecraft Forge Modding Tutorials: Block With Simple GUI. Which had some bugs, like the mouse not showing up.

It doesn't work, I don't know why.

It works, I don't know why.

IGuiHandler is designed to connect Container with its GuiContainer.

 

If you don't need Container (and you need it only if you want to hold/display/interact with ItemStacks) you don't use it.

 

In that case opening GuiScreen needs to be done from Client thread using:

* player.openGui (which on client will directly call for client element)

or

* Minecraft#displayGuiScreen

 

If whatever you do to open it (iteract with block/entity/whatever) is fired only on server, you need to send packet from server to client where it will call one of methods above.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Hi,

came up with the same solution 3 minutes ago  ;D . For the sake of better understanding, what would be the drawback of actually doing it the FMLMessage-way? Are there any drawbacks, except the delay due to the pakets?

It doesn't work, I don't know why.

It works, I don't know why.

FMLMessage-way? Are there any drawbacks, except the delay due to the pakets?

 

1. What is "FMLMessage-way" for you? You mean like you do it in code you gave (assign container to every gui, no matter what)?

* Please post update source.

 

2. Packet delay is not really a drawback, it is just something that cannot be overcome.

 

3. Mentioned approach (my prev post) is the only viable way of doing it. Container should always go with GuiContainer and GuiScreen should always be client only.

1.7.10 is no longer supported by forge, you are on your own.

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.