Skip to content

Commit

Permalink
Merge pull request #3 from GTNewHorizons/bsl-comapt
Browse files Browse the repository at this point in the history
Add BetterLoadingScreen Comapt
  • Loading branch information
Dream-Master authored Mar 18, 2023
2 parents 3288872 + 9c7c778 commit f5c9313
Show file tree
Hide file tree
Showing 11 changed files with 389 additions and 28 deletions.
309 changes: 290 additions & 19 deletions build.gradle

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dependencies {}
dependencies {
compileOnly("com.github.GTNewHorizons:BetterLoadingScreen:1.3.39-GTNH:dev") { transitive = false }
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/glowredman/txloader/RemoteHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import com.google.gson.JsonSyntaxException;

import cpw.mods.fml.common.ProgressManager;
import cpw.mods.fml.common.ProgressManager.ProgressBar;
import glowredman.txloader.Asset.Source;
import glowredman.txloader.progress.IProgressBar;
import glowredman.txloader.progress.ProgressBarProxy;

@SuppressWarnings("deprecation")
class RemoteHandler {

static String latestRelease;
Expand Down Expand Up @@ -50,7 +49,7 @@ static boolean getVersions() {
static void getAssets() {
final Map<JVersionDetails, Map<String, JAsset>> assets = new HashMap<>();
final Map<String, JVersionDetails> versionDetailsCache = new HashMap<>();
final ProgressBar bar = ProgressManager.push("Loading Remote Assets", TXLoaderCore.REMOTE_ASSETS.size());
final IProgressBar bar = ProgressBarProxy.get("Loading Remote Assets", TXLoaderCore.REMOTE_ASSETS.size());
int added = 0;
int skipped = 0;
int failed = 0;
Expand Down Expand Up @@ -131,7 +130,7 @@ static void getAssets() {
added++;
}
TXLoaderCore.LOGGER.info("Successfully added {} assets. ({} skipped, {} failed)", added, skipped, failed);
ProgressManager.pop(bar);
bar.pop();
}

private static JVersionManifest downloadManifest() throws JsonSyntaxException, IOException {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/glowredman/txloader/TXLoaderModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

import cpw.mods.fml.common.DummyModContainer;
import cpw.mods.fml.common.LoadController;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModMetadata;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.versioning.VersionParser;
import cpw.mods.fml.common.versioning.VersionRange;
import glowredman.txloader.progress.ProgressBarProxy;

public class TXLoaderModContainer extends DummyModContainer {

Expand Down Expand Up @@ -48,6 +51,11 @@ public boolean registerBus(EventBus bus, LoadController controller) {
return true;
}

@Subscribe
public void preInit(FMLPreInitializationEvent event) {
ProgressBarProxy.isBLSLoaded = Loader.isModLoaded("betterloadingscreen");
}

@Subscribe
public void serverStarting(FMLServerStartingEvent event) {
event.registerServerCommand(new CommandTX());
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/glowredman/txloader/progress/BLSProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package glowredman.txloader.progress;

import java.io.IOException;

import alexiil.mods.load.ProgressDisplayer;
import cpw.mods.fml.common.FMLCommonHandler;

class BLSProgressBar implements IProgressBar {

private final String name;
private final int maxSteps;
private int currentStep = 0;

BLSProgressBar(String name, int maxSteps) {
this.name = name;
this.maxSteps = maxSteps;
}

@Override
public void step(String message) {
this.currentStep++;
try {
ProgressDisplayer
.displayProgress(this.name + ": " + message, (float) this.currentStep / (float) this.maxSteps);
} catch (IOException e) {
throw new RuntimeException(e);
}
FMLCommonHandler.instance().processWindowMessages();
}

@Override
public void pop() {}

}
25 changes: 25 additions & 0 deletions src/main/java/glowredman/txloader/progress/FMLProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package glowredman.txloader.progress;

import cpw.mods.fml.common.ProgressManager;
import cpw.mods.fml.common.ProgressManager.ProgressBar;

@SuppressWarnings("deprecation")
class FMLProgressBar implements IProgressBar {

private final ProgressBar instance;

FMLProgressBar(String name, int maxSteps) {
this.instance = ProgressManager.push(name, maxSteps);
}

@Override
public void step(String message) {
this.instance.step(message);
}

@Override
public void pop() {
ProgressManager.pop(this.instance);
}

}
9 changes: 9 additions & 0 deletions src/main/java/glowredman/txloader/progress/IProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package glowredman.txloader.progress;

public interface IProgressBar {

void step(String message);

void pop();

}
13 changes: 13 additions & 0 deletions src/main/java/glowredman/txloader/progress/ProgressBarProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package glowredman.txloader.progress;

public class ProgressBarProxy {

public static boolean isBLSLoaded;

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

private ProgressBarProxy() {}

}

0 comments on commit f5c9313

Please sign in to comment.