Jump to content

Recommended Posts

Posted (edited)

I know it's good to schedule the messages received by the client and server in order to avoid crashes and bugs. However, should I make the messages scheduled or only a certain few? If so, how do I know which ones to add as a scheduled task?

 

Any help is appreciated. :)

 

Thanks

Edited by Differentiation
Posted

Packet handling and the game are on different threads. Therefore, any actions concerning the game should be in a scheduled task (i.e. world manipulation, tile entity manipulation, etc).

Some tips:

  Reveal hidden contents

 

Posted
  On 10/15/2019 at 1:35 AM, DavidM said:

Packet handling and the game are on different threads. Therefore, any actions concerning the game should be in a scheduled task (i.e. world manipulation, tile entity manipulation, etc).

Expand  

So if I have something as simple as EntityPlayer::capabilities#allowFlight = true; in client handler

I'd still need to schedule?

Posted
  On 10/15/2019 at 1:40 AM, Differentiation said:

So if I have something as simple as EntityPlayer::capabilities#allowFlight = true; in client handler

I'd still need to schedule?

Expand  

I believe so.

Some tips:

  Reveal hidden contents

 

Posted
  On 10/15/2019 at 1:15 AM, Differentiation said:

should I make the messages scheduled or only a certain few?

Expand  

The simple answer is "any and all."

The only time you wouldn't need to would be if you were going to send a new packet somewhere and did not need to interact with anything outside the handler's current scope. These situations will be so rare and edge-case as to be practically nonexistent.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
  On 10/15/2019 at 5:38 PM, Draco18s said:

The simple answer is "any and all."

The only time you wouldn't need to would be if you were going to send a new packet somewhere and did not need to interact with anything outside the handler's current scope. These situations will be so rare and edge-case as to be practically nonexistent.

Expand  

Then... can I just do this?

public abstract class AbstractPacket<REQ extends IMessage> implements IMessage, IMessageHandler<REQ, REQ>
{
    @Override
    public REQ onMessage(REQ message, MessageContext context)
    {
        if (context.side == Side.SERVER)
        {
        	EntityPlayerMP player = context.getServerHandler().player;
        	
            	player.getServer().addScheduledTask(new Runnable()
		{
			@Override
			public void run()
			{
		        	handleServerSide(message, player);
			}
		});
        } 
        else
        {
       		EntityPlayer player = Dinocraft.PROXY.getPlayer();
        	
            	Minecraft.getMinecraft().addScheduledTask(new Runnable()
		{
			@Override
			public void run()
			{
		        	handleClientSide(message, player);
			}
		});
        }
        
        return null;
    }

    public abstract void handleClientSide(REQ message, EntityPlayer player);

    public abstract void handleServerSide(REQ message, EntityPlayer player);
}

 

Edited by Differentiation

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.