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:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
3 minutes ago, 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).

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

I'd still need to schedule?

Posted
1 minute ago, Differentiation said:

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

I'd still need to schedule?

I believe so.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
16 hours ago, Differentiation said:

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

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)
6 hours ago, 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.

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.