diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-06-19 02:44:47 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2023-05-29 21:00:31 +0800 |
| commit | c680b92a7bd32050a11827f2a7290f34ed03ef98 (patch) | |
| tree | 3cadff4ab1943ce5b4bfe9800fa09999ce92af4e /runtime/src/main/java | |
| parent | 020a705d3947c38c1f27d6d322bade09a17c0853 (diff) | |
| download | RoughlyEnoughItems-c680b92a7bd32050a11827f2a7290f34ed03ef98.tar.gz RoughlyEnoughItems-c680b92a7bd32050a11827f2a7290f34ed03ef98.tar.bz2 RoughlyEnoughItems-c680b92a7bd32050a11827f2a7290f34ed03ef98.zip | |
Fix #918
Diffstat (limited to 'runtime/src/main/java')
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java | 39 | ||||
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java | 16 |
2 files changed, 45 insertions, 10 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 7709e03c4..9ab085fc4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -50,7 +50,9 @@ import me.shedaniel.rei.api.client.registry.screen.ClickArea; import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; +import me.shedaniel.rei.api.common.plugins.REIPlugin; import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; @@ -108,9 +110,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.*; import java.util.function.BiFunction; import java.util.function.BooleanSupplier; import java.util.function.Function; @@ -131,6 +131,7 @@ public class RoughlyEnoughItemsCoreClient { }); return thread; }); + private static final List<Future<?>> RELOAD_TASKS = new CopyOnWriteArrayList<>(); public static void attachClientInternals() { InternalWidgets.attach(); @@ -320,8 +321,24 @@ public class RoughlyEnoughItemsCoreClient { reloadPlugins(startReload, ReloadStage.START); }); RecipeUpdateEvent.EVENT.register(recipeManager -> { - if (!Platform.isFabric()) RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); - reloadPlugins(endReload, Platform.isFabric() ? ReloadStage.END : null); + reloadPlugins(endReload, ReloadStage.END); + }); + ClientGuiEvent.INIT_PRE.register((screen, access) -> { + List<ReloadStage> stages = ((PluginManagerImpl<REIPlugin<?>>) PluginManager.getInstance()).getObservedStages(); + + if (Minecraft.getInstance().level != null && Minecraft.getInstance().player != null && stages.contains(ReloadStage.START) + && !stages.contains(ReloadStage.END) && !PluginManager.areAnyReloading() && screen instanceof AbstractContainerScreen) { + for (Future<?> task : RELOAD_TASKS) { + if (!task.isDone()) { + return EventResult.pass(); + } + } + + RoughlyEnoughItemsCore.LOGGER.error("Detected missing stage: END! This is possibly due to issues during client recipe reload! REI will force a reload of the recipes now!"); + reloadPlugins(endReload, ReloadStage.END); + } + + return EventResult.pass(); }); GuiEvent.INIT_POST.register((screen, widgets, children) -> { REIRuntime.getInstance().getOverlay(false, true); @@ -453,7 +470,17 @@ public class RoughlyEnoughItemsCoreClient { lastReload.setValue(System.currentTimeMillis()); } if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) { - CompletableFuture.runAsync(() -> RoughlyEnoughItemsCore._reloadPlugins(start), RELOAD_PLUGINS); + Future<?>[] futures = new Future<?>[1]; + CompletableFuture<Void> future = CompletableFuture.runAsync(() -> RoughlyEnoughItemsCore._reloadPlugins(start), RELOAD_PLUGINS) + .whenComplete((unused, throwable) -> { + // Remove the future from the list of futures + if (futures[0] != null) { + RELOAD_TASKS.remove(futures[0]); + futures[0] = null; + } + }); + futures[0] = future; + RELOAD_TASKS.add(future); } else { RoughlyEnoughItemsCore._reloadPlugins(start); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java index 21db89cca..164e589f1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java @@ -60,7 +60,9 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< private final Map<Class<? extends Reloadable<P>>, Reloadable<? super P>> cache = new ConcurrentHashMap<>(); private final Class<P> pluginClass; private final UnaryOperator<PluginView<P>> view; - private boolean reloading = false; + @Nullable + private ReloadStage reloading = null; + private List<ReloadStage> observedStages = new ArrayList<>(); private final List<REIPluginProvider<P>> plugins = new ArrayList<>(); private final LongConsumer reloadDoneListener; private final Stopwatch reloadStopwatch = Stopwatch.createUnstarted(); @@ -84,7 +86,7 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< @Override public boolean isReloading() { - return reloading; + return reloading != null; } @Override @@ -224,6 +226,8 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< this.forcedMainThread = false; this.forceMainThreadStopwatch.reset(); this.reloadStopwatch.reset().start(); + this.observedStages.clear(); + this.observedStages.add(stage); List<PluginWrapper<P>> plugins = new ArrayList<>(getPluginWrapped().toList()); plugins.sort(Comparator.comparingDouble(PluginWrapper<P>::getPriority).reversed()); Collections.reverse(plugins); @@ -279,7 +283,7 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< public void startReload(ReloadStage stage) { try { this.reloadStopwatch.start(); - reloading = true; + reloading = stage; // Pre Reload try (SectionClosable startReloadAll = section(stage, "start-reload/"); @@ -372,7 +376,11 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager< } catch (Throwable throwable) { throwable.printStackTrace(); } finally { - reloading = false; + reloading = null; } } + + public List<ReloadStage> getObservedStages() { + return observedStages; + } } |
