Jump to content

[SOLVED, coders mistake][1.7.10] How to open Gui with packet?


Ernio

Recommended Posts

I am doing something wrong here, lore:

Server - an Integrated Server-thread

Client - a Client-thread

Dedic - A Dedicated Server-thread

 

public class GuiHandler implements IGuiHandler
{
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	switch (ID)
	{
	case 100: return null;
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	if (world instanceof WorldClient)
	{
		switch (ID)
		{
		case 100: return new GuiIntroduction();
		}
	}
	return null;
}
}

@SubscribeEvent
public void playerLoggedInEvent (PlayerEvent.PlayerLoggedInEvent event)
{
		System.out.println("LOGGED IN");
		PlayerStats ps = ExtendedPlayer.get(event.player).getStats();
		if (ps.getRace() == null || ps.getSubRace() == null || ps.getOrigin() == null)
		{
			System.out.println("SHOULD OPEN");
			event.player.openGui(RoAMain.instance, 100, event.player.worldObj, (int) event.player.posX, (int) event.player.posY, (int) event.player.posZ);
			PacketDispatcher.sendTo(new PacketOpenCloseGui((byte) 1), (EntityPlayerMP) event.player);
		}
}

public class PacketOpenCloseGui implements IMessage
{
byte b = 0;

public PacketOpenCloseGui() {}

public PacketOpenCloseGui(byte b)
{
	System.out.println("SENDING OPEN CLOSE GUI PACKET");
	this.b = b;
}

@Override
public void toBytes(ByteBuf buffer)
{
	buffer.writeByte(this.b);
}

@Override
public void fromBytes(ByteBuf buffer)
{
	this.b = buffer.readByte();
}

public static class PacketOpenCloseGuiHandler extends AbstractClientMessageHandler<PacketOpenCloseGui>
{
	@Override
	public IMessage handleClientMessage(EntityPlayer player, PacketOpenCloseGui message, MessageContext ctx)
	{
		System.out.println("RECEIVED OPEN CLOSE GUI PACKET");
		switch(message.b)
		{
		case 1: player.openGui(RoAMain.instance, 100, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
		}
		return null;
	}
}
}

 

On Client-Server:

[22:11:37] [server thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.events.FMLEvents:playerLoggedInEvent:28]: LOGGED IN
[22:11:37] [server thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.events.FMLEvents:playerLoggedInEvent:32]: SHOULD OPEN
[22:11:37] [server thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.network.server.PacketOpenCloseGui:<init>:23]: SENDING OPEN CLOSE 
GUI PACKET
[22:19:25] [Client thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.network.server.PacketOpenCloseGui$PacketOpenCloseGuiHandler:handleClientMessage:44]: RECEIVED OPEN CLOSE GUI PACKET

On Client-Dedic:

[22:12:15] [server thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.events.FMLEvents:playerLoggedInEvent:28]: LOGGED IN
[22:12:15] [server thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.events.FMLEvents:playerLoggedInEvent:32]: SHOULD OPEN
[22:12:15] [server thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.network.server.PacketOpenCloseGui:<init>:23]: SENDING OPEN CLOSE GUI PACKET
And client gets:
[22:12:16] [Client thread/INFO] [sTDOUT]: [com.midstcraft.ernio.RoA.common.network.server.PacketOpenCloseGui$PacketOpenCloseGuiHandler:handleClientMessage:44]: RECEIVED OPEN CLOSE GUI PACKET

 

Bam... nothing happens, no matter if its client or server or dedi...

 

Situation 2:

I tries putting:

@Override
	public IMessage handleClientMessage(EntityPlayer player, PacketOpenCloseGui message, MessageContext ctx)
	{
		System.out.println("RECEIVED OPEN CLOSE GUI PACKET");
		switch(message.b)
		{
		case 1: Minecraft.getMinecraft().displayGuiScreen(new GuiIntroduction());
		}
		return null;
	}

 

Then it works on Client-Server, but on Client-Dedic crashes with no GuiScreen found (which is obvious since it doesn't exist).

 

Question:

How do I make code that works for all?

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

Link to comment
Share on other sites

Well that's what I did:

1. Tried sending with packed with code on clientHandler: Minecraft.getMinecraft().displayGuiScreen(new GuiIntroduction());

2. Worked on Client-Integrated, when i launched dedic, it crashed since GuiScreen doesn't exist there.

3. Started using openGui

4. Was frustrated

<magic happens>

<Ernio realizes he's retarded and writing this topic and Syso in code was a waste of good 30min>

BAM

case 1: player.openGui(RoAMain.instance, 100, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
		case -1: player.closeScreen(); break;

<Ernio notices he forgot break; after 1st case>

<Facepalms himself for not even providing full code in this thread (i removed case -1 to not make too long code)>

 

DAMN I am...

Thanks :D

 

Ernio.gif

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

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.



×
×
  • Create New...

Important Information

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