diff options
Diffstat (limited to 'runtime/src/main/java')
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java | 24 | ||||
| -rw-r--r-- | runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java | 24 |
2 files changed, 27 insertions, 21 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 1cda29bf3..3e7bba901 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -27,7 +27,6 @@ import dev.architectury.platform.Platform; import dev.architectury.registry.ReloadListenerRegistry; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; -import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.annotation.Nullable; import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; import me.shedaniel.rei.api.common.entry.comparison.FluidComparatorRegistry; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; @@ -40,6 +39,7 @@ import me.shedaniel.rei.api.common.registry.RecipeManagerContext; import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.transfer.info.MenuInfoRegistry; import me.shedaniel.rei.impl.Internals; +import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.logging.performance.PerformanceLogger; import me.shedaniel.rei.impl.common.logging.performance.PerformanceLoggerImpl; import me.shedaniel.rei.impl.init.PluginDetector; @@ -47,6 +47,7 @@ import net.minecraft.server.packs.PackType; import net.minecraft.util.Unit; import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -71,6 +72,7 @@ public class RoughlyEnoughItemsCore { PluginManager.getInstance().registerReloadable(DisplaySerializerRegistry.class); PluginManager.getInstance().registerReloadable(FluidSupportProvider.class); PluginManager.getServerInstance().registerReloadable(MenuInfoRegistry.class); + Internals.attachInstanceSupplier((Runnable) () -> RoughlyEnoughItemsCore.reloadPlugins(null, null), "reloadREI"); } public static void _reloadPlugins(@Nullable ReloadStage stage) { @@ -95,6 +97,21 @@ public class RoughlyEnoughItemsCore { } } + public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start) { + if (lastReload != null) { + if (lastReload.getValue() > 0 && System.currentTimeMillis() - lastReload.getValue() <= 5000) { + InternalLogger.getInstance().warn("Suppressing Reload Plugins of stage " + start); + return; + } + lastReload.setValue(System.currentTimeMillis()); + } + if (start == null) PERFORMANCE_LOGGER.clear(); + if (Platform.getEnvironment() == Env.CLIENT) { + if (RoughlyEnoughItemsCoreClient.reloadPluginsClient(start)) return; + } + _reloadPlugins(start); + } + public void onInitialize() { for (PluginDetector detector : PLUGIN_DETECTORS) { detector.detectCommonPlugins(); @@ -105,10 +122,7 @@ public class RoughlyEnoughItemsCore { if (Platform.getEnvironment() == Env.SERVER) { MutableLong lastReload = new MutableLong(-1); ReloadListenerRegistry.register(PackType.SERVER_DATA, (preparationBarrier, resourceManager, profilerFiller, profilerFiller2, executor, executor2) -> { - return preparationBarrier.wait(Unit.INSTANCE).thenRunAsync(() -> { - PERFORMANCE_LOGGER.clear(); - RoughlyEnoughItemsCore._reloadPlugins(null); - }, executor2); + return preparationBarrier.wait(Unit.INSTANCE).thenRunAsync(PluginManager::reloadAll, executor2); }); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index e2dba5a38..7c56d41d9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -102,7 +102,6 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.crafting.Ingredient; import org.apache.commons.lang3.function.TriFunction; import org.apache.commons.lang3.mutable.MutableLong; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; @@ -303,11 +302,11 @@ public class RoughlyEnoughItemsCoreClient { MutableLong startReload = new MutableLong(-1); MutableLong endReload = new MutableLong(-1); PRE_UPDATE_RECIPES.register(recipeManager -> { - RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); - reloadPlugins(startReload, ReloadStage.START); + PluginManager.reloadAll(); + RoughlyEnoughItemsCore.reloadPlugins(startReload, ReloadStage.START); }); ClientRecipeUpdateEvent.EVENT.register(recipeManager -> { - reloadPlugins(endReload, ReloadStage.END); + RoughlyEnoughItemsCore.reloadPlugins(endReload, ReloadStage.END); }); ClientGuiEvent.INIT_PRE.register((screen, access) -> { List<ReloadStage> stages = ((PluginManagerImpl<REIPlugin<?>>) PluginManager.getInstance()).getReloader().getObservedStages(); @@ -321,7 +320,7 @@ public class RoughlyEnoughItemsCoreClient { } InternalLogger.getInstance().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); + RoughlyEnoughItemsCore.reloadPlugins(endReload, ReloadStage.END); } return EventResult.pass(); @@ -449,15 +448,7 @@ public class RoughlyEnoughItemsCoreClient { return true; } - @ApiStatus.Internal - public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start) { - if (lastReload != null) { - if (lastReload.getValue() > 0 && System.currentTimeMillis() - lastReload.getValue() <= 5000) { - InternalLogger.getInstance().warn("Suppressing Reload Plugins of stage " + start); - return; - } - lastReload.setValue(System.currentTimeMillis()); - } + static boolean reloadPluginsClient(@Nullable ReloadStage start) { if (ConfigObject.getInstance().doesRegisterRecipesInAnotherThread()) { Future<?>[] futures = new Future<?>[1]; CompletableFuture<Void> future = CompletableFuture.runAsync(() -> RoughlyEnoughItemsCore._reloadPlugins(start), RELOAD_PLUGINS) @@ -470,8 +461,9 @@ public class RoughlyEnoughItemsCoreClient { }); futures[0] = future; RELOAD_TASKS.add(future); - } else { - RoughlyEnoughItemsCore._reloadPlugins(start); + return true; } + + return false; } } |
