diff --git a/gradle.properties b/gradle.properties index 6efd52b..1280f71 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,8 +7,8 @@ maven_version=3.6.0-SNAPSHOT maven_group=de.florianmichael # ViaVersion -viaversion_version=4.10.0-24w06a-SNAPSHOT -viabackwards_version=4.10.0-24w06a-SNAPSHOT +viaversion_version=4.10.0-24w07a-SNAPSHOT +viabackwards_version=4.10.0-24w07a-SNAPSHOT viarewind_version=3.0.6-SNAPSHOT vialegacy_version=2.2.22-SNAPSHOT viaaprilfools_version=2.0.11-SNAPSHOT diff --git a/src/main/java/de/florianmichael/viaforge/common/ViaForgeCommon.java b/src/main/java/de/florianmichael/viaforge/common/ViaForgeCommon.java index d1bd89e..3354a0c 100644 --- a/src/main/java/de/florianmichael/viaforge/common/ViaForgeCommon.java +++ b/src/main/java/de/florianmichael/viaforge/common/ViaForgeCommon.java @@ -19,6 +19,7 @@ package de.florianmichael.viaforge.common; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.connection.UserConnectionImpl; import com.viaversion.viaversion.protocol.ProtocolPipelineImpl; import de.florianmichael.viaforge.common.platform.VFPlatform; @@ -33,7 +34,6 @@ import io.netty.util.AttributeKey; import net.raphimc.vialoader.ViaLoader; import net.raphimc.vialoader.impl.platform.*; import net.raphimc.vialoader.netty.CompressionReorderEvent; -import net.raphimc.vialoader.util.VersionEnum; import java.io.File; @@ -49,7 +49,7 @@ public class ViaForgeCommon { private static ViaForgeCommon manager; private final VFPlatform platform; - private VersionEnum targetVersion; + private ProtocolVersion targetVersion; private ViaForgeConfig config; @@ -66,8 +66,8 @@ public class ViaForgeCommon { if (manager != null) { return; // Already initialized, ignore it then :tm: } - final VersionEnum version = VersionEnum.fromProtocolId(platform.getGameVersion()); - if (version == VersionEnum.UNKNOWN) { + final ProtocolVersion version = ProtocolVersion.getProtocol(platform.getGameVersion()); // ViaForge will only load on post-netty versions + if (version == ProtocolVersion.unknown) { throw new IllegalArgumentException("Unknown version " + platform.getGameVersion()); } @@ -78,8 +78,8 @@ public class ViaForgeCommon { ViaLoader.init(new ViaVersionPlatformImpl(mainFolder), new ViaForgeVLLoader(platform), new ViaForgeVLInjector(), null, ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new); manager.config = new ViaForgeConfig(new File(mainFolder, "viaforge.yml")); - final VersionEnum configVersion = VersionEnum.fromProtocolId(manager.config.getClientSideVersion()); - if (configVersion != VersionEnum.UNKNOWN) { + final ProtocolVersion configVersion = ProtocolVersion.getClosest(manager.config.getClientSideVersion()); + if (configVersion != null) { manager.setTargetVersion(configVersion); } else { manager.setTargetVersion(version); @@ -114,25 +114,25 @@ public class ViaForgeCommon { channel.pipeline().fireUserEventTriggered(CompressionReorderEvent.INSTANCE); } - public VersionEnum getNativeVersion() { - return VersionEnum.fromProtocolId(platform.getGameVersion()); + public ProtocolVersion getNativeVersion() { + return ProtocolVersion.getProtocol(platform.getGameVersion()); } - public VersionEnum getTargetVersion() { + public ProtocolVersion getTargetVersion() { return targetVersion; } public void restoreVersion() { - this.targetVersion = VersionEnum.fromProtocolId(config.getClientSideVersion()); + this.targetVersion = ProtocolVersion.getClosest(config.getClientSideVersion()); } - public void setTargetVersionSilent(final VersionEnum targetVersion) { + public void setTargetVersionSilent(final ProtocolVersion targetVersion) { this.targetVersion = targetVersion; } - public void setTargetVersion(final VersionEnum targetVersion) { + public void setTargetVersion(final ProtocolVersion targetVersion) { this.targetVersion = targetVersion; - config.setClientSideVersion(targetVersion.getVersion()); + config.setClientSideVersion(targetVersion.getName()); } public VFPlatform getPlatform() { diff --git a/src/main/java/de/florianmichael/viaforge/common/gui/ExtendedServerData.java b/src/main/java/de/florianmichael/viaforge/common/gui/ExtendedServerData.java index dfb380b..487afb6 100644 --- a/src/main/java/de/florianmichael/viaforge/common/gui/ExtendedServerData.java +++ b/src/main/java/de/florianmichael/viaforge/common/gui/ExtendedServerData.java @@ -18,15 +18,15 @@ package de.florianmichael.viaforge.common.gui; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; /** * This interface is used to store the target version for a specific server in the server list. */ public interface ExtendedServerData { - VersionEnum viaForge$getVersion(); + ProtocolVersion viaForge$getVersion(); - void viaForge$setVersion(final VersionEnum version); + void viaForge$setVersion(final ProtocolVersion version); } diff --git a/src/main/java/de/florianmichael/viaforge/common/platform/VFPlatform.java b/src/main/java/de/florianmichael/viaforge/common/platform/VFPlatform.java index f9ca471..8033289 100644 --- a/src/main/java/de/florianmichael/viaforge/common/platform/VFPlatform.java +++ b/src/main/java/de/florianmichael/viaforge/common/platform/VFPlatform.java @@ -19,7 +19,6 @@ package de.florianmichael.viaforge.common.platform; import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; -import net.raphimc.vialoader.util.VersionEnum; import java.io.File; import java.util.function.Supplier; diff --git a/src/main/java/de/florianmichael/viaforge/common/platform/ViaForgeConfig.java b/src/main/java/de/florianmichael/viaforge/common/platform/ViaForgeConfig.java index 93c18f0..8982939 100644 --- a/src/main/java/de/florianmichael/viaforge/common/platform/ViaForgeConfig.java +++ b/src/main/java/de/florianmichael/viaforge/common/platform/ViaForgeConfig.java @@ -18,6 +18,7 @@ package de.florianmichael.viaforge.common.platform; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.util.Config; import com.viaversion.viaversion.util.Pair; @@ -70,11 +71,14 @@ public class ViaForgeConfig extends Config { save(); // Automatically save the config when something changes } - public int getClientSideVersion() { - return getInt(CLIENT_SIDE_VERSION, 0); + public String getClientSideVersion() { + if (getInt(CLIENT_SIDE_VERSION, -1) != -1) { // Temporary fix for old configs + return ProtocolVersion.getProtocol(getInt(CLIENT_SIDE_VERSION, -1)).getName(); + } + return getString(CLIENT_SIDE_VERSION, ""); } - public void setClientSideVersion(final int version) { + public void setClientSideVersion(final String version) { set(CLIENT_SIDE_VERSION, version); } diff --git a/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/VFNetworkManager.java b/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/VFNetworkManager.java index e695f3a..47628cd 100644 --- a/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/VFNetworkManager.java +++ b/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/VFNetworkManager.java @@ -18,7 +18,7 @@ package de.florianmichael.viaforge.common.protocolhack.netty; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; public interface VFNetworkManager { @@ -31,13 +31,13 @@ public interface VFNetworkManager { /** * @return the target version of the connection */ - VersionEnum viaForge$getTrackedVersion(); + ProtocolVersion viaForge$getTrackedVersion(); /** * Sets the target version of the connection. * * @param version the target version */ - void viaForge$setTrackedVersion(final VersionEnum version); + void viaForge$setTrackedVersion(final ProtocolVersion version); } diff --git a/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/ViaForgeVLLegacyPipeline.java b/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/ViaForgeVLLegacyPipeline.java index 38cd500..68061cc 100644 --- a/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/ViaForgeVLLegacyPipeline.java +++ b/src/main/java/de/florianmichael/viaforge/common/protocolhack/netty/ViaForgeVLLegacyPipeline.java @@ -19,12 +19,12 @@ package de.florianmichael.viaforge.common.protocolhack.netty; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; public class ViaForgeVLLegacyPipeline extends VLLegacyPipeline { - public ViaForgeVLLegacyPipeline(UserConnection user, VersionEnum version) { + public ViaForgeVLLegacyPipeline(UserConnection user, ProtocolVersion version) { super(user, version); } diff --git a/src/main/java/de/florianmichael/viaforge/common/protocolhack/provider/ViaForgeVersionProvider.java b/src/main/java/de/florianmichael/viaforge/common/protocolhack/provider/ViaForgeVersionProvider.java index 0f36fa5..06e6df4 100644 --- a/src/main/java/de/florianmichael/viaforge/common/protocolhack/provider/ViaForgeVersionProvider.java +++ b/src/main/java/de/florianmichael/viaforge/common/protocolhack/provider/ViaForgeVersionProvider.java @@ -19,16 +19,16 @@ package de.florianmichael.viaforge.common.protocolhack.provider; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.protocols.base.BaseVersionProvider; import de.florianmichael.viaforge.common.ViaForgeCommon; -import net.raphimc.vialoader.util.VersionEnum; public class ViaForgeVersionProvider extends BaseVersionProvider { @Override - public int getClosestServerProtocol(UserConnection connection) throws Exception { + public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception { if (connection.isClientSide() && !ViaForgeCommon.getManager().getPlatform().isSingleplayer().get()) { - return connection.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).get().viaForge$getTrackedVersion().getVersion(); + return connection.getChannel().attr(ViaForgeCommon.VF_NETWORK_MANAGER).get().viaForge$getTrackedVersion(); } return super.getClosestServerProtocol(connection); } diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index 65b9b56..1005ff8 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -20,13 +20,13 @@ package de.florianmichael.viaforge.gui; import com.mojang.realmsclient.gui.ChatFormatting; import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.util.DumpUtil; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiSlot; -import net.raphimc.vialoader.util.VersionEnum; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -133,12 +133,12 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected int getSize() { - return VersionEnum.SORTED_VERSIONS.size(); + return ProtocolVersion.getProtocols().size(); } @Override protected void elementClicked(int index, boolean b, int i1, int i2) { - finishedCallback.finished(VersionEnum.SORTED_VERSIONS.get(index), parent); + finishedCallback.finished(ProtocolVersion.getProtocols().get(index), parent); } @Override @@ -153,8 +153,8 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int mouseY, float partialTicks) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); - final VersionEnum version = VersionEnum.SORTED_VERSIONS.get(index); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ProtocolVersion.getProtocols().get(index); String color; if (targetVersion == version) { @@ -169,7 +169,7 @@ public class GuiProtocolSelector extends GuiScreen { public interface FinishedCallback { - void finished(final VersionEnum version, final GuiScreen parent); + void finished(final ProtocolVersion version, final GuiScreen parent); } } diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java index 8630794..ac88fbd 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java @@ -22,7 +22,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.Minecraft; import net.minecraft.network.NetworkManager; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -38,7 +38,7 @@ public class MixinGuiConnecting_1 { // use it to determine the protocol version to use. // We hope that the current server data is not null if (Minecraft.getMinecraft().getCurrentServerData() instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) Minecraft.getMinecraft().getCurrentServerData()).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) Minecraft.getMinecraft().getCurrentServerData()).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java index a4c4bb2..b6d1377 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java @@ -18,10 +18,10 @@ package de.florianmichael.viaforge.mixin.impl; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.gui.GuiOverlayDebug; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -35,13 +35,13 @@ public class MixinGuiOverlayDebug { @Inject(method = "getDebugInfoRight", at = @At(value = "TAIL")) public void addViaForgeVersion(CallbackInfoReturnable> cir) { final ViaForgeCommon common = ViaForgeCommon.getManager(); - final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion(); if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) { cir.getReturnValue().add(""); int protocolVersion = version.getVersion(); - if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches // So we need to unmap the version to get the real protocol version id protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion); diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java index 412a3d0..14a2f18 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java @@ -18,6 +18,7 @@ package de.florianmichael.viaforge.mixin.impl; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.util.Pair; import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; @@ -27,7 +28,6 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreenAddServer; import net.minecraft.client.multiplayer.ServerData; -import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -47,7 +47,7 @@ public class MixinGuiScreenAddServer extends GuiScreen { if (config.isShowAddServerButton()) { final Pair pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height); - final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion(); + final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion(); buttonList.add(new GuiButton(1_000_000_000, pos.key(), pos.value(), 100, 20, target != null ? target.getName() : "Set Version")); } } diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java index 2078200..a104edf 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java @@ -25,8 +25,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.network.NetHandlerLoginClient; import net.minecraft.network.NetworkManager; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -41,7 +42,7 @@ public class MixinNetHandlerLoginClient { @Redirect(method = "handleEncryptionRequest", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V")) public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { final UserConnection user = networkManager.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get(); if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) { // We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java index 3755be6..2936445 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java @@ -27,8 +27,9 @@ import net.minecraft.network.NetworkManager; import net.minecraft.util.CryptManager; import net.minecraft.util.LazyLoadBase; import net.minecraft.util.text.ITextComponent; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -51,7 +52,7 @@ public class MixinNetworkManager implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "createNetworkManagerAndConnect", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD) private static void trackSelfTarget(InetAddress address, int serverPort, boolean useNativeTransport, CallbackInfoReturnable cir, NetworkManager networkmanager, Class oclass, LazyLoadBase lazyloadbase) { @@ -64,7 +65,7 @@ public class MixinNetworkManager implements VFNetworkManager { @Inject(method = "enableEncryption", at = @At("HEAD"), cancellable = true) private void storeEncryptionCiphers(SecretKey key, CallbackInfo ci) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Minecraft's encryption code is bad for us, we need to reorder the pipeline ci.cancel(); @@ -96,12 +97,12 @@ public class MixinNetworkManager implements VFNetworkManager { } @Override - public VersionEnum viaForge$getTrackedVersion() { + public ProtocolVersion viaForge$getTrackedVersion() { return viaForge$targetVersion; } @Override - public void viaForge$setTrackedVersion(VersionEnum version) { + public void viaForge$setTrackedVersion(ProtocolVersion version) { viaForge$targetVersion = version; } diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java index 120d646..8344531 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java @@ -18,10 +18,10 @@ package de.florianmichael.viaforge.mixin.impl; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.nbt.NBTTagCompound; -import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,19 +34,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class MixinServerData implements ExtendedServerData { @Unique - private VersionEnum viaForge$version; + private ProtocolVersion viaForge$version; @Inject(method = "getNBTCompound", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;setString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) public void saveVersion(CallbackInfoReturnable cir, NBTTagCompound nbttagcompound) { if (viaForge$version != null) { - nbttagcompound.setInteger("viaForge$version", viaForge$version.getVersion()); + nbttagcompound.setString("viaForge$version", viaForge$version.getName()); } } @Inject(method = "getServerDataFromNBTCompound", at = @At(value = "TAIL")) private static void getVersion(NBTTagCompound nbtCompound, CallbackInfoReturnable cir) { if (nbtCompound.hasKey("viaForge$version")) { - ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(nbtCompound.getInteger("viaForge$version"))); + ProtocolVersion version; + if (nbtCompound.getInteger("viaForge$version") != 0) { // Temporary fix for old versions + version = ProtocolVersion.getProtocol(nbtCompound.getInteger("viaForge$version")); + } else { + version = ProtocolVersion.getClosest(nbtCompound.getString("viaForge$version")); + } + ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version); } } @@ -58,12 +64,12 @@ public class MixinServerData implements ExtendedServerData { } @Override - public VersionEnum viaForge$getVersion() { + public ProtocolVersion viaForge$getVersion() { return viaForge$version; } @Override - public void viaForge$setVersion(VersionEnum version) { + public void viaForge$setVersion(ProtocolVersion version) { viaForge$version = version; } diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java index 98ee772..69fed6b 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java @@ -18,12 +18,12 @@ package de.florianmichael.viaforge.mixin.impl; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.network.ServerPinger; import net.minecraft.network.NetworkManager; -import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -51,7 +51,7 @@ public class MixinServerPinger { // We hope that the current server data is not null if (viaForge$serverData instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java index 1133c24..e4e778e 100644 --- a/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java +++ b/viaforge-mc112/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java @@ -19,11 +19,11 @@ package de.florianmichael.viaforge.mixin.impl.fixes; import com.mojang.authlib.GameProfile; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.world.World; -import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +40,7 @@ public class MixinEntityPlayerSP extends AbstractClientPlayer { @Redirect(method = "onUpdateWalkingPlayer", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/EntityPlayerSP;prevOnGround:Z", ordinal = 0)) public boolean emulateIdlePacket(EntityPlayerSP instance) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes // So we invert the original logic: // if (prevOnGround != onGround) sendPacket diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index acdb342..d401726 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -29,7 +29,7 @@ import net.minecraft.client.gui.widget.list.AbstractList; import net.minecraft.client.gui.widget.list.ExtendedList; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; @@ -122,44 +122,44 @@ public class GuiProtocolSelector extends Screen { public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) { super(client, width, height, top, bottom, slotHeight); - for (VersionEnum version : VersionEnum.SORTED_VERSIONS) { + for (ProtocolVersion version : ProtocolVersion.getProtocols()) { addEntry(new SlotEntry(version)); } } public class SlotEntry extends AbstractList.AbstractListEntry { - private final VersionEnum versionEnum; + private final ProtocolVersion ProtocolVersion; - public SlotEntry(VersionEnum versionEnum) { - this.versionEnum = versionEnum; + public SlotEntry(ProtocolVersion ProtocolVersion) { + this.ProtocolVersion = ProtocolVersion; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent); + GuiProtocolSelector.this.finishedCallback.finished(ProtocolVersion, GuiProtocolSelector.this.parent); return super.mouseClicked(mouseX, mouseY, button); } @Override public void render(MatrixStack matrices, int p_230432_2_, int y, int p_230432_4_, int p_230432_5_, int p_230432_6_, int p_230432_7_, int p_230432_8_, boolean p_230432_9_, float p_230432_10_) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); String color; - if (targetVersion == versionEnum) { + if (targetVersion == ProtocolVersion) { color = GuiProtocolSelector.this.simple ? TextFormatting.GOLD.toString() : TextFormatting.GREEN.toString(); } else { color = GuiProtocolSelector.this.simple ? TextFormatting.WHITE.toString() : TextFormatting.DARK_RED.toString(); } - drawCenteredString(matrices, Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1); + drawCenteredString(matrices, Minecraft.getInstance().font, color + ProtocolVersion.getName(), width / 2, y, -1); } } } public interface FinishedCallback { - void finished(final VersionEnum version, final Screen parent); + void finished(final ProtocolVersion version, final Screen parent); } diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinAddServerScreen.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinAddServerScreen.java index 1dd5988..9133ba3 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinAddServerScreen.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinAddServerScreen.java @@ -29,7 +29,7 @@ import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -53,7 +53,7 @@ public class MixinAddServerScreen extends Screen { if (config.isShowAddServerButton()) { final Pair pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height); - final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion(); + final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion(); addButton(new Button(pos.key(), pos.value(), 100, 20, new StringTextComponent(target != null ? target.getName() : "Set Version"), b -> { minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> { // Set version and go back to the parent screen. diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinClientLoginNetHandler.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinClientLoginNetHandler.java index 2ebed18..4083ba7 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinClientLoginNetHandler.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinClientLoginNetHandler.java @@ -25,8 +25,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.network.login.ClientLoginNetHandler; import net.minecraft.network.NetworkManager; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -41,7 +42,7 @@ public class MixinClientLoginNetHandler { @Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V")) public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get(); if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) { // We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectingScreen_1.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectingScreen_1.java index 1e7ca3a..ac01fc0 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectingScreen_1.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectingScreen_1.java @@ -22,7 +22,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.Minecraft; import net.minecraft.network.NetworkManager; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -38,7 +38,7 @@ public class MixinConnectingScreen_1 { // use it to determine the protocol version to use. // We hope that the current server data is not null if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugOverlayGui.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugOverlayGui.java index 2656598..0837c32 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugOverlayGui.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugOverlayGui.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.gui.overlay.DebugOverlayGui; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -35,13 +35,13 @@ public class MixinDebugOverlayGui { @Inject(method = "getSystemInformation", at = @At(value = "TAIL")) public void addViaForgeVersion(CallbackInfoReturnable> cir) { final ViaForgeCommon common = ViaForgeCommon.getManager(); - final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion(); if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) { cir.getReturnValue().add(""); int protocolVersion = version.getVersion(); - if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches // So we need to unmap the version to get the real protocol version id protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion); diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinNetworkManager.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinNetworkManager.java index a87c026..2595cdc 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinNetworkManager.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinNetworkManager.java @@ -27,8 +27,9 @@ import net.minecraft.network.NetworkManager; import net.minecraft.util.CryptManager; import net.minecraft.util.LazyValue; import net.minecraft.util.text.ITextComponent; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -51,7 +52,7 @@ public class MixinNetworkManager implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD) private static void trackSelfTarget(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_, CallbackInfoReturnable cir, NetworkManager networkmanager, Class oclass, LazyValue lazyvalue) { @@ -64,7 +65,7 @@ public class MixinNetworkManager implements VFNetworkManager { @Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true) private void storeEncryptionCiphers(Cipher p_244777_1_, Cipher p_244777_2_, CallbackInfo ci) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Minecraft's encryption code is bad for us, we need to reorder the pipeline ci.cancel(); @@ -96,12 +97,12 @@ public class MixinNetworkManager implements VFNetworkManager { } @Override - public VersionEnum viaForge$getTrackedVersion() { + public ProtocolVersion viaForge$getTrackedVersion() { return viaForge$targetVersion; } @Override - public void viaForge$setTrackedVersion(VersionEnum version) { + public void viaForge$setTrackedVersion(ProtocolVersion version) { viaForge$targetVersion = version; } diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java index de7e3a0..21f848d 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.nbt.CompoundNBT; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,19 +34,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class MixinServerData implements ExtendedServerData { @Unique - private VersionEnum viaForge$version; + private ProtocolVersion viaForge$version; @Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundNBT;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) public void saveVersion(CallbackInfoReturnable cir, CompoundNBT compoundnbt) { if (viaForge$version != null) { - compoundnbt.putInt("viaForge$version", viaForge$version.getVersion()); + compoundnbt.putString("viaForge$version", viaForge$version.getName()); } } @Inject(method = "read", at = @At(value = "TAIL")) private static void getVersion(CompoundNBT compoundnbt, CallbackInfoReturnable cir) { if (compoundnbt.contains("viaForge$version")) { - ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version"))); + ProtocolVersion version; + if (compoundnbt.getInt("viaForge$version") != 0) { // Temporary fix for old versions + version = ProtocolVersion.getProtocol(compoundnbt.getInt("viaForge$version")); + } else { + version = ProtocolVersion.getClosest(compoundnbt.getString("viaForge$version")); + } + ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version); } } @@ -58,12 +64,12 @@ public class MixinServerData implements ExtendedServerData { } @Override - public VersionEnum viaForge$getVersion() { + public ProtocolVersion viaForge$getVersion() { return viaForge$version; } @Override - public void viaForge$setVersion(VersionEnum version) { + public void viaForge$setVersion(ProtocolVersion version) { viaForge$version = version; } diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerPinger.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerPinger.java index b28be29..963e1a8 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerPinger.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/MixinServerPinger.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.network.ServerPinger; import net.minecraft.network.NetworkManager; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -51,7 +51,7 @@ public class MixinServerPinger { // We hope that the current server data is not null if (viaForge$serverData instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinClientPlayerEntity.java b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinClientPlayerEntity.java index 65633ea..720c5c4 100644 --- a/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinClientPlayerEntity.java +++ b/viaforge-mc116/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinClientPlayerEntity.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.entity.player.AbstractClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.world.ClientWorld; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +40,7 @@ public class MixinClientPlayerEntity extends AbstractClientPlayerEntity { @Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/entity/player/ClientPlayerEntity;lastOnGround:Z", ordinal = 0)) public boolean emulateIdlePacket(ClientPlayerEntity instance) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes // So we invert the original logic: // if (prevOnGround != onGround) sendPacket diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index a6f9698..60af73c 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -29,7 +29,7 @@ import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.lwjgl.glfw.GLFW; import java.util.UUID; @@ -121,49 +121,49 @@ public class GuiProtocolSelector extends Screen { public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) { super(client, width, height, top, bottom, slotHeight); - for (VersionEnum version : VersionEnum.SORTED_VERSIONS) { + for (ProtocolVersion version : ProtocolVersion.getProtocols()) { addEntry(new SlotEntry(version)); } } public class SlotEntry extends ObjectSelectionList.Entry { - private final VersionEnum versionEnum; + private final ProtocolVersion ProtocolVersion; - public SlotEntry(VersionEnum versionEnum) { - this.versionEnum = versionEnum; + public SlotEntry(ProtocolVersion ProtocolVersion) { + this.ProtocolVersion = ProtocolVersion; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent); + GuiProtocolSelector.this.finishedCallback.finished(ProtocolVersion, GuiProtocolSelector.this.parent); return super.mouseClicked(mouseX, mouseY, button); } @Override public Component getNarration() { - return new TextComponent(versionEnum.getName()); + return new TextComponent(ProtocolVersion.getName()); } @Override public void render(PoseStack matrices, int p_93524_, int y, int p_93526_, int p_93527_, int p_93528_, int p_93529_, int p_93530_, boolean p_93531_, float p_93532_) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); String color; - if (targetVersion == versionEnum) { + if (targetVersion == ProtocolVersion) { color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString(); } else { color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString(); } - drawCenteredString(matrices, Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1); + drawCenteredString(matrices, Minecraft.getInstance().font, color + ProtocolVersion.getName(), width / 2, y, -1); } } } public interface FinishedCallback { - void finished(final VersionEnum version, final Screen parent); + void finished(final ProtocolVersion version, final Screen parent); } diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java index 9027b17..dad35ad 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java @@ -25,8 +25,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; import net.minecraft.network.Connection; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -41,7 +42,7 @@ public class MixinClientHandshakePacketListenerImpl { @Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V")) public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get(); if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) { // We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java index 41994e2..68d4da4 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java @@ -22,7 +22,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.Minecraft; import net.minecraft.network.Connection; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -38,7 +38,7 @@ public class MixinConnectScreen_1 { // use it to determine the protocol version to use. // We hope that the current server data is not null if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java index 0b6d793..2c7c192 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java @@ -25,8 +25,9 @@ import net.minecraft.network.CipherDecoder; import net.minecraft.network.CipherEncoder; import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -48,7 +49,7 @@ public class MixinConnection implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD) private static void trackSelfTarget(InetSocketAddress p_178301_, boolean p_178302_, CallbackInfoReturnable cir, final Connection connection) { @@ -61,7 +62,7 @@ public class MixinConnection implements VFNetworkManager { @Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true) private void storeEncryptionCiphers(Cipher p_244777_1_, Cipher p_244777_2_, CallbackInfo ci) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Minecraft's encryption code is bad for us, we need to reorder the pipeline ci.cancel(); @@ -93,12 +94,12 @@ public class MixinConnection implements VFNetworkManager { } @Override - public VersionEnum viaForge$getTrackedVersion() { + public ProtocolVersion viaForge$getTrackedVersion() { return viaForge$targetVersion; } @Override - public void viaForge$setTrackedVersion(VersionEnum version) { + public void viaForge$setTrackedVersion(ProtocolVersion version) { viaForge$targetVersion = version; } diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java index ea178b1..251ec24 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.gui.components.DebugScreenOverlay; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -35,13 +35,13 @@ public class MixinDebugScreenOverlay { @Inject(method = "getSystemInformation", at = @At(value = "TAIL")) public void addViaForgeVersion(CallbackInfoReturnable> cir) { final ViaForgeCommon common = ViaForgeCommon.getManager(); - final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion(); if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) { cir.getReturnValue().add(""); int protocolVersion = version.getVersion(); - if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches // So we need to unmap the version to get the real protocol version id protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion); diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java index c2d9d69..746b037 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java @@ -29,7 +29,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -55,7 +55,7 @@ public class MixinEditServerScreen extends Screen { if (config.isShowAddServerButton()) { final Pair pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height); - final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion(); + final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion(); addRenderableWidget(new Button(pos.key(), pos.value(), 100, 20, new TextComponent(target != null ? target.getName() : "Set Version"), b -> { minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> { // Set version and go back to the parent screen. diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java index 3248d96..0c0a837 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.nbt.CompoundTag; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,19 +34,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class MixinServerData implements ExtendedServerData { @Unique - private VersionEnum viaForge$version; + private ProtocolVersion viaForge$version; @Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) public void saveVersion(CallbackInfoReturnable cir, CompoundTag compoundtag) { if (viaForge$version != null) { - compoundtag.putInt("viaForge$version", viaForge$version.getVersion()); + compoundtag.putString("viaForge$version", viaForge$version.getName()); } } @Inject(method = "read", at = @At(value = "TAIL")) private static void getVersion(CompoundTag compoundnbt, CallbackInfoReturnable cir) { if (compoundnbt.contains("viaForge$version")) { - ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version"))); + ProtocolVersion version; + if (compoundnbt.getInt("viaForge$version") != 0) { // Temporary fix for old versions + version = ProtocolVersion.getProtocol(compoundnbt.getInt("viaForge$version")); + } else { + version = ProtocolVersion.getClosest(compoundnbt.getString("viaForge$version")); + } + ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version); } } @@ -58,12 +64,12 @@ public class MixinServerData implements ExtendedServerData { } @Override - public VersionEnum viaForge$getVersion() { + public ProtocolVersion viaForge$getVersion() { return viaForge$version; } @Override - public void viaForge$setVersion(VersionEnum version) { + public void viaForge$setVersion(ProtocolVersion version) { viaForge$version = version; } diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java index c78254f..3f175c4 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.ServerStatusPinger; import net.minecraft.network.Connection; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -51,7 +51,7 @@ public class MixinServerStatusPinger { // We hope that the current server data is not null if (viaForge$serverData instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java index e3a5c54..d384631 100644 --- a/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java +++ b/viaforge-mc117/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +40,7 @@ public class MixinLocalPlayer extends AbstractClientPlayer { @Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0)) public boolean emulateIdlePacket(LocalPlayer instance) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes // So we invert the original logic: // if (prevOnGround != onGround) sendPacket diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index 6bded86..1931fe1 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -29,7 +29,7 @@ import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.lwjgl.glfw.GLFW; import java.util.UUID; @@ -121,49 +121,49 @@ public class GuiProtocolSelector extends Screen { public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) { super(client, width, height, top, bottom, slotHeight); - for (VersionEnum version : VersionEnum.SORTED_VERSIONS) { + for (ProtocolVersion version : ProtocolVersion.getProtocols()) { addEntry(new SlotEntry(version)); } } public class SlotEntry extends Entry { - private final VersionEnum versionEnum; + private final ProtocolVersion ProtocolVersion; - public SlotEntry(VersionEnum versionEnum) { - this.versionEnum = versionEnum; + public SlotEntry(ProtocolVersion ProtocolVersion) { + this.ProtocolVersion = ProtocolVersion; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent); + GuiProtocolSelector.this.finishedCallback.finished(ProtocolVersion, GuiProtocolSelector.this.parent); return super.mouseClicked(mouseX, mouseY, button); } @Override public Component getNarration() { - return new TextComponent(versionEnum.getName()); + return new TextComponent(ProtocolVersion.getName()); } @Override public void render(PoseStack matrices, int p_93524_, int y, int p_93526_, int p_93527_, int p_93528_, int p_93529_, int p_93530_, boolean p_93531_, float p_93532_) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); String color; - if (targetVersion == versionEnum) { + if (targetVersion == ProtocolVersion) { color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString(); } else { color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString(); } - drawCenteredString(matrices, Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1); + drawCenteredString(matrices, Minecraft.getInstance().font, color + ProtocolVersion.getName(), width / 2, y, -1); } } } public interface FinishedCallback { - void finished(final VersionEnum version, final Screen parent); + void finished(final ProtocolVersion version, final Screen parent); } diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java index 9027b17..dad35ad 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java @@ -25,8 +25,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; import net.minecraft.network.Connection; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -41,7 +42,7 @@ public class MixinClientHandshakePacketListenerImpl { @Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V")) public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get(); if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) { // We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java index 41994e2..68d4da4 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java @@ -22,7 +22,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.Minecraft; import net.minecraft.network.Connection; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -38,7 +38,7 @@ public class MixinConnectScreen_1 { // use it to determine the protocol version to use. // We hope that the current server data is not null if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java index 0b6d793..2c7c192 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java @@ -25,8 +25,9 @@ import net.minecraft.network.CipherDecoder; import net.minecraft.network.CipherEncoder; import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -48,7 +49,7 @@ public class MixinConnection implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD) private static void trackSelfTarget(InetSocketAddress p_178301_, boolean p_178302_, CallbackInfoReturnable cir, final Connection connection) { @@ -61,7 +62,7 @@ public class MixinConnection implements VFNetworkManager { @Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true) private void storeEncryptionCiphers(Cipher p_244777_1_, Cipher p_244777_2_, CallbackInfo ci) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Minecraft's encryption code is bad for us, we need to reorder the pipeline ci.cancel(); @@ -93,12 +94,12 @@ public class MixinConnection implements VFNetworkManager { } @Override - public VersionEnum viaForge$getTrackedVersion() { + public ProtocolVersion viaForge$getTrackedVersion() { return viaForge$targetVersion; } @Override - public void viaForge$setTrackedVersion(VersionEnum version) { + public void viaForge$setTrackedVersion(ProtocolVersion version) { viaForge$targetVersion = version; } diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java index ea178b1..251ec24 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.gui.components.DebugScreenOverlay; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -35,13 +35,13 @@ public class MixinDebugScreenOverlay { @Inject(method = "getSystemInformation", at = @At(value = "TAIL")) public void addViaForgeVersion(CallbackInfoReturnable> cir) { final ViaForgeCommon common = ViaForgeCommon.getManager(); - final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion(); if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) { cir.getReturnValue().add(""); int protocolVersion = version.getVersion(); - if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches // So we need to unmap the version to get the real protocol version id protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion); diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java index c2d9d69..746b037 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java @@ -29,7 +29,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -55,7 +55,7 @@ public class MixinEditServerScreen extends Screen { if (config.isShowAddServerButton()) { final Pair pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height); - final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion(); + final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion(); addRenderableWidget(new Button(pos.key(), pos.value(), 100, 20, new TextComponent(target != null ? target.getName() : "Set Version"), b -> { minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> { // Set version and go back to the parent screen. diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java index 3248d96..0c0a837 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.nbt.CompoundTag; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,19 +34,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class MixinServerData implements ExtendedServerData { @Unique - private VersionEnum viaForge$version; + private ProtocolVersion viaForge$version; @Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) public void saveVersion(CallbackInfoReturnable cir, CompoundTag compoundtag) { if (viaForge$version != null) { - compoundtag.putInt("viaForge$version", viaForge$version.getVersion()); + compoundtag.putString("viaForge$version", viaForge$version.getName()); } } @Inject(method = "read", at = @At(value = "TAIL")) private static void getVersion(CompoundTag compoundnbt, CallbackInfoReturnable cir) { if (compoundnbt.contains("viaForge$version")) { - ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version"))); + ProtocolVersion version; + if (compoundnbt.getInt("viaForge$version") != 0) { // Temporary fix for old versions + version = ProtocolVersion.getProtocol(compoundnbt.getInt("viaForge$version")); + } else { + version = ProtocolVersion.getClosest(compoundnbt.getString("viaForge$version")); + } + ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version); } } @@ -58,12 +64,12 @@ public class MixinServerData implements ExtendedServerData { } @Override - public VersionEnum viaForge$getVersion() { + public ProtocolVersion viaForge$getVersion() { return viaForge$version; } @Override - public void viaForge$setVersion(VersionEnum version) { + public void viaForge$setVersion(ProtocolVersion version) { viaForge$version = version; } diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java index c78254f..3f175c4 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.ServerStatusPinger; import net.minecraft.network.Connection; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -51,7 +51,7 @@ public class MixinServerStatusPinger { // We hope that the current server data is not null if (viaForge$serverData instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java index e3a5c54..d384631 100644 --- a/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java +++ b/viaforge-mc118/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +40,7 @@ public class MixinLocalPlayer extends AbstractClientPlayer { @Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0)) public boolean emulateIdlePacket(LocalPlayer instance) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes // So we invert the original logic: // if (prevOnGround != onGround) sendPacket diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index 3ca5f8f..e1c9688 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -28,7 +28,7 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.lwjgl.glfw.GLFW; import java.util.UUID; @@ -120,49 +120,49 @@ public class GuiProtocolSelector extends Screen { public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) { super(client, width, height, top, bottom, slotHeight); - for (VersionEnum version : VersionEnum.SORTED_VERSIONS) { + for (ProtocolVersion version : ProtocolVersion.getProtocols()) { addEntry(new SlotEntry(version)); } } public class SlotEntry extends Entry { - private final VersionEnum versionEnum; + private final ProtocolVersion ProtocolVersion; - public SlotEntry(VersionEnum versionEnum) { - this.versionEnum = versionEnum; + public SlotEntry(ProtocolVersion ProtocolVersion) { + this.ProtocolVersion = ProtocolVersion; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent); + GuiProtocolSelector.this.finishedCallback.finished(ProtocolVersion, GuiProtocolSelector.this.parent); return super.mouseClicked(mouseX, mouseY, button); } @Override public Component getNarration() { - return Component.literal(versionEnum.getName()); + return Component.literal(ProtocolVersion.getName()); } @Override public void render(PoseStack matrices, int p_93524_, int y, int p_93526_, int p_93527_, int p_93528_, int p_93529_, int p_93530_, boolean p_93531_, float p_93532_) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); String color; - if (targetVersion == versionEnum) { + if (targetVersion == ProtocolVersion) { color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString(); } else { color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString(); } - drawCenteredString(matrices, Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1); + drawCenteredString(matrices, Minecraft.getInstance().font, color + ProtocolVersion.getName(), width / 2, y, -1); } } } public interface FinishedCallback { - void finished(final VersionEnum version, final Screen parent); + void finished(final ProtocolVersion version, final Screen parent); } diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java index 9027b17..dad35ad 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java @@ -25,8 +25,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; import net.minecraft.network.Connection; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -41,7 +42,7 @@ public class MixinClientHandshakePacketListenerImpl { @Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Lcom/mojang/authlib/GameProfile;Ljava/lang/String;Ljava/lang/String;)V")) public void onlyJoinServerIfPremium(MinecraftSessionService instance, GameProfile profile, String authenticationToken, String serverId) throws AuthenticationException { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get(); if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) { // We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java index 41994e2..68d4da4 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnectScreen_1.java @@ -22,7 +22,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.Minecraft; import net.minecraft.network.Connection; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -38,7 +38,7 @@ public class MixinConnectScreen_1 { // use it to determine the protocol version to use. // We hope that the current server data is not null if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java index 0b6d793..2c7c192 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java @@ -25,8 +25,9 @@ import net.minecraft.network.CipherDecoder; import net.minecraft.network.CipherEncoder; import net.minecraft.network.Connection; import net.minecraft.network.chat.Component; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -48,7 +49,7 @@ public class MixinConnection implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lio/netty/bootstrap/Bootstrap;group(Lio/netty/channel/EventLoopGroup;)Lio/netty/bootstrap/AbstractBootstrap;"), locals = LocalCapture.CAPTURE_FAILHARD) private static void trackSelfTarget(InetSocketAddress p_178301_, boolean p_178302_, CallbackInfoReturnable cir, final Connection connection) { @@ -61,7 +62,7 @@ public class MixinConnection implements VFNetworkManager { @Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true) private void storeEncryptionCiphers(Cipher p_244777_1_, Cipher p_244777_2_, CallbackInfo ci) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Minecraft's encryption code is bad for us, we need to reorder the pipeline ci.cancel(); @@ -93,12 +94,12 @@ public class MixinConnection implements VFNetworkManager { } @Override - public VersionEnum viaForge$getTrackedVersion() { + public ProtocolVersion viaForge$getTrackedVersion() { return viaForge$targetVersion; } @Override - public void viaForge$setTrackedVersion(VersionEnum version) { + public void viaForge$setTrackedVersion(ProtocolVersion version) { viaForge$targetVersion = version; } diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java index ea178b1..251ec24 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.gui.components.DebugScreenOverlay; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -35,13 +35,13 @@ public class MixinDebugScreenOverlay { @Inject(method = "getSystemInformation", at = @At(value = "TAIL")) public void addViaForgeVersion(CallbackInfoReturnable> cir) { final ViaForgeCommon common = ViaForgeCommon.getManager(); - final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion(); if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) { cir.getReturnValue().add(""); int protocolVersion = version.getVersion(); - if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches // So we need to unmap the version to get the real protocol version id protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion); diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java index d3e9035..aad945e 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java @@ -28,7 +28,7 @@ import net.minecraft.client.gui.screens.EditServerScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.network.chat.Component; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -54,7 +54,7 @@ public class MixinEditServerScreen extends Screen { if (config.isShowAddServerButton()) { final Pair pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height); - final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion(); + final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion(); addRenderableWidget(Button.builder(Component.literal(target != null ? target.getName() : "Set Version"), b -> { minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> { // Set version and go back to the parent screen. diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java index 3248d96..0c0a837 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.nbt.CompoundTag; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,19 +34,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class MixinServerData implements ExtendedServerData { @Unique - private VersionEnum viaForge$version; + private ProtocolVersion viaForge$version; @Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) public void saveVersion(CallbackInfoReturnable cir, CompoundTag compoundtag) { if (viaForge$version != null) { - compoundtag.putInt("viaForge$version", viaForge$version.getVersion()); + compoundtag.putString("viaForge$version", viaForge$version.getName()); } } @Inject(method = "read", at = @At(value = "TAIL")) private static void getVersion(CompoundTag compoundnbt, CallbackInfoReturnable cir) { if (compoundnbt.contains("viaForge$version")) { - ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version"))); + ProtocolVersion version; + if (compoundnbt.getInt("viaForge$version") != 0) { // Temporary fix for old versions + version = ProtocolVersion.getProtocol(compoundnbt.getInt("viaForge$version")); + } else { + version = ProtocolVersion.getClosest(compoundnbt.getString("viaForge$version")); + } + ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version); } } @@ -58,12 +64,12 @@ public class MixinServerData implements ExtendedServerData { } @Override - public VersionEnum viaForge$getVersion() { + public ProtocolVersion viaForge$getVersion() { return viaForge$version; } @Override - public void viaForge$setVersion(VersionEnum version) { + public void viaForge$setVersion(ProtocolVersion version) { viaForge$version = version; } diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java index c78254f..3f175c4 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.ServerStatusPinger; import net.minecraft.network.Connection; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -51,7 +51,7 @@ public class MixinServerStatusPinger { // We hope that the current server data is not null if (viaForge$serverData instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java index e3a5c54..d384631 100644 --- a/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java +++ b/viaforge-mc119/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +40,7 @@ public class MixinLocalPlayer extends AbstractClientPlayer { @Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0)) public boolean emulateIdlePacket(LocalPlayer instance) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes // So we invert the original logic: // if (prevOnGround != onGround) sendPacket diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index fa78d41..989700b 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -28,7 +28,7 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ObjectSelectionList; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.lwjgl.glfw.GLFW; import java.util.UUID; @@ -120,49 +120,49 @@ public class GuiProtocolSelector extends Screen { public SlotList(Minecraft client, int width, int height, int top, int bottom, int slotHeight) { super(client, width, height - top - bottom, top, slotHeight); - for (VersionEnum version : VersionEnum.SORTED_VERSIONS) { + for (ProtocolVersion version : ProtocolVersion.getProtocols()) { addEntry(new SlotEntry(version)); } } public class SlotEntry extends Entry { - private final VersionEnum versionEnum; + private final ProtocolVersion ProtocolVersion; - public SlotEntry(VersionEnum versionEnum) { - this.versionEnum = versionEnum; + public SlotEntry(ProtocolVersion ProtocolVersion) { + this.ProtocolVersion = ProtocolVersion; } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - GuiProtocolSelector.this.finishedCallback.finished(versionEnum, GuiProtocolSelector.this.parent); + GuiProtocolSelector.this.finishedCallback.finished(ProtocolVersion, GuiProtocolSelector.this.parent); return super.mouseClicked(mouseX, mouseY, button); } @Override public Component getNarration() { - return Component.literal(versionEnum.getName()); + return Component.literal(ProtocolVersion.getName()); } @Override public void render(GuiGraphics graphics, int p_93524_, int y, int p_93526_, int p_93527_, int p_93528_, int p_93529_, int p_93530_, boolean p_93531_, float p_93532_) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); String color; - if (targetVersion == versionEnum) { + if (targetVersion == ProtocolVersion) { color = GuiProtocolSelector.this.simple ? ChatFormatting.GOLD.toString() : ChatFormatting.GREEN.toString(); } else { color = GuiProtocolSelector.this.simple ? ChatFormatting.WHITE.toString() : ChatFormatting.DARK_RED.toString(); } - graphics.drawCenteredString(Minecraft.getInstance().font, color + versionEnum.getName(), width / 2, y, -1); + graphics.drawCenteredString(Minecraft.getInstance().font, color + ProtocolVersion.getName(), width / 2, y, -1); } } } public interface FinishedCallback { - void finished(final VersionEnum version, final Screen parent); + void finished(final ProtocolVersion version, final Screen parent); } diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java index 3194b6d..c426d4e 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinClientHandshakePacketListenerImpl.java @@ -24,8 +24,9 @@ import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl; import net.minecraft.network.Connection; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -42,7 +43,7 @@ public class MixinClientHandshakePacketListenerImpl { @Redirect(method = "authenticateServer", at = @At(value = "INVOKE", target = "Lcom/mojang/authlib/minecraft/MinecraftSessionService;joinServer(Ljava/util/UUID;Ljava/lang/String;Ljava/lang/String;)V")) public void onlyJoinServerIfPremium(MinecraftSessionService instance, UUID uuid, String authenticationToken, String serverId) throws AuthenticationException { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { final UserConnection user = connection.channel().attr(ViaForgeCommon.LOCAL_VIA_USER).get(); if (user != null && user.has(ProtocolMetadataStorage.class) && !user.get(ProtocolMetadataStorage.class).authenticate) { // We are in the 1.7 -> 1.6 protocol, so we need to skip the joinServer call diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java index d1e01ab..da6349a 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinConnection.java @@ -30,8 +30,9 @@ import net.minecraft.network.PacketListener; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.handshake.ClientIntent; import net.minecraft.util.SampleLogger; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -53,7 +54,7 @@ public class MixinConnection implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "connectToServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/network/Connection;)Lio/netty/channel/ChannelFuture;"), locals = LocalCapture.CAPTURE_FAILHARD) private static void trackSelfTarget(InetSocketAddress p_178301_, boolean p_178302_, SampleLogger p_300093_, CallbackInfoReturnable cir, Connection connection) { @@ -67,7 +68,7 @@ public class MixinConnection implements VFNetworkManager { @Inject(method = "initiateServerboundConnection", at = @At("HEAD")) public void test(String p_300730_, int p_300598_, PacketListener p_298739_, ClientIntent p_297789_, CallbackInfo ci) { if (Minecraft.getInstance().getCurrentServer() instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) Minecraft.getInstance().getCurrentServer()).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { @@ -80,7 +81,7 @@ public class MixinConnection implements VFNetworkManager { @Inject(method = "setEncryptionKey", at = @At("HEAD"), cancellable = true) private void storeEncryptionCiphers(Cipher p_244777_1_, Cipher p_244777_2_, CallbackInfo ci) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Minecraft's encryption code is bad for us, we need to reorder the pipeline ci.cancel(); @@ -112,12 +113,12 @@ public class MixinConnection implements VFNetworkManager { } @Override - public VersionEnum viaForge$getTrackedVersion() { + public ProtocolVersion viaForge$getTrackedVersion() { return viaForge$targetVersion; } @Override - public void viaForge$setTrackedVersion(VersionEnum version) { + public void viaForge$setTrackedVersion(ProtocolVersion version) { viaForge$targetVersion = version; } diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java index ea178b1..251ec24 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinDebugScreenOverlay.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.gui.components.DebugScreenOverlay; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -35,13 +35,13 @@ public class MixinDebugScreenOverlay { @Inject(method = "getSystemInformation", at = @At(value = "TAIL")) public void addViaForgeVersion(CallbackInfoReturnable> cir) { final ViaForgeCommon common = ViaForgeCommon.getManager(); - final VersionEnum version = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ViaForgeCommon.getManager().getTargetVersion(); if (common.getConfig().isShowProtocolVersionInF3() && version != common.getNativeVersion() && !common.getPlatform().isSingleplayer().get()) { cir.getReturnValue().add(""); int protocolVersion = version.getVersion(); - if (version.isOlderThanOrEqualTo(VersionEnum.r1_6_4)) { + if (version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { // Older versions (<= 1.6.4) are using fake ids in ViaLegacy to prevent version duplications / mismatches // So we need to unmap the version to get the real protocol version id protocolVersion = LegacyProtocolVersion.getRealProtocolVersion(protocolVersion); diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java index d3e9035..aad945e 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinEditServerScreen.java @@ -28,7 +28,7 @@ import net.minecraft.client.gui.screens.EditServerScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.network.chat.Component; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -54,7 +54,7 @@ public class MixinEditServerScreen extends Screen { if (config.isShowAddServerButton()) { final Pair pos = config.getAddServerScreenButtonPosition().getPosition(this.width, this.height); - final VersionEnum target = ((ExtendedServerData) serverData).viaForge$getVersion(); + final ProtocolVersion target = ((ExtendedServerData) serverData).viaForge$getVersion(); addRenderableWidget(Button.builder(Component.literal(target != null ? target.getName() : "Set Version"), b -> { minecraft.setScreen(new GuiProtocolSelector(this, true, (version, parent) -> { // Set version and go back to the parent screen. diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java index 3248d96..0c0a837 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerData.java @@ -21,7 +21,7 @@ package de.florianmichael.viaforge.mixin; import de.florianmichael.viaforge.common.gui.ExtendedServerData; import net.minecraft.client.multiplayer.ServerData; import net.minecraft.nbt.CompoundTag; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -34,19 +34,25 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture; public class MixinServerData implements ExtendedServerData { @Unique - private VersionEnum viaForge$version; + private ProtocolVersion viaForge$version; @Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/CompoundTag;putString(Ljava/lang/String;Ljava/lang/String;)V", ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD) public void saveVersion(CallbackInfoReturnable cir, CompoundTag compoundtag) { if (viaForge$version != null) { - compoundtag.putInt("viaForge$version", viaForge$version.getVersion()); + compoundtag.putString("viaForge$version", viaForge$version.getName()); } } @Inject(method = "read", at = @At(value = "TAIL")) private static void getVersion(CompoundTag compoundnbt, CallbackInfoReturnable cir) { if (compoundnbt.contains("viaForge$version")) { - ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(VersionEnum.fromProtocolId(compoundnbt.getInt("viaForge$version"))); + ProtocolVersion version; + if (compoundnbt.getInt("viaForge$version") != 0) { // Temporary fix for old versions + version = ProtocolVersion.getProtocol(compoundnbt.getInt("viaForge$version")); + } else { + version = ProtocolVersion.getClosest(compoundnbt.getString("viaForge$version")); + } + ((ExtendedServerData) cir.getReturnValue()).viaForge$setVersion(version); } } @@ -58,12 +64,12 @@ public class MixinServerData implements ExtendedServerData { } @Override - public VersionEnum viaForge$getVersion() { + public ProtocolVersion viaForge$getVersion() { return viaForge$version; } @Override - public void viaForge$setVersion(VersionEnum version) { + public void viaForge$setVersion(ProtocolVersion version) { viaForge$version = version; } diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java index 63e8f64..d262d5d 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/MixinServerStatusPinger.java @@ -24,7 +24,7 @@ import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.multiplayer.ServerStatusPinger; import net.minecraft.network.Connection; import net.minecraft.util.SampleLogger; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -52,7 +52,7 @@ public class MixinServerStatusPinger { // We hope that the current server data is not null if (viaForge$serverData instanceof ExtendedServerData) { - final VersionEnum version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); + final ProtocolVersion version = ((ExtendedServerData) viaForge$serverData).viaForge$getVersion(); if (version != null) { ViaForgeCommon.getManager().setTargetVersionSilent(version); } else { diff --git a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java index 55fa9f6..a2ec4b3 100644 --- a/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java +++ b/viaforge-mc120/src/main/java/de/florianmichael/viaforge/mixin/fixes/MixinLocalPlayer.java @@ -23,7 +23,7 @@ import de.florianmichael.viaforge.common.ViaForgeCommon; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; -import net.raphimc.vialoader.util.VersionEnum; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -40,7 +40,7 @@ public class MixinLocalPlayer extends AbstractClientPlayer { @Redirect(method = "sendPosition", at = @At(value = "FIELD", target = "Lnet/minecraft/client/player/LocalPlayer;lastOnGround:Z", ordinal = 0)) public boolean emulateIdlePacket(LocalPlayer instance) { - if (ViaForgeCommon.getManager().getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes // So we invert the original logic: // if (prevOnGround != onGround) sendPacket