Jump to content

[1.7.2] Opening GUI with PacketHandler


Recommended Posts

I got suggested that I should use a PacketHandler to open my GUI. Now I have no idea on how to open the gui in the PacketHandler, so I would require some help. I searched for some tutorials and explanations, but I can't realize what should I do.


The GUI has 1 button and 1 text input field. When you input a number in the field and click on the button, it will take the number and set the strength of the explosion.


Here's the action method for the button:


protected void actionPerformed(GuiButton button) {

	World world = null;
	WorldServer[] list = MinecraftServer.getServer().worldServers;

	/*switch (button.id) {
	case 1:
		i += 1;
	case 2:
		i -= 1;
	// Packet code here
        // PaintEventDispatcher.sendPacketToServer(packet); //send packet

	for (WorldServer ins : list) {
		if (ins.provider.dimensionId == entity.worldObj.provider.dimensionId)
			world = ins;
	if (world == null)
		world = list[0];

	if (button.id == 0) {

		if (true) {
			if (power.getText().isEmpty())
			else if (power.getText().matches("[a-zA-Z]+")) 
			else if (power.getText().matches("[0-9]+")) {
				this.mc.displayGuiScreen((GuiScreen) null);
				world.createExplosion((Entity) null, i, j - 10, k, Integer.parseInt(power.getText().trim()), true); 





___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

First, you would create a packet handler etc. and register it. Then, you would create a packet that takes an integer (ID of the gui you want to open) as its data. When the packet is received, open up the GUI via the gui ID you sent.

We all stuff up sometimes... But I seem to be at the bottom of that pot.

Link to comment
Share on other sites

Why do you need a PacketHandler if you can just use the onBlockActivated(args) method in the block class so if you click on the block in te world (not in the inventory) it opens the gui. If you wan't it to be in your inventory and right click it, you need a custom ItemBlock and use the onItemUse(args) method and open the gui in that method. If this doesn't match your needs, can you please specify where the block is, so we now what you wan't to do with the block.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.


1.12 -> 1.13 primer by williewillus.


1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.



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.

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.


  • Create New...

Important Information

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