Twometer / NextCraft

Full 3D Minecraft Multiplayer Client for 1.8
Apache License 2.0
16 stars 5 forks source link

How to understand network protocol in MineCraft 1.8 #2

Closed codingwatching closed 3 years ago

codingwatching commented 3 years ago

Hi @Twometer I want to learn the way network protocol between NextCraft and Server. What is the current Server that we are using? Is this server1.8.jar from the Minecraft site? How to debug or get the protocol data of the 1.8 version Thank you so much! I like and very enjoy when learn to build a client for Minecraft. I think 1.8 is a good start too, it quite simple and have fewer blocks and items than other versions (Hopefully) Thank you!

Twometer commented 3 years ago

The server we are currently using is the server1.8.jar from Mojangs site, yes.

For learning to work with the Minecraft protocol, I can definitely recommend wiki.vg - It's a full protocol documentation and really good resource (direct link to 1.8, chunk formats).

Sometimes it can also be helpful to look at the original Minecraft source code, for that I can recommend you the Mod Coder Pack, as it will not only decompile but also deobfuscate the sources.

If you'd like to see a working and a simple implementation you can also check out the McClient class in NextCraft.

And for the last point: Yes, they made lots of optimizations on 1.16+ versions, which makes it harder to implement. Version 1.8 is definitely more straightforward, especially if you are just starting out.

Hope this helps :)

codingwatching commented 3 years ago

Hi @Twometer It is over expected for me, thank you for the detailed explanation is network TCP or UDP when we connect to the server?

Twometer commented 3 years ago

Minecraft Java Edition uses a TCP Connection, normally on port 25565

codingwatching commented 3 years ago

Hi @Twometer Thank you, I will follow your link and read the protocol Could you please take a note of what is packets exchange between Server and Client after login? And for "Smooth chunk loading" feature of NextCraft, how to implement that? Thank you so much!

Twometer commented 3 years ago

The basic login packet sequence for an unencrypted connection is as follows:

This is described in more detail at wiki.vg here (however note that their login example is for an encrypted connection, which involves more steps.)

After that, the server sends the world data using the Map Chunk Bulk (ID 0x26) packets. A client is also required to respond to KeepAlive packets, or you will be disconnected from the server. You can update your position and rotation using the Player Position And Look packets (ID 0x03 through 0x06 IIRC). There are packets for block updates, for entity spawning, etc etc.

The "Smooth chunk loading" feature basically does two things

codingwatching commented 3 years ago

@Twometer Thank you so much!