From 1e1536120e62b4b7b55f5c20ac055af0ffcc6d8f Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 14 Feb 2024 23:04:43 +0100 Subject: [PATCH] 24w07a, port to upstream changes (maybe) --- gradle.properties | 4 +-- .../viaforge/common/ViaForgeCommon.java | 32 +++++++++---------- .../common/gui/ExtendedServerData.java | 6 ++-- .../common/platform/ViaForgeConfig.java | 10 ++++-- .../protocolhack/netty/VFNetworkManager.java | 6 ++-- .../netty/ViaForgeVLLegacyPipeline.java | 4 +-- .../provider/ViaForgeVersionProvider.java | 6 ++-- .../viaforge/gui/GuiProtocolSelector.java | 12 ++++--- .../mixin/impl/MixinGuiConnecting_1.java | 3 +- .../mixin/impl/MixinGuiOverlayDebug.java | 5 +-- .../mixin/impl/MixinGuiScreenAddServer.java | 3 +- .../impl/MixinNetHandlerLoginClient.java | 3 +- .../mixin/impl/MixinNetworkManager.java | 10 +++--- .../viaforge/mixin/impl/MixinServerData.java | 11 +++++-- .../mixin/impl/MixinServerPinger.java | 3 +- .../mixin/impl/fixes/MixinEntityPlayerSP.java | 3 +- 16 files changed, 71 insertions(+), 50 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6e4ee20..ad3ce7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,8 +8,8 @@ maven_version=3.5.0 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 05ef494..834f9bb 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; @@ -42,14 +42,14 @@ import java.io.File; * It is used to inject the ViaVersion pipeline into the netty pipeline. It also manages the target version. */ public class ViaForgeCommon { - + public static final AttributeKey LOCAL_VIA_USER = AttributeKey.valueOf("local_via_user"); public static final AttributeKey VF_NETWORK_MANAGER = AttributeKey.valueOf("encryption_setup"); 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() { @@ -146,5 +146,5 @@ public class ViaForgeCommon { public static ViaForgeCommon getManager() { return manager; } - -} + +} \ No newline at end of file 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/ViaForgeConfig.java b/src/main/java/de/florianmichael/viaforge/common/platform/ViaForgeConfig.java index 7d4fcb3..68dfc2e 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 60890eb..05a6cd9 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 3a7c16b..a22c497 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/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java b/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java index 58a426c..f377d17 100644 --- a/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java +++ b/src/main/java/de/florianmichael/viaforge/gui/GuiProtocolSelector.java @@ -20,12 +20,14 @@ 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.ProtocolVersionList; import net.raphimc.vialoader.util.VersionEnum; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -133,12 +135,12 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected int getSize() { - return VersionEnum.SORTED_VERSIONS.size(); + return ProtocolVersionList.getProtocolsNewToOld().size(); } @Override protected void elementClicked(int index, boolean b, int i1, int i2) { - finishedCallback.finished(VersionEnum.SORTED_VERSIONS.get(index), parent); + finishedCallback.finished(ProtocolVersionList.getProtocolsNewToOld().get(index), parent); } @Override @@ -153,8 +155,8 @@ public class GuiProtocolSelector extends GuiScreen { @Override protected void drawSlot(int index, int x, int y, int slotHeight, int mouseX, int mouseY) { - final VersionEnum targetVersion = ViaForgeCommon.getManager().getTargetVersion(); - final VersionEnum version = VersionEnum.SORTED_VERSIONS.get(index); + final ProtocolVersion targetVersion = ViaForgeCommon.getManager().getTargetVersion(); + final ProtocolVersion version = ProtocolVersionList.getProtocolsNewToOld().get(index); String color; if (targetVersion == version) { @@ -169,7 +171,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/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java index ebf5346..729805e 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiConnecting_1.java @@ -18,6 +18,7 @@ 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.Minecraft; @@ -38,7 +39,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/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java index a4c4bb2..f941499 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiOverlayDebug.java @@ -18,6 +18,7 @@ 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; @@ -35,13 +36,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/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java index a5ee481..bc6a256 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinGuiScreenAddServer.java +++ b/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; @@ -47,7 +48,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/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java index 2078200..19eb82d 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetHandlerLoginClient.java @@ -25,6 +25,7 @@ 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 org.spongepowered.asm.mixin.Final; @@ -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/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java index 57a4752..9937658 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinNetworkManager.java @@ -18,6 +18,7 @@ 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.protocolhack.netty.VFNetworkManager; import io.netty.channel.Channel; @@ -27,6 +28,7 @@ import net.minecraft.network.NetworkManager; import net.minecraft.util.CryptManager; import net.minecraft.util.IChatComponent; import net.minecraft.util.LazyLoadBase; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; import net.raphimc.vialoader.netty.VLLegacyPipeline; import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Mixin; @@ -51,7 +53,7 @@ public class MixinNetworkManager implements VFNetworkManager { private Cipher viaForge$decryptionCipher; @Unique - private VersionEnum viaForge$targetVersion; + private ProtocolVersion viaForge$targetVersion; @Inject(method = "func_181124_a", 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 +66,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 +98,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/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java index 120d646..fd76140 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerData.java @@ -18,6 +18,7 @@ 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; @@ -39,14 +40,20 @@ public class MixinServerData implements ExtendedServerData { @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); } } diff --git a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java index da7fa07..1aa0c2d 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/MixinServerPinger.java @@ -18,6 +18,7 @@ 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; @@ -51,7 +52,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/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java b/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java index 33e39a7..a76082d 100644 --- a/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java +++ b/src/main/java/de/florianmichael/viaforge/mixin/impl/fixes/MixinEntityPlayerSP.java @@ -19,6 +19,7 @@ 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; @@ -46,7 +47,7 @@ public class MixinEntityPlayerSP extends AbstractClientPlayer { @Redirect(method = "onUpdateWalkingPlayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/NetHandlerPlayClient;addToSendQueue(Lnet/minecraft/network/Packet;)V", ordinal = 7)) public void emulateIdlePacket(NetHandlerPlayClient instance, Packet p_addToSendQueue_1_) { - if (ViaForgeCommon.getManager().getTargetVersion().isNewerThan(VersionEnum.r1_8)) { + if (ViaForgeCommon.getManager().getTargetVersion().newerThan(ProtocolVersion.v1_8)) { // <= 1.8 spams the idle packet instead of only sending it when the ground state changes if (this.viaForge$prevOnGround == this.onGround) { return;