Jump to content

Opening a GuiScreen from the Server


Vega Alpha

Recommended Posts

I’m constructing a MOD that implements

MyBlock extends net.minecraft.block.Block 

and an associated

MyTileEntity extends net.minecraft.tileentity.TileEntity

that should open

MyGuiScreen extends net.minecraft.client.gui.GuiScreen

when the Minecraft Server decides to.  The client side will ask the server to open MyGuiScreen and the Server will open it, after taking security concerns into account.

 

Currently I have MyGuiScreen opening just fine when the client decides to, like this

if (worldIn.isRemote) playerIn.openGui(MyMod.INSTANCE, MyGuiHandler.GUI_ID, worldIn, x, y, z)

 

How do I allow the server to open MyGuiScreen at the client after the server receives a request from the client to do so?

 

A software engineer’s job is often to condense fact from the nuance of vapor.

Link to comment
Share on other sites

If you call

EntityPlayer#openGUI

on the server and your

IGuiHandler#getServerGuiElement

method returns a

Container

, FML will send a packet to the client telling it to open the same GUI (via your

IGuiHandler

).

 

If the open request needs to be sent from the client side (e.g. in response to a key press), send a custom packet to the server. The same applies if your GUI doesn't have a

Container

and you need to send the response packet manually.

 

Forge's documentation explains networking in Minecraft here. This includes the Simple Network Implementation, which you should use to send the packet.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

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.