pyCraft icon indicating copy to clipboard operation
pyCraft copied to clipboard

A document of coding a packet classes is needed

Open 276562578 opened this issue 5 years ago • 3 comments

I want to code other functionality with pyCraft and add them under minecraft/networking/packets. But the stucture of class packet may be too complex to code for coder which hasn't enough experience of python just like me. So, could you write a document to teach how to write a other functionality packet class? Thank you very much!

276562578 avatar Feb 24 '20 02:02 276562578

Trust me at the beginning it is somewhat tricky, but essentially everything you need to add packets is already there. You just need to bring the time and motivation to add it.

Let me try to give you a high level overview:

  • how packets are look like is documented in https://wiki.vg/Protocol. This is a non-official documentation and thus just might give you a rough indicator on what data is included in a packet. Please note that the data what a packet might contain can change between versions, or new versions can bring new packets. To reflect such changes the specific data is usually 'attached' to a protocol id. Depending on what type of packet you are looking at this might range from protocol id 47 (minecraft version 1.8.9) to protocol id 578 (minecraft version 1.15.2). Now the link above just provides you the latest.
  • to get an overview of a specific packet and the relevant versions I'd refer to https://joodicator.github.io/mc-dev-data/ which is essentially a high level overview of such changes.
  • let me perhaps try to explain on a example packet (e.g. EntityVelocityPacket): in the get_id-method you essentially see that the packet id has changed with different versions. However the content of the packet that is encoded within the get_definition-property stayed the same across all versions so far and thus has not changed. The reflecting packet is also documented on the protocol page (https://wiki.vg/Protocol#Entity_Velocity) with the same data fields.
  • A slightly more complex example would be the RespawnPacket, which also has the get_id-method recording the change of the packet id across different versions. You might notice some if-conditions in the get_definition-property. This essentially encodes the packet content changes across different versions. It means before protocol_version 464 this packet had a field difficulty of type UnsignedByte. The field 'hashed_seed': Long} was introduced with protocol_version 552. All other fields are the same across versions.

So in order to add a new packet, you'd need to go through the overview and find out which protocol versions had changed what part of the packet (is it just the id that changed, or the structure of data). To upgrade this client to a newer version you'd need to do this process for all existing packets which IMHO is a very tedious process with the constant protocol and packet updates....

TheSnoozer avatar Feb 24 '20 20:02 TheSnoozer

@TheSnoozer very appreciate your help! In fact, I was confused by "Advance Usage" of python in this project more than others. So I need a document to tell me what is each part of "Packet Class". A fully example will be great helpful.

276562578 avatar Feb 25 '20 01:02 276562578

@276562578 Kinda old but in case you still need it I created a new issue with a full guide.

Codehc avatar Dec 06 '20 18:12 Codehc