aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-07-31 21:37:58 +0800
committershedaniel <daniel@shedaniel.me>2022-08-26 10:52:28 +0900
commit8f5d3ef632f3d1a733c98ce5607c9fd5a0fd7567 (patch)
treed25de04229cf417b81fe4166734890ab0f387bf3 /runtime/src/main/java/me
parent9954713e457a5a5d80025432961b56ab0003bbb0 (diff)
downloadRoughlyEnoughItems-8f5d3ef632f3d1a733c98ce5607c9fd5a0fd7567.tar.gz
RoughlyEnoughItems-8f5d3ef632f3d1a733c98ce5607c9fd5a0fd7567.tar.bz2
RoughlyEnoughItems-8f5d3ef632f3d1a733c98ce5607c9fd5a0fd7567.zip
Add reload all to the api
Diffstat (limited to 'runtime/src/main/java/me')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java24
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java24
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;
}
}