Skip to content

Commit

Permalink
Don't reset selected version when playing singleplayer
Browse files Browse the repository at this point in the history
Closes #337
  • Loading branch information
FlorianMichael committed Jan 29, 2024
1 parent a4f837f commit b5b677d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ public static void checkOutdated() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,11 +41,10 @@ private void callPostGameLoadEvent(RunArgs args, CallbackInfo ci) {
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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ private void removeHeaders(CallbackInfoReturnable<Map<String, String>> cir) {
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);
}

Expand Down

0 comments on commit b5b677d

Please sign in to comment.