Jump to content

[1.15.2] Join the minecraft thread from another thread


Recommended Posts

Posted (edited)

So,

I have two thread : The first one is the one of minecraft, the second one is async thread that I created to do something on the web.

I would like that when the second thread is done, the first thread execute a method ( and not the second thread because minecraft really doesn't like when you use method using another thread).

Before the second thread ended, the first thread must continue working.

Does anyone have any idea of how to do that please ?

 

Edited by uiytt
Clarification
Posted

Hi

You could consider using the packet receiving system to do that.

Any time a packet is received, it is in a network thread.  The network thread creates a Runnable lambda which is then executed in either the client thread or the server thread.

Some more info here:

http://greyminecraftcoder.blogspot.com/2020/03/thread-safety-with-network-messages-1144.html

 

There's probably a way for your second thread to add your own Runnable lambda to those queues without using packets.

 

Alternatively, you could perhaps subscribe to a Tick event on the server or the client, and every tick check your second thread to see whether it has finished executing or not.

 

-TGG

  • Like 1
Posted

Well I tried :

Minecraft.getInstance().runImmediately(new Runnable() {
	@Override
	public void run() {
		MultiPlayerGui.this.minecraft.displayGuiScreen(new ConnectingScreen(MultiPlayerGui.this, MultiPlayerGui.this.minecraft, server));
	}
});

And it's really weird...

In my console, I receive everything from the server chat. But on my game, it's stuck on loading the terrain infinitely !!!

MultiPlayerGui is my custome class but the rest is not..

I don't undersant why O_o

Posted (edited)
7 hours ago, diesieben07 said:

Any reason you are using runImmediately? Whats the thread that this is called from?

A thread that I created to check for my server's information.
If I use the screen directly from my thread, minecraft will crash..

Edited by uiytt

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.