Skip to content

Commit

Permalink
Merge pull request #2421 from ArkoSammy12/1.20.3
Browse files Browse the repository at this point in the history
Implement new IRIS_VERSION gl define
  • Loading branch information
IMS212 authored Jul 21, 2024
2 parents 1300e9d + 8d709db commit 4c67e75
Showing 1 changed file with 64 additions and 19 deletions.
83 changes: 64 additions & 19 deletions src/main/java/net/irisshaders/iris/gl/shader/StandardMacros.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.irisshaders.iris.texture.format.TextureFormat;
import net.irisshaders.iris.texture.format.TextureFormatLoader;
import net.minecraft.Util;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20C;
import org.lwjgl.opengl.GL30C;
Expand Down Expand Up @@ -43,6 +44,7 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
ArrayList<StringPair> standardDefines = new ArrayList<>();

define(standardDefines, "MC_VERSION", getMcVersion());
define(standardDefines, "IRIS_VERSION", getFormattedIrisVersion());
define(standardDefines, "MC_GL_VERSION", getGlVersion(GL20C.GL_VERSION));
define(standardDefines, "MC_GLSL_VERSION", getGlVersion(GL20C.GL_SHADING_LANGUAGE_VERSION));
define(standardDefines, getOsString());
Expand Down Expand Up @@ -103,6 +105,7 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
return ImmutableList.copyOf(standardDefines);
}


/**
* Gets the current mc version String in a 5 digit format
*
Expand All @@ -111,36 +114,78 @@ public static ImmutableList<StringPair> createStandardEnvironmentDefines() {
*/
public static String getMcVersion() {
String version = Iris.getReleaseTarget();

if (version == null) {
throw new IllegalStateException("Could not get the current minecraft version!");
throw new IllegalStateException("Could not get the current Minecraft version!");
}

String[] splitVersion = version.split("\\.");

if (splitVersion.length < 2) {
String formattedVersion = formatVersionString(version);
if (formattedVersion == null) {
Iris.logger.error("Could not parse game version \"" + version + "\"");
splitVersion = Iris.getBackupVersionNumber().split("\\.");
} else {
return formattedVersion;
}
String backupVersion = Iris.getBackupVersionNumber();
String formattedBackupVersion = formatVersionString(backupVersion);
if (formattedBackupVersion == null) {
throw new IllegalArgumentException("Could not parse backup game version \"" + version + "\"");
} else {
return formattedBackupVersion;
}
}

String major = splitVersion[0];
String minor = splitVersion[1];
String bugfix;

if (splitVersion.length < 3) {
bugfix = "00";
/**
* Gets the current Iris version String in a 5 digit format
*
* @return The Iris version string
*
*/
public static String getFormattedIrisVersion() {
String rawVersion = Iris.getVersion();
if (rawVersion == null) {
throw new IllegalArgumentException("Could not get current Iris version!");
}
Matcher matcher = SEMVER_PATTERN.matcher(rawVersion);
if (!matcher.matches()) {
throw new IllegalArgumentException("Could not parse semantic Iris version from \"" + rawVersion + "\"");
}
String major = matcher.group("major");
String minor = matcher.group("minor");
String bugFix = matcher.group("bugfix");
if (bugFix == null) {
bugFix = "0";
}
if (major == null || minor == null) {
throw new IllegalArgumentException("Could not parse semantic Iris version from \"" + rawVersion + "\"");
}
String irisSemver = "%s.%s.%s".formatted(major, minor, bugFix);
String formattedSemver = formatVersionString(irisSemver);
if (formattedSemver == null) {
throw new IllegalArgumentException("Could not get a valid semantic version string for Iris version \"" + irisSemver + "\"");
} else {
bugfix = splitVersion[2];
return formattedSemver;
}
}

if (minor.length() == 1) {
minor = 0 + minor;
/**
*
* Formats a semver string into a 122 format
*
* @param version The string version to format
* @return the formatted version in a 122 format, or <b>null</b> if the string is not a valid semver string.
*/
@Nullable
public static String formatVersionString(String version) {
String[] splitVersion = version.split("\\.");
if (splitVersion.length < 2) {
return null;
}
if (bugfix.length() == 1) {
bugfix = 0 + bugfix;
String major = splitVersion[0];
String minor = splitVersion[1].length() == 1 ? 0 + splitVersion[1] : splitVersion[1];
String bugFix = splitVersion.length < 3 ? "00" : splitVersion[2];
if (bugFix.length() == 1) {
bugFix = 0 + bugFix;
}

return major + minor + bugfix;
return major + minor + bugFix;
}

/**
Expand Down

0 comments on commit 4c67e75

Please sign in to comment.