Don't reset selected version when playing singleplayer

Closes https://github.com/ViaVersion/ViaFabricPlus/issues/337
This commit is contained in:
FlorianMichael 2024-01-29 13:57:34 +01:00
parent a4f837fb9d
commit b5b677da71
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 15 additions and 11 deletions

View File

@ -98,8 +98,9 @@ public class ResourcePackHeaderDiff {
public static GameVersion get(final VersionEnum version) {
if (!GAME_VERSION_DIFF.containsKey(version)) {
return SharedConstants.getGameVersion();
} else {
return GAME_VERSION_DIFF.get(version);
}
return GAME_VERSION_DIFF.get(version);
}
private static void registerVersion(final VersionEnum version, final int packFormat, final String name) {

View File

@ -19,10 +19,15 @@
package de.florianmichael.viafabricplus.injection.mixin.base.integration;
import com.llamalad7.mixinextras.sugar.Local;
import de.florianmichael.viafabricplus.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.network.ClientConnection;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.server.SaveLoader;
import net.minecraft.world.level.storage.LevelStorage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
@ -36,11 +41,10 @@ public abstract class MixinMinecraftClient {
PostGameLoadCallback.EVENT.invoker().postGameLoad();
}
@Inject(method = "startIntegratedServer", at = @At("HEAD"))
private void disableProtocolHack(CallbackInfo ci) {
// Set the target version to the native version when starting a singleplayer world
// This will automatically reload all the mappings and reset the target version to the forced version
ProtocolHack.setTargetVersion(ProtocolHack.NATIVE_VERSION);
@Inject(method = "startIntegratedServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;connect(Ljava/lang/String;ILnet/minecraft/network/listener/ClientLoginPacketListener;)V", shift = At.Shift.BEFORE))
private void disableProtocolHack(LevelStorage.Session session, ResourcePackManager dataPackManager, SaveLoader saveLoader, boolean newWorld, CallbackInfo ci, @Local ClientConnection clientConnection) {
ProtocolHack.setTargetVersion(ProtocolHack.NATIVE_VERSION, true);
clientConnection.channel.closeFuture().addListener(channel -> ProtocolHack.resetPreviousVersion());
}
}

View File

@ -45,12 +45,11 @@ public abstract class MixinServerResourcePackLoader_4 {
final LinkedHashMap<String, String> modifiableMap = new LinkedHashMap<>(cir.getReturnValue());
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_14_3)) {
modifiableMap.remove("X-Minecraft-Version-ID");
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
modifiableMap.remove("X-Minecraft-Pack-Format");
modifiableMap.remove("User-Agent");
}
}
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
modifiableMap.remove("X-Minecraft-Pack-Format");
modifiableMap.remove("User-Agent");
}
cir.setReturnValue(modifiableMap);
}