Skip to content

Commit

Permalink
wait for pregens
Browse files Browse the repository at this point in the history
Signed-off-by: Devan-Kerman <[email protected]>
  • Loading branch information
Devan-Kerman committed Mar 3, 2022
1 parent 6e03d34 commit 2b44b80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/main/java/net/devtech/arrp/ARRP.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package net.devtech.arrp;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import net.devtech.arrp.api.RRPPreGenEntrypoint;
import net.devtech.arrp.impl.RuntimeResourcePackImpl;
import org.apache.logging.log4j.LogManager;
Expand All @@ -10,13 +15,25 @@

public class ARRP implements PreLaunchEntrypoint {
private static final Logger LOGGER = LogManager.getLogger("ARRP");
private static List<Future<?>> futures;

@Override
public void onPreLaunch() {
LOGGER.info("I used the json to destroy the json");
FabricLoader loader = FabricLoader.getInstance();
List<Future<?>> futures = new ArrayList<>();
for (RRPPreGenEntrypoint entrypoint : loader.getEntrypoints("rrp:pregen", RRPPreGenEntrypoint.class)) {
RuntimeResourcePackImpl.EXECUTOR_SERVICE.submit(entrypoint::pregen);
futures.add(RuntimeResourcePackImpl.EXECUTOR_SERVICE.submit(entrypoint::pregen));
}
ARRP.futures = futures;
}

public static void waitForPregen() throws ExecutionException, InterruptedException {
if(futures != null) {
for(Future<?> future : futures) {
future.get();
}
futures = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;

import net.devtech.arrp.ARRP;
import net.devtech.arrp.api.RRPCallback;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -25,7 +27,9 @@ public abstract class ReloadableResourceManagerImplMixin {
private List<ResourcePack> registerARRPs(List<ResourcePack> packs, Executor prepareExecutor,
Executor applyExecutor,
CompletableFuture<Unit> initialStage,
List<ResourcePack> packs0) {
List<ResourcePack> packs0) throws ExecutionException, InterruptedException {
ARRP.waitForPregen();

ARRP_LOGGER.info("ARRP register - before vanilla");
List<ResourcePack> before = new ArrayList<>();
RRPCallback.BEFORE_VANILLA.invoker().insert(before);
Expand All @@ -38,6 +42,7 @@ private List<ResourcePack> registerARRPs(List<ResourcePack> packs, Executor prep

before.addAll(after);


return before;
}
}

0 comments on commit 2b44b80

Please sign in to comment.