Skip to content

Commit

Permalink
Rework sodium download link constants
Browse files Browse the repository at this point in the history
This change was made to avoid cases where people editing the sodium version checker forget to edit the download link.
  • Loading branch information
coderbot16 committed Jan 17, 2022
1 parent 5565144 commit d020b33
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
public class Iris implements ClientModInitializer {
public static final String MODID = "iris";
public static final Logger logger = LogManager.getLogger(MODID);
public static final String SODIUM_DOWNLOAD_LINK = "https://www.curseforge.com/minecraft/mc-mods/sodium/files/3488820";

private static Path shaderpacksDirectory;
private static ShaderpackDirectoryManager shaderpacksDirectoryManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package net.coderbot.iris.compat.sodium;

import java.util.Optional;

public class AllowedSodiumVersion {
private final String version;
private final String downloadLink;
private final boolean prefixMatch;

public AllowedSodiumVersion(String version, boolean prefixMatch) {
public AllowedSodiumVersion(String version, String downloadLink, boolean prefixMatch) {
this.version = version;
this.downloadLink = downloadLink;
this.prefixMatch = prefixMatch;
}

public static AllowedSodiumVersion prefix(String prefix) {
return new AllowedSodiumVersion(prefix, true);
return new AllowedSodiumVersion(prefix, null, true);
}

public static AllowedSodiumVersion exact(String version) {
return new AllowedSodiumVersion(version, false);
public static AllowedSodiumVersion exact(String version, String downloadLink) {
return new AllowedSodiumVersion(version, downloadLink, false);
}

public boolean matches(String candidate) {
Expand All @@ -32,4 +36,8 @@ public String getVersion() {
public boolean isPrefixMatch() {
return prefixMatch;
}

public Optional<String> getDownloadLink() {
return Optional.ofNullable(downloadLink);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

import com.google.common.collect.ImmutableList;

import java.util.Optional;

public class SodiumVersionCheck {
// The allowed versions of Sodium for use with Iris
//
// Make sure to update the comments / download links when editing this!!!
// If you forget to edit the download links you'll cause the support team a bunch
// of pain. So don't forget!
private static final ImmutableList<AllowedSodiumVersion> ALLOWED_SODIUM_VERSIONS = ImmutableList.of(
// Official 0.2.0
AllowedSodiumVersion.exact("0.2.0+build.4"),
AllowedSodiumVersion.exact("0.2.0+build.4",
"https://www.curseforge.com/minecraft/mc-mods/sodium/files/3488820"),

// ReplayMod's existing compatible forked 0.2.0 version
AllowedSodiumVersion.prefix("0.2.0+rev.f42b4ca"),
Expand All @@ -15,6 +22,11 @@ public class SodiumVersionCheck {
AllowedSodiumVersion.prefix("0.2.0+replaymod")
);

public static String getDownloadLink() {
return ALLOWED_SODIUM_VERSIONS.stream().map(AllowedSodiumVersion::getDownloadLink)
.filter(Optional::isPresent).findFirst().get().get();
}

public static boolean isAllowedVersion(String sodiumVersion) {
for (AllowedSodiumVersion allowed : ALLOWED_SODIUM_VERSIONS) {
if (allowed.matches(sodiumVersion)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/coderbot/iris/mixin/MixinTitleScreen.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.coderbot.iris.mixin;

import net.coderbot.iris.Iris;
import net.coderbot.iris.compat.sodium.SodiumVersionCheck;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.AlertScreen;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.network.chat.TranslatableComponent;
Expand Down Expand Up @@ -35,7 +35,7 @@ public class MixinTitleScreen {
(boolean accepted) -> {
if (accepted) {
try {
Util.getPlatform().openUri(new URI(Iris.SODIUM_DOWNLOAD_LINK));
Util.getPlatform().openUri(new URI(SodiumVersionCheck.getDownloadLink()));
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
Expand Down

0 comments on commit d020b33

Please sign in to comment.