Jump to content

Recommended Posts

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.

Posted

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.

Posted

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.

Posted

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

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