GeyserMC / MCProtocolLib

A library for communication with a Minecraft client/server.
MIT License
721 stars 201 forks source link

Proposal: Multi-version? #686

Open perfectOfFantasy opened 2 years ago

perfectOfFantasy commented 2 years ago

Hi! It would be nice if your library supported multi-version (for example ViaVersion 1.8-1.18.1), I don't know if it's difficult to implement, but I hope you will add it. You can also make this mutiversion optional (i.e. activated by flags for a specific session or server in general)

NathanKassab commented 2 years ago

they're probably not going to do that, you're better off running VIAaaS or implementing via version yourself https://github.com/ViaVersion/VIAaaS

cxzlw commented 2 years ago

I don't know if it's hard to do. However, I found a python project called pycraft in GitHub, which can achieve multiple versions. Specifically, you can use the latest version to connect to the lower version server without switching version.

perfectOfFantasy commented 2 years ago

This isn't hard to do, on my other system which is on netty only with no other libraries I did ViaVersion implementations within 1 hour with fixing single bugs. However, they have recently introduced an interesting packet system which allows them to enter multiple versions manually, but it is a bit time consuming so the option is to use some packet generator (I've seen one that generated packages from wiki.vg) and just put them into the library. possibly implement packets that are used very often and remove the rest of packets and enter into the PacketLib library support for an unknown packet (i.e. if a disconnect packet is not implemented, it will read id and data anyway and forward it). In my opinion it would be better to enter all packages manually, but if you don't want to mess with data translation then it would be better to use ViaVersion.

cxzlw commented 2 years ago

This isn't hard to do, on my other system which is on netty only with no other libraries I did ViaVersion implementations within 1 hour with fixing single bugs. However, they have recently introduced an interesting packet system which allows them to enter multiple versions manually, but it is a bit time consuming so the option is to use some packet generator (I've seen one that generated packages from wiki.vg) and just put them into the library. possibly implement packets that are used very often and remove the rest of packets and enter into the PacketLib library support for an unknown packet (i.e. if a disconnect packet is not implemented, it will read id and data anyway and forward it). In my opinion it would be better to enter all packages manually, but if you don't want to mess with data translation then it would be better to use ViaVersion.

Can you teach me how to use the packet system which allows them to enter multiple versions manually? Thank you.

MrZomka commented 2 years ago

Why would MCProtocolLib devs spend time to teach you how to add multi version support when they won’t even add multi version support themselves?

cxzlw commented 2 years ago

Why would MCProtocolLib devs spend time to teach you how to add multi version support when they won’t even add multi version support themselves?

Are u one of MCProtocolLib devs? Am I asking u for help?

cxzlw commented 2 years ago

MCProtocolLib devs spend time to teach you

I really don't know the person who ask this question is one of MCProtocolLib devs.

perfectOfFantasy commented 2 years ago

This isn't hard to do, on my other system which is on netty only with no other libraries I did ViaVersion implementations within 1 hour with fixing single bugs. However, they have recently introduced an interesting packet system which allows them to enter multiple versions manually, but it is a bit time consuming so the option is to use some packet generator (I've seen one that generated packages from wiki.vg) and just put them into the library. possibly implement packets that are used very often and remove the rest of packets and enter into the PacketLib library support for an unknown packet (i.e. if a disconnect packet is not implemented, it will read id and data anyway and forward it). In my opinion it would be better to enter all packages manually, but if you don't want to mess with data translation then it would be better to use ViaVersion.

Can you teach me how to use the packet system which allows them to enter multiple versions manually? Thank you.

There will be quite a few classes on the current packet system if you would like to implement more versions. However, if this does not bother you then you need to get rid of reading & writing packets from the packet classes and make them abstract classes implementing Packet. Then for each such packet you need to create an implementation for a given version, for example LoginSuccessPacketCodecV1_18, and instead of recreating the constructor, you only need to implement only reading and writing methods. And when it comes to registering such a packet, you need to modify the MinecraftCodec class (package com.github.steveice10.mc.protocol.codec) and there either make a list and add PacketCodec there or just add additional variables in the form of CODEC1_18, CODEC1_16_5 and so further, it is only important not to do it this way when registering:

.registerPacket(packet id, packet.class, packet::new)

just like this: .registerPacket(packet id, packet.class, packet implementation::new).

//edit I forgot to add, remember that when creating a client / server you need to add the appropriate PacketCodec from the MinecraftCodec class in the MinecraftProtocol constructor. //

I explained it to you as much as I could, if I was wrong so sorry, good luck with implementation :)

cxzlw commented 2 years ago

This isn't hard to do, on my other system which is on netty only with no other libraries I did ViaVersion implementations within 1 hour with fixing single bugs. However, they have recently introduced an interesting packet system which allows them to enter multiple versions manually, but it is a bit time consuming so the option is to use some packet generator (I've seen one that generated packages from wiki.vg) and just put them into the library. possibly implement packets that are used very often and remove the rest of packets and enter into the PacketLib library support for an unknown packet (i.e. if a disconnect packet is not implemented, it will read id and data anyway and forward it). In my opinion it would be better to enter all packages manually, but if you don't want to mess with data translation then it would be better to use ViaVersion.

Can you teach me how to use the packet system which allows them to enter multiple versions manually? Thank you.

There will be quite a few classes on the current packet system if you would like to implement more versions. However, if this does not bother you then you need to get rid of reading & writing packets from the packet classes and make them abstract classes implementing Packet. Then for each such packet you need to create an implementation for a given version, for example LoginSuccessPacketCodecV1_18, and instead of recreating the constructor, you only need to implement only reading and writing methods. And when it comes to registering such a packet, you need to modify the MinecraftCodec class (package com.github.steveice10.mc.protocol.codec) and there either make a list and add PacketCodec there or just add additional variables in the form of CODEC1_18, CODEC1_16_5 and so further, it is only important not to do it this way when registering:

.registerPacket(packet id, packet.class, packet::new)

just like this: .registerPacket(packet id, packet.class, packet implementation::new).

//edit I forgot to add, remember that when creating a client / server you need to add the appropriate PacketCodec from the MinecraftCodec class in the MinecraftProtocol constructor. //

I explained it to you as much as I could, if I was wrong so sorry, good luck with implementation :)

Thank you very much. I will try to learn it. And have a try. Thank you.

Redned235 commented 2 years ago

This is something we've been looking in to as a long-term plan of MCProtocolLib. As mentioned the groundwork for such a system already exists but will require some digging into the codebase and messing around with packet codecs if you want to achieve multi version capability today. Ultimately we've not settled on a final decision yet but I'll keep this open to see what others think of more polished multi version support within the library