Skip to content

Commit

Permalink
Multiple changes for beta info
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Mar 10, 2024
1 parent 7fcec4d commit 29d4177
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 6 deletions.
29 changes: 29 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ object Constants {
const val CUSTOM_SODIUM: Boolean = false
const val CUSTOM_SODIUM_NAME: String = ""

const val IS_SHARED_BETA: Boolean = true
const val BETA_TAG: String = "DH Support"
const val BETA_VERSION = 1

const val SODIUM_VERSION: String = "mc1.20.4-0.5.8"
}

Expand All @@ -36,6 +40,7 @@ plugins {
// really helps to improve startup times on slow connections.
id("fabric-loom") version "1.5.7"
id("org.ajoberstar.grgit") version "5.2.2"
id("com.github.gmazzo.buildconfig") version "5.3.5"
}

base {
Expand All @@ -62,6 +67,7 @@ sourceSets {
val main = getByName("main")
val test = getByName("test")
val headers = create("headers")
val desktop = create("desktop")
val vendored = create("vendored")
val sodiumCompatibility = create("sodiumCompatibility")

Expand Down Expand Up @@ -101,6 +107,21 @@ sourceSets {
}
}

buildConfig {
className("BuildConfig") // forces the class name. Defaults to 'BuildConfig'
packageName("net.irisshaders.iris") // forces the package. Defaults to '${project.group}'
useJavaOutput()

buildConfigField("IS_SHARED_BETA", Constants.IS_SHARED_BETA)
buildConfigField("BETA_TAG", Constants.BETA_TAG)
buildConfigField("BETA_VERSION", Constants.BETA_VERSION)

sourceSets.getByName("desktop") {
buildConfigField("IS_SHARED_BETA", Constants.IS_SHARED_BETA)
}
}


java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -145,6 +166,10 @@ dependencies {
}

tasks {
getByName<JavaCompile>("compileDesktopJava") {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}

jar {
from("${rootProject.projectDir}/LICENSE")
Expand All @@ -158,6 +183,10 @@ tasks {
from(vendored.output.classesDirs)
from(vendored.output.resourcesDir)

val desktop = sourceSets.getByName("desktop")
from(desktop.output.classesDirs)
from(desktop.output.resourcesDir)

from (sodiumCompatibility.output) {
this.filesMatching("*refmap.json") {
this.name = "iris-sodium-compat-refmap.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
public class LaunchWarn {
public static void main(String[] args) {
// TODO: make this translatable
String message = "This file is the Fabric version of Iris, meant to be installed as a mod. Would you like to get the Iris Installer instead?";
String fallback = "This file is the Fabric version of Iris, meant to be installed as a mod. Please download the Iris Installer from https://irisshaders.dev.";
String message = DesktopBuildConfig.IS_SHARED_BETA
? "If you're seeing this, you didn't read instructions.\n (Hint: This isn't a installer or a Forge mod. It's a Fabric mod.)"
: "This file is the Fabric version of Iris, meant to be installed as a mod. Would you like to get the Iris Installer instead?";
String fallback = DesktopBuildConfig.IS_SHARED_BETA
? "If you're seeing this, you didn't read instructions.\n (Hint: This isn't a installer or a Forge mod. It's a Fabric mod.)"
: "This file is the Fabric version of Iris, meant to be installed as a mod. Please download the Iris Installer from https://irisshaders.dev.";
if (GraphicsEnvironment.isHeadless()) {
System.err.println(fallback);
} else {
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/net/irisshaders/iris/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import net.irisshaders.iris.BuildConfig;
import net.irisshaders.iris.config.IrisConfig;
import net.irisshaders.iris.gl.shader.StandardMacros;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -39,7 +40,9 @@
public class UpdateChecker {
private final Version currentVersion;
private CompletableFuture<UpdateInfo> info;
private CompletableFuture<BetaInfo> betaInfo;
private boolean shouldShowUpdateMessage;
private boolean shouldShowBetaUpdateMessage;
private boolean usedIrisInstaller;

public UpdateChecker(Version currentVersion) {
Expand All @@ -50,6 +53,11 @@ public UpdateChecker(Version currentVersion) {
}

public void checkForUpdates(IrisConfig irisConfig) {
if (BuildConfig.IS_SHARED_BETA) {
checkBetaUpdates();
return;
}

if (irisConfig.shouldDisableUpdateMessage()) {
shouldShowUpdateMessage = false;
return;
Expand Down Expand Up @@ -115,6 +123,28 @@ public void checkForUpdates(IrisConfig irisConfig) {
});
}

private void checkBetaUpdates() {
this.betaInfo = CompletableFuture.supplyAsync(() -> {
try {
try (InputStream in = new URL("https://raw.githubusercontent.com/IrisShaders/Iris-Installer-Files/master/betaTag.json").openStream()) {
BetaInfo updateInfo = new Gson().fromJson(JsonParser.parseReader(new InputStreamReader(in)).getAsJsonObject(), BetaInfo.class);
if (BuildConfig.BETA_VERSION < updateInfo.betaVersion && BuildConfig.BETA_TAG.equalsIgnoreCase(updateInfo.betaTag)) {
shouldShowUpdateMessage = true;
Iris.logger.info("[Iris Beta Update Check] New update detected, showing update message!");
return updateInfo;
} else {
return null;
}
}
} catch (FileNotFoundException e) {
Iris.logger.warn("[Iris Beta Update Check] Unable to download " + e.getMessage());
} catch (IOException e) {
Iris.logger.warn("[Iris Beta Update Check] Failed to get update info!", e);
}
return null;
});
}

@Nullable
public UpdateInfo getUpdateInfo() {
if (info != null && info.isDone()) {
Expand All @@ -128,6 +158,19 @@ public UpdateInfo getUpdateInfo() {
return null;
}

@Nullable
public Optional<BetaInfo> getBetaInfo() {
if (betaInfo != null && betaInfo.isDone()) {
try {
return Optional.ofNullable(betaInfo.get());
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}

return Optional.empty();
}

public Optional<Component> getUpdateMessage() {
if (shouldShowUpdateMessage) {
UpdateInfo info = getUpdateInfo();
Expand Down Expand Up @@ -170,4 +213,9 @@ static class UpdateInfo {
public String modDownload;
public String installer;
}

public static class BetaInfo {
public String betaTag;
public int betaVersion;
}
}
10 changes: 6 additions & 4 deletions src/main/java/net/irisshaders/iris/compat/dh/DHCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class DHCompat {
private static boolean dhPresent = true;
private static boolean lastIncompatible;
private Object compatInternalInstance;
private static MethodHandle setupEventHandlers;
private static MethodHandle deletePipeline;
private static MethodHandle incompatible;
private static MethodHandle getDepthTex;
Expand All @@ -30,7 +31,7 @@ public class DHCompat {

public DHCompat(IrisRenderingPipeline pipeline, boolean renderDHShadow) {
try {
if (FabricLoader.getInstance().isModLoaded("distanthorizons")) {
if (dhPresent) {
compatInternalInstance = Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal").getDeclaredConstructor(pipeline.getClass(), boolean.class).newInstance(pipeline, renderDHShadow);
lastIncompatible = (boolean) incompatible.invoke(compatInternalInstance);
}
Expand All @@ -57,9 +58,8 @@ public static Matrix4f getProjection() {
public static void run() {
try {
if (FabricLoader.getInstance().isModLoaded("distanthorizons")) {
LodRendererEvents.setupEventHandlers();

deletePipeline = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "clear", MethodType.methodType(void.class));
setupEventHandlers = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.LodRendererEvents"), "setupEventHandlers", MethodType.methodType(void.class));
getDepthTex = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "getStoredDepthTex", MethodType.methodType(int.class));
getRenderDistance = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "getRenderDistance", MethodType.methodType(int.class));
incompatible = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "incompatiblePack", MethodType.methodType(boolean.class));
Expand All @@ -69,10 +69,12 @@ public static void run() {
checkFrame = MethodHandles.lookup().findStatic(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "checkFrame", MethodType.methodType(boolean.class));
renderShadowSolid = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "renderShadowSolid", MethodType.methodType(void.class));
renderShadowTranslucent = MethodHandles.lookup().findVirtual(Class.forName("net.irisshaders.iris.compat.dh.DHCompatInternal"), "renderShadowTranslucent", MethodType.methodType(void.class));

setupEventHandlers.invoke();
} else {
dhPresent = false;
}
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) {
} catch (Throwable e) {
dhPresent = false;

if (FabricLoader.getInstance().isModLoaded("distanthorizons")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.irisshaders.iris.uniforms.CapturedRenderingState;
import net.irisshaders.iris.uniforms.IrisTimeUniforms;
import net.irisshaders.iris.uniforms.SystemTimeUniforms;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
Expand All @@ -23,6 +24,7 @@
import net.minecraft.client.renderer.RenderBuffers;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.network.chat.Component;
import net.minecraft.world.TickRateManager;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
Expand Down Expand Up @@ -64,6 +66,7 @@ public class MixinLevelRenderer {

@Shadow
private @Nullable ClientLevel level;
private boolean warned;

// Begin shader rendering after buffers have been cleared.
// At this point we've ensured that Minecraft's main framebuffer is cleared.
Expand Down Expand Up @@ -117,6 +120,12 @@ public class MixinLevelRenderer {
pipeline.finalizeLevelRendering();
pipeline = null;

if (!warned) {
warned = true;
Iris.getUpdateChecker().getBetaInfo().ifPresent(info ->
Minecraft.getInstance().gui.getChat().addMessage(Component.literal("A new beta is out for Iris " + info.betaTag + ". Please redownload it.").withStyle(ChatFormatting.BOLD, ChatFormatting.RED)));
}

if (Iris.shouldActivateWireframe() && this.minecraft.isLocalServer()) {
IrisRenderSystem.setPolygonMode(GL43C.GL_FILL);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"canvas": "*",
"optifabric": "*",
"worldeditcui": "<1.18.1",
"physicsmod": "<=3.0.13",
"distanthorizons": "<=2.0.1",
"immersive_portals": "<=1.4.2"
},
"custom": {
Expand Down

0 comments on commit 29d4177

Please sign in to comment.