Use SharedConstants, use server version when starting it

This commit is contained in:
creeper123123321 2019-02-08 18:33:13 -02:00
parent 1c9345ada5
commit 9d2103b011
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
3 changed files with 13 additions and 4 deletions

View File

@ -35,6 +35,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
import io.github.cottonmc.clientcommands.ArgumentBuilders;
import io.github.cottonmc.clientcommands.ClientCommands;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.events.ServerEvent;
import net.fabricmc.loader.FabricLoader;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
@ -78,5 +79,13 @@ public class VRViaVersionInitializer {
)
);
}
ServerEvent.START.register(server -> {
try {
ProtocolRegistry.SERVER_PROTOCOL = Via.getManager().getInjector().getServerProtocolVersion();
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

View File

@ -32,7 +32,7 @@ import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.SharedConstants;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
@ -95,7 +95,7 @@ public class ViaFabric implements ModInitializer {
while (matcher.find()) {
versions.add(matcher.group(1));
}
String mcVersion = MinecraftClient.getInstance().getGame().getVersion().getName();
String mcVersion = SharedConstants.getGameVersion().getName();
String bestViaVersion = null;
if (mcVersion.contains("w") || mcVersion.contains("-")) {
bestViaVersion = versions.stream()

View File

@ -24,7 +24,7 @@
package com.github.creeper123123321.viafabric.platform;
import net.minecraft.client.options.ServerEntry;
import net.minecraft.SharedConstants;
import us.myles.ViaVersion.api.platform.ViaInjector;
public class VRInjector implements ViaInjector {
@ -40,7 +40,7 @@ public class VRInjector implements ViaInjector {
@Override
public int getServerProtocolVersion() {
return new ServerEntry("", "", false).protocolVersion;
return SharedConstants.getGameVersion().getProtocolVersion();
}
@Override