2023-05-28 19:19:59 +02:00
# ViaLoader
2023-09-23 19:41:11 +02:00
Easy to use ViaVersion, (and optional ViaBackwards, ViaRewind, ViaLegacy, ViaAprilFools and ViaBedrock) platform implementation.
2023-01-04 17:12:10 +01:00
2023-05-28 19:19:59 +02:00
ViaLoader is not usable by itself as a standalone software, as it is an implementation of a ViaVersion platform.
2023-01-04 17:12:10 +01:00
2023-05-28 19:19:59 +02:00
### Projects implementing ViaLoader
- [ViaProxy ](https://github.com/ViaVersion/ViaProxy ): Standalone proxy which allows players to join EVERY Minecraft server version (Classic, Alpha, Beta, Release, Bedrock).
2023-10-08 09:30:40 +02:00
- [ViaForge ](https://github.com/ViaVersion/ViaForge ): Client-side Implementation of ViaVersion, ViaBackwards and ViaRewind for Legacy Minecraft Forge.
2023-05-28 19:19:59 +02:00
- [ViaFabricPlus ](https://github.com/ViaVersion/ViaFabricPlus ): Fabric mod to connect to EVERY Minecraft server version (Release, Beta, Alpha, Classic, Snapshots, Bedrock) with QoL fixes to the gameplay.
2023-01-04 01:01:32 +01:00
## Releases
### Gradle/Maven
2023-05-28 19:19:59 +02:00
To use ViaLoader with Gradle/Maven you can use the ViaVersion maven server:
```groovy
repositories {
maven { url "https://repo.viaversion.com" }
}
dependencies {
2023-10-17 12:58:37 +02:00
implementation("net.raphimc:ViaLoader:x.x.x") // Get latest version from releases
2023-05-28 19:19:59 +02:00
}
```
```xml
< repositories >
< repository >
< id > viaversion< / id >
< url > https://repo.viaversion.com< / url >
< / repository >
< / repositories >
< dependencies >
< dependency >
< groupId > net.raphimc< / groupId >
< artifactId > ViaLoader< / artifactId >
2023-10-17 12:58:37 +02:00
< version > x.x.x< / version > <!-- Get latest version from releases -->
2023-05-28 19:19:59 +02:00
< / dependency >
< / dependencies >
```
2023-01-04 01:01:32 +01:00
### Jar File
2023-10-17 13:10:05 +02:00
If you just want the latest jar file you can download it from [GitHub Actions ](https://github.com/RaphiMC/ViaLoader/actions/workflows/build.yml ) or the [ViaVersion Jenkins ](https://ci.viaversion.com/view/All/job/ViaLoader/ ).
2023-01-04 01:01:32 +01:00
## Usage
2023-05-28 19:19:59 +02:00
To use ViaLoader in your project you need to decide what components of Via* you want to use.
2023-08-03 22:38:05 +02:00
ViaLoader is split into 6 different components:
2023-05-28 19:19:59 +02:00
- ViaVersion (Is the base component of ViaLoader [required])
2023-01-04 17:12:10 +01:00
- ViaBackwards (Allows older clients to join to newer server versions [needs ViaVersion])
- ViaRewind (Allows 1.8.x and 1.7.x clients to join to 1.9+ servers [needs ViaBackwards])
2023-03-01 17:21:05 +01:00
- ViaLegacy (Allows clients to join to < = 1.7.10 servers [needs ViaVersion])
2023-04-12 17:34:56 +02:00
- ViaAprilFools (Allows clients to join to some notable Minecraft snapshots [needs ViaBackwards])
2023-08-03 22:38:05 +02:00
- ViaBedrock (Allows clients to join to Bedrock edition servers [needs ViaVersion])
2023-01-04 17:12:10 +01:00
2023-08-03 22:38:05 +02:00
In case you want to include ViaBedrock, you have to add the Lenni0451 maven repository to your build script:
2023-01-04 17:12:10 +01:00
```groovy
repositories {
maven {
2023-09-21 18:03:25 +02:00
name = "Lenni0451"
url = "https://maven.lenni0451.net/everything"
2023-01-04 17:12:10 +01:00
}
}
```
Here is an example dependency configuration for all components:
```groovy
2024-08-08 17:52:50 +02:00
implementation "com.viaversion:viaversion:5.0.3"
implementation "com.viaversion:viabackwards-common:5.0.3"
2024-07-28 21:37:13 +02:00
implementation "com.viaversion:viarewind-common:4.0.2"
implementation "net.raphimc:ViaLegacy:3.0.2"
implementation "net.raphimc:ViaAprilFools:3.0.1"
implementation "net.raphimc:ViaBedrock:0.0.10-SNAPSHOT"
2023-01-04 17:12:10 +01:00
```
## Implementation
2023-05-28 19:19:59 +02:00
To implement ViaLoader into your project you need to initialize the Via* platforms first.
ViaLoader provides a wrapper class with default values for that. To use a default value you can just pass ``null`` to that argument.
2023-01-04 17:12:10 +01:00
If you want to change the default value you should create your own class which extends the base class and overrides the methods you want to change.
2024-07-24 12:38:06 +02:00
The only default value you have to change is the ``VLLoader`` argument. The loader is used to register all the providers for the Via* platforms.
Providers are used to provide information about the platform to ViaVersion when it's (almost) impossible to get them ourselves.
To override the default you first create a new class which extends ``VLLoader`` and overrides the ``load`` method.
2023-01-04 17:12:10 +01:00
Within the ``load`` method you have to register a ``VersionProvider`` implementation which will be used to determine the target server version of a given connection.
Here is an example implementation:
```java
2024-07-24 12:38:06 +02:00
public class CustomVLLoaderImpl extends VLLoader {
2023-01-04 17:12:10 +01:00
@Override
2024-07-24 12:38:06 +02:00
public void load() {
super.load();
Via.getManager().getProviders().use(VersionProvider.class, new BaseVersionProvider() {
@Override
public ProtocolVersion getClosestServerProtocol(UserConnection connection) {
// Change the logic here to select the target server version
return ProtocolVersion.v1_8;
}
});
2023-01-04 17:12:10 +01:00
}
2024-07-24 12:38:06 +02:00
}
2023-01-04 17:12:10 +01:00
```
2023-05-28 19:19:59 +02:00
Then you have to create a new instance of your loader class and pass it to the ``ViaLoader.init`` call.
2023-01-04 17:12:10 +01:00
2023-05-28 19:19:59 +02:00
To do this you can call the ``ViaLoader.init()`` method somewhere suitable in your project (You can do that async) with your desired argument values:
2023-01-04 17:12:10 +01:00
```java
2024-07-24 12:38:06 +02:00
ViaLoader.init(null/*ViaPlatform*/, new CustomVLLoaderImpl(), null/*ViaInjector*/, null/*ViaCommandHandler*/, ViaBackwardsPlatformImpl::new, ViaRewindPlatforImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new);
2023-01-04 17:12:10 +01:00
```
2024-07-24 12:38:06 +02:00
Make sure to have all platform impls you need added to the init call. Every platform added there needs to be in your dependencies.
2023-01-04 17:12:10 +01:00
2023-05-28 19:19:59 +02:00
After you have initialized the Via* platforms you can start implementing ViaLoader into your project.
2023-01-04 17:12:10 +01:00
2024-07-24 12:38:06 +02:00
### Netty modifications
2023-01-04 17:12:10 +01:00
The most important part is the modification of your netty pipeline. This is needed for ViaVersion to translate the packets in both ways.
2024-07-24 12:38:06 +02:00
Our recommended way is to use the `VLPipeline` (for codec based pipelines) or the `VLLegacyPipeline` (for decoder/encoder pipelines) as it
automatically handles the modifications required for all Via* platforms.
2023-01-04 17:12:10 +01:00
Here is an example implementation:
```java
2024-07-24 12:38:06 +02:00
public class CustomVLPipeline extends VLPipeline {
2024-08-06 14:43:59 +02:00
public CustomVLPipeline(UserConnection user) {
2024-07-24 12:38:06 +02:00
super(user);
}
// Replace these with the names of your pipeline components
@Override
protected String compressionCodecName() {
return "compression_codec";
}
@Override
protected String packetCodecName() {
return "packet_codec";
}
@Override
protected String lengthCodecName() {
return "length_codec";
}
}
```
The same can be done for the `VLLegacyPipeline` with similar functions for the decoder/encoder pairs.
Then you can add the Via* pipeline to your netty pipeline:
```java
2023-11-12 18:00:30 +01:00
final UserConnection user = new UserConnectionImpl(channel, true/*clientside or serverside*/);
2023-01-04 17:12:10 +01:00
new ProtocolPipelineImpl(user);
2024-07-24 12:38:06 +02:00
channel.pipeline().addLast(new CustomVLPipeline(user));
```
Both `VLPipeline` and `VLLegacyPipeline` contain various functions allowing you to modify/wrap the existing pipeline elements,
if you need a more complex/dynamic pipeline setup you can also manually add the Via* handlers to the pipeline.
Here is an example implementation:
```java
final UserConnection user = new UserConnectionImpl(channel, true/*clientside or serverside*/);
new ProtocolPipelineImpl(user);
//channel.pipeline().addBefore("packet_decoder", VLLegacyPipeline.VIA_DECODER_NAME, new ViaDecoder(user));
//channel.pipeline().addBefore("packet_encoder", VLLegacyPipeline.VIA_ENCODER_NAME, new ViaEncoder(user));
2023-05-28 19:19:59 +02:00
channel.pipeline().addBefore("packet_codec", VLPipeline.VIA_CODEC_NAME, new ViaCodec(user));
2023-01-04 17:12:10 +01:00
```
2024-07-24 12:38:06 +02:00
If you are using ViaLegacy, you should read its [README ](https://github.com/ViaVersion/ViaLegacy?tab=readme-ov-file#vialegacy ) to see what changes you need to make to the netty pipeline for it to work.
2023-05-28 19:19:59 +02:00
Depending on where you are implementing ViaLoader you might need to ensure that the pipeline is held in the correct order.
2023-01-04 17:12:10 +01:00
Minecraft clients modify the pipeline order when adding the compression handlers. You have to ensure that the Via* handlers are always on their correct location.
2024-07-24 12:38:06 +02:00
If you are using the `VLPipeline` or `VLLegacyPipeline` you can fire the `CompressionReorderEvent` once the compression handler is added to the pipeline.
2023-01-04 17:12:10 +01:00
Now you should have a working protocol translator implementation in your project.
2023-04-12 08:39:22 +02:00
## Configuring the protocol translation
2023-05-28 19:19:59 +02:00
To change the protocol translation settings/features you can look into the ViaLoader folder.
2023-04-12 08:39:22 +02:00
You can find 5 config files there depending on the platforms loaded:
- viaversion.yml (ViaVersion)
2023-10-08 09:31:47 +02:00
- viabackwards.yml (ViaBackwards)
2023-04-12 08:39:22 +02:00
- viarewind.yml (ViaRewind)
- vialegacy.yml (ViaLegacy)
- viabedrock.yml (ViaBedrock)
2023-01-04 17:12:10 +01:00
## Contact
If you encounter any issues, please report them on the
2023-07-25 19:41:48 +02:00
[issue tracker ](https://github.com/ViaVersion/ViaLoader/issues ).
2023-05-30 21:48:30 +02:00
If you just want to talk or need help implementing ViaLoader feel free to join the ViaVersion
[Discord ](https://discord.gg/viaversion ).