Jump to content

[SOLVED] GUI not working


Darki

Recommended Posts

That's not the problem, it's just a method name. The value returned by the method is eventually cast to

GuiScreen

, not

GuiContainer

.

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

Ok but I cant see where displayScreen is called too

 

What do you mean?

 

Set a breakpoint in

Minecraft#displayScreen

and remove your other breakpoints. It should be called once with your GUI and then called another time with a different GUI. Does this second call happen? If it does, post a screenshot/video of the debugger showing it.

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

Ok first time after I call it:

this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));

in:

    public void handleJoinGame(SPacketJoinGame packetIn)
    {
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
        this.gameController.playerController = new PlayerControllerMP(this.gameController, this);
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, packetIn.isHardcoreMode(), packetIn.getWorldType()), net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.get(getNetworkManager()).getOverrideDimension(packetIn), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.gameController.gameSettings.difficulty = packetIn.getDifficulty();
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.thePlayer.dimension = packetIn.getDimension();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
        this.gameController.thePlayer.setEntityId(packetIn.getPlayerId());
        this.currentServerMaxPlayers = packetIn.getMaxPlayers();
        this.gameController.thePlayer.setReducedDebug(packetIn.isReducedDebugInfo());
        this.gameController.playerController.setGameType(packetIn.getGameType());
        this.gameController.gameSettings.sendSettingsToServer();
        this.netManager.sendPacket(new CPacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer())).writeString(ClientBrandRetriever.getClientModName())));
    }

Oh I found it here, this method:

public void handlePlayerPosLook(SPacketPlayerPosLook packetIn)

will be called after the first and the method do that:

this.gameController.displayGuiScreen((GuiScreen)null);

I think this is the problem

Link to comment
Share on other sites

Ah, that makes sense.

Minecraft#loadWorld

spawns the client player in the world, firing

EntityJoinWorldEvent

and opening your GUI. The

Minecraft#displayGuiScreen

call after that replaces your GUI before you can see it, so it looks like it was never opened. This means that you'll need to show your GUI slightly later in the login process.

 

I suggest subscribing to

PlayerLoggedInEvent

(fired on the server side) and checking if the player has built their character (i.e. finished with the character builder GUI). If they haven't, send a packet to the client to open the character builder GUI. This should be received after

GuiDownloadTerrain

has been hidden by the

SPacketPlayerPosLook

handler.

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

Another problem: When I try to open the GUI screen with the PlayerLoggedInEvent nothing happens because its a server side event but my gui handler returns null:

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	return null;
}

Link to comment
Share on other sites

How can I asked whether the GuiDownloadTerrain has been hidden?

Minecraft#currentScreen

contains the current

GuiScreen

, but you shouldn't need to check this; just display the GUI when you receive the packet.

 

Another problem: When I try to open the GUI screen with the PlayerLoggedInEvent nothing happens because its a server side event but my gui handler returns null:

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	return null;
}

That's why I told you to send a packet rather than calling

EntityPlayer#openGUI

.

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

Ok I look in it and its not so difficulty. Its good that I worked with packets in the past when i coding plugins with the spigot api but one big question is open what i have to do you said i should send a packet that opens the the gui but which packet then you said i should do this after the spacketplayerpos hides the guidownloadterrain but how can i proof this? That would be fine when you can answer this

Link to comment
Share on other sites

Ok I tried a little bit. Here my Packet:

public class GuiScreenOpenPacket implements IMessage {

public int gui_id;

public GuiScreenOpenPacket(int gui_id) {
	this.gui_id = gui_id;
}

@Override
public void fromBytes(ByteBuf buf) {
	gui_id = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(gui_id);
}

}

And My Handler:

public class GuiScreenOpenPacketHandler  implements IMessageHandler<GuiScreenOpenPacket, IMessage> {

@Override
public IMessage onMessage(GuiScreenOpenPacket message, MessageContext ctx) {
	EntityPlayerMP player = ctx.getServerHandler().playerEntity;
	player.openGui(Main.getInstance(), message.gui_id, player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
	return null;
}


}

Is that right? And how can I open the Gui with the Packet now?

Link to comment
Share on other sites

i but one big question is open what i have to do you said i should send a packet that opens the the gui but which packet

Create your own.

 

then you said i should do this after the spacketplayerpos hides the guidownloadterrain but how can i proof this? That would be fine when you can answer this

PlayerLoggedInEvent

is fired after

SPacketPlayerPosLook

is sent from the server, so a packet sent from the event handler should be received by the client after the vanilla packet.

 

Ok I tried a little bit. Here my Packet:

 

...

 

Is that right? And how can I open the Gui with the Packet now?

Packet handlers are run on a separate thread, you must schedule a task to run on the main thread before you can safely interact with normal Minecraft classes. The Warning section of the documentation explains how to do this.

 

This packet will be sent by the server and received by the client, so you can't use

NetHandlerPlayServer

or

EntityPlayerMP

in the handler. You need to open the GUI through the client player (

Minecraft#thePlayer

) instead.

 

Sending the packet to a client will cause the client to open the GUI once it's been received.

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

Packet handlers are run on a separate thread, you must schedule a task to run on the main thread before you can safely interact with normal Minecraft classes. The Warning section of the documentation explains how to do this.

Is that right?

	@Override
public IMessage onMessage(GuiScreenOpenPacket message, MessageContext ctx) {
	final GuiScreenOpenPacket msg = message;
	final EntityPlayer player = Minecraft.getMinecraft().thePlayer;
	Minecraft.getMinecraft().addScheduledTask(new Runnable() {

		@Override
		public void run() {
			player.openGui(Main.getInstance(), msg.gui_id, player.worldObj, player.getPosition().getX(), player.getPosition().getY(), player.getPosition().getZ());
		}
	});
	return null;
}

Link to comment
Share on other sites

Ok its working. I tried it and than first there was a big error in the console and minecraft crashed but the problem was that I only had the constructor with the guiid but you have to make another constructor without anything. Now it works big thanks to you Choonster that you helped me so long  ;) You should get the Mod Rank but yeah thank you very much

Link to comment
Share on other sites

Is that right?

 

The

msg

local variable is pointless, just use the

message

argument. The

player

variable should be moved inside the

Runnable#run

implementation to avoid potential thread safety issues.

 

Other than that, what you have should work.

 

 

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.