Skip to content

Commit

Permalink
Merge pull request #4 from GTNewHorizons/fix-bls-npe
Browse files Browse the repository at this point in the history
Fix NPE with BLS
  • Loading branch information
Dream-Master authored Mar 20, 2023
2 parents f5c9313 + 0c07de9 commit e887176
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
36 changes: 22 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1679040806
//version: 1679170051
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -513,14 +513,6 @@ repositories {
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
allowInsecureProtocol = true
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
if (usesMixinDebug.toBoolean()) {
maven {
name = "Fabric Maven"
url = "https://maven.fabricmc.net/"
}
}
}
maven {
name 'sonatype'
url 'https://oss.sonatype.org/content/repositories/snapshots/'
Expand Down Expand Up @@ -559,29 +551,45 @@ repositories {
}
}

def mixinProviderGroup = "io.github.legacymoddingmc"
def mixinProviderModule = "unimixins"
def mixinProviderVersion = "0.1.5"
def mixinProviderSpec = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"

dependencies {
if (usesMixins.toBoolean()) {
annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3')
annotationProcessor('com.google.guava:guava:24.1.1-jre')
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.13:processor')
annotationProcessor(mixinProviderSpec)
if (usesMixinDebug.toBoolean()) {
runtimeOnlyNonPublishable('org.jetbrains:intellij-fernflower:1.2.1.16')
}
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
implementation('com.gtnewhorizon:gtnhmixins:2.1.13')
implementation(mixinProviderSpec)
}
}

pluginManager.withPlugin('org.jetbrains.kotlin.kapt') {
if (usesMixins.toBoolean()) {
dependencies {
kapt('com.gtnewhorizon:gtnhmixins:2.1.13:processor')
kapt(mixinProviderSpec)
}
}
}

// Replace old mixin mods with unimixins
// https://docs.gradle.org/8.0.2/userguide/resolution_rules.html#sec:substitution_with_classifier
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('com.gtnewhorizon:gtnhmixins') using module(mixinProviderSpec) withoutClassifier() because("Unimixins replaces other mixin mods")
substitute module('com.github.GTNewHorizons:Mixingasm') using module(mixinProviderSpec) withoutClassifier() because("Unimixins replaces other mixin mods")
substitute module('com.github.GTNewHorizons:SpongePoweredMixin') using module(mixinProviderSpec) withoutClassifier() because("Unimixins replaces other mixin mods")
substitute module('com.github.GTNewHorizons:SpongeMixins') using module(mixinProviderSpec) withoutClassifier() because("Unimixins replaces other mixin mods")
}
}

apply from: 'dependencies.gradle'

def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json'
Expand Down Expand Up @@ -1125,7 +1133,7 @@ if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) {
}
}
if (usesMixins.toBoolean()) {
addModrinthDep("required", "project", "gtnhmixins")
addModrinthDep("required", "project", "unimixins")
}
tasks.modrinth.dependsOn(build)
tasks.publish.dependsOn(tasks.modrinth)
Expand Down Expand Up @@ -1169,7 +1177,7 @@ if (curseForgeProjectId.size() != 0 && System.getenv("CURSEFORGE_TOKEN") != null
}
}
if (usesMixins.toBoolean()) {
addCurseForgeRelation("requiredDependency", "gtnhmixins")
addCurseForgeRelation("requiredDependency", "unimixins")
}
tasks.curseforge.dependsOn(build)
tasks.publish.dependsOn(tasks.curseforge)
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/glowredman/txloader/progress/ProgressBarProxy.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
package glowredman.txloader.progress;

import java.lang.reflect.Field;

public class ProgressBarProxy {

public static boolean isBLSLoaded;

private static Class<?> ProgressDisplayer;
private static Field displayer;

public static IProgressBar get(String name, int maxSteps) {
return isBLSLoaded ? new BLSProgressBar(name, maxSteps) : new FMLProgressBar(name, maxSteps);
return (isBLSLoaded && isDisplayerAvailable()) ? new BLSProgressBar(name, maxSteps)
: new FMLProgressBar(name, maxSteps);
}

public static boolean isDisplayerAvailable() {
if (ProgressDisplayer == null) return false;

if (displayer == null) {
try {
displayer = ProgressDisplayer.getDeclaredField("displayer");
} catch (Exception ignored) {
// This shouldn't be reached...
// In case it is, cause early exits in the future
isBLSLoaded = false;
ProgressDisplayer = null;
return false;
}
}

try {
return displayer.get(null) != null;
} catch (Exception ignored) {
return false;
}
}

static {
try {
ProgressDisplayer = Class.forName("alexiil.mods.load.ProgressDisplayer");
} catch (Exception ignored) {}
}

private ProgressBarProxy() {}
Expand Down

0 comments on commit e887176

Please sign in to comment.