Simplify and improve version sanity checks

Adds a check for the ProtocolTranslator#NATIVE_VERSION field
This commit is contained in:
FlorianMichael 2024-07-01 22:15:16 +02:00
parent a0baba5661
commit 330412618a
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 7 additions and 10 deletions

View File

@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.data;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.GameVersion;
import net.minecraft.SaveVersion;
import net.minecraft.SharedConstants;
@ -83,17 +83,10 @@ public class ResourcePackHeaderDiff {
registerVersion(ProtocolVersion.v1_7_2, 1, "1.7.5");
}
/**
* Checks if the registry is outdated.
*/
@ApiStatus.Internal
public static void checkOutdated() {
for (ProtocolVersion version : ProtocolVersion.getProtocols()) {
if (version.isSnapshot()) continue;
if (version.getVersionType() != VersionType.RELEASE) continue;
if (!GAME_VERSION_DIFF.containsKey(version)) {
throw new RuntimeException("The version " + version + " has no pack format registered");
}
if (!GAME_VERSION_DIFF.containsKey(ProtocolTranslator.NATIVE_VERSION)) {
throw new RuntimeException("The native client version is not registered in the resource pack header diff!");
}
}

View File

@ -48,6 +48,7 @@ import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
@ -315,6 +316,9 @@ public class ProtocolTranslator {
*/
@ApiStatus.Internal
public static CompletableFuture<Void> init(final File directory) {
if (SharedConstants.getProtocolVersion() != NATIVE_VERSION.getOriginalVersion()) {
throw new IllegalStateException("Native version is not the same as the current version");
}
patchConfigs(new File(directory, "ViaLoader"));
// Register command callback for /viafabricplus