aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-02-01 21:15:23 +0800
committershedaniel <daniel@shedaniel.me>2022-02-01 21:15:23 +0800
commit87ffd039b745b4bea631c26a60731497c176988d (patch)
treee879f9933e1e3e23d682a5939a59e4f7656316f9 /runtime
parent986e99beb15303c825e30e383d134d543e6f54ae (diff)
downloadRoughlyEnoughItems-87ffd039b745b4bea631c26a60731497c176988d.tar.gz
RoughlyEnoughItems-87ffd039b745b4bea631c26a60731497c176988d.tar.bz2
RoughlyEnoughItems-87ffd039b745b4bea631c26a60731497c176988d.zip
Add progress bar to plugin reloads
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java14
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java4
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java5
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchField.java37
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java3
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/impl/common/plugins/PluginManagerImpl.java44
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java146
8 files changed, 233 insertions, 25 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java
index be517ff15..ca7c9c068 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java
@@ -40,5 +40,10 @@ public interface HintProvider {
@Nullable
Tooltip provideTooltip(Point mouse);
+ @Nullable
+ default Double getProgress() {
+ return null;
+ }
+
Color getColor();
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java
index 57c319968..47e846125 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java
@@ -46,26 +46,26 @@ public class ConfigReloadingScreen extends Screen {
}
@Override
- public void render(PoseStack matrices, int int_1, int int_2, float float_1) {
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
this.renderDirtBackground(0);
if (!PluginManager.areAnyReloading()) {
parent.run();
}
drawCenteredString(matrices, this.font, I18n.get("text.rei.config.is.reloading"), this.width / 2, this.height / 2 - 50, 16777215);
- String string_3;
+ String text;
switch ((int) (Util.getMillis() / 300L % 4L)) {
case 0:
default:
- string_3 = "O o o";
+ text = "O o o";
break;
case 1:
case 3:
- string_3 = "o O o";
+ text = "o O o";
break;
case 2:
- string_3 = "o o O";
+ text = "o o O";
}
- drawCenteredString(matrices, this.font, string_3, this.width / 2, this.height / 2 - 41, 8421504);
- super.render(matrices, int_1, int_2, float_1);
+ drawCenteredString(matrices, this.font, text, this.width / 2, this.height / 2 - 41, 8421504);
+ super.render(matrices, mouseX, mouseY, delta);
}
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
index b44e90a9c..7a363f315 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/UncertainDisplayViewingScreen.java
@@ -39,6 +39,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
import me.shedaniel.rei.api.client.ClientHelper;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.config.ConfigManager;
+import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.gui.animator.NumberAnimator;
import me.shedaniel.rei.api.client.gui.animator.ValueAnimator;
import me.shedaniel.rei.api.client.gui.config.DisplayScreenType;
@@ -103,6 +104,7 @@ public class UncertainDisplayViewingScreen extends Screen {
this.parent = parent;
this.showTips = showTips;
if (showTips && false && Platform.isForge()) {
+ this.jeiEnabled = ConfigObject.getInstance().isJEICompatibilityLayerEnabled();
allModsUsingJEI = ClientInternals.getJeiCompatMods().stream()
.distinct()
.map(ClientHelper.getInstance()::getModFromModId)
@@ -150,7 +152,7 @@ public class UncertainDisplayViewingScreen extends Screen {
ConfigManager.getInstance().saveConfig();
RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear();
RoughlyEnoughItemsCoreClient.reloadPlugins(null, null);
- Minecraft.getInstance().setScreen(new ConfigReloadingScreen(() -> callback.accept(original)));
+ Minecraft.getInstance().setScreen(REIRuntime.getInstance().getPreviousScreen());
} else {
callback.accept(original);
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java
index 3438025e0..5894740da 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/FavoritesListWidget.java
@@ -52,6 +52,7 @@ import me.shedaniel.rei.api.client.overlay.OverlayListWidget;
import me.shedaniel.rei.api.client.overlay.ScreenOverlay;
import me.shedaniel.rei.api.client.util.ClientEntryStacks;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.util.CollectionUtils;
import me.shedaniel.rei.api.common.util.ImmutableTextComponent;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
@@ -276,7 +277,9 @@ public class FavoritesListWidget extends WidgetWithBounds implements DraggableSt
} else {
trashBounds.setBounds(0, 0, 0, 0);
}
- updateSystemRegion();
+ if (!PluginManager.areAnyReloading()) {
+ updateSystemRegion();
+ }
// systemRegion.getBounds().setBounds(this.fullBounds.x + 1, this.fullBounds.y - 1 + 14, this.fullBounds.width - 1, Math.max(1, systemRegion.scrolling.getMaxScrollHeight()));
systemRegion.getBounds().setBounds(this.fullBounds.x, this.fullBounds.y + 1, this.fullBounds.width, Math.max(1, systemRegion.scrolling.getMaxScrollHeight()));
int systemHeight = systemRegion.getBounds().getHeight();
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchField.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchField.java
index 1c7a05f0e..df4b4409e 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchField.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/search/OverlaySearchField.java
@@ -35,6 +35,8 @@ import me.shedaniel.math.Rectangle;
import me.shedaniel.math.impl.PointHelper;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.config.ConfigObject;
+import me.shedaniel.rei.api.client.gui.animator.NumberAnimator;
+import me.shedaniel.rei.api.client.gui.animator.ValueAnimator;
import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.api.common.util.CollectionUtils;
@@ -60,6 +62,8 @@ import net.minecraft.util.Tuple;
import org.jetbrains.annotations.ApiStatus;
import java.util.List;
+import java.util.Objects;
+import java.util.OptionalDouble;
import java.util.function.Consumer;
@ApiStatus.Internal
@@ -74,6 +78,7 @@ public class OverlaySearchField extends TextFieldWidget implements TextFieldWidg
public boolean isMain = true;
protected Tuple<Long, Point> lastClickedDetails = null;
private List<String> history = Lists.newArrayListWithCapacity(100);
+ private final NumberAnimator<Double> progress = ValueAnimator.ofDouble();
public OverlaySearchField(int x, int y, int width, int height) {
super(x, y, width, height);
@@ -137,21 +142,31 @@ public class OverlaySearchField extends TextFieldWidget implements TextFieldWidg
}
}
- public void laterRender(PoseStack matrices, int int_1, int int_2, float float_1) {
+ public void laterRender(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ progress.update(delta);
RenderSystem.disableDepthTest();
- if (isMain) drawHint(matrices, int_1, int_2);
+ if (isMain) drawHint(matrices, mouseX, mouseY);
setSuggestion(!isFocused() && getText().isEmpty() ? I18n.get("text.rei.search.field.suggestion") : null);
- super.render(matrices, int_1, int_2, float_1);
+ super.render(matrices, mouseX, mouseY, delta);
RenderSystem.enableDepthTest();
}
- private void drawHint(PoseStack poses, int int_1, int int_2) {
- List<Pair<HintProvider, Component>> hints = CollectionUtils.flatMap(REIRuntimeImpl.getInstance().getHintProviders(), provider ->
+ private void drawHint(PoseStack poses, int mouseX, int mouseY) {
+ List<HintProvider> hintProviders = REIRuntimeImpl.getInstance().getHintProviders();
+ List<Pair<HintProvider, Component>> hints = CollectionUtils.flatMap(hintProviders, provider ->
CollectionUtils.map(provider.provide(), component -> new Pair<>(provider, component)));
if (hints.isEmpty()) return;
int width = getBounds().getWidth() - 4;
List<Pair<HintProvider, FormattedCharSequence>> sequences = CollectionUtils.flatMap(hints, pair ->
CollectionUtils.map(font.split(pair.getSecond(), width - 6), sequence -> new Pair<>(pair.getFirst(), sequence)));
+ OptionalDouble progress = hintProviders.stream().map(HintProvider::getProgress).filter(Objects::nonNull).mapToDouble(Double::doubleValue)
+ .average();
+ boolean hasProgress = progress.isPresent();
+ if (!hasProgress) {
+ this.progress.setAs(0);
+ } else {
+ this.progress.setTo(progress.getAsDouble(), 200);
+ }
Color color = hints.stream()
.map(Pair::getFirst)
.distinct()
@@ -162,7 +177,7 @@ public class OverlaySearchField extends TextFieldWidget implements TextFieldWidg
int b = color1.getBlue() - (color1.getBlue() - color2.getBlue()) / 2;
return Color.ofRGBA(r, g, b, (color1.getAlpha() + color2.getAlpha()) / 2);
}).orElse(Color.ofTransparent(0x50000000));
- int height = 6 + font.lineHeight * sequences.size();
+ int height = 6 + font.lineHeight * sequences.size() + (hasProgress ? 2 : 0);
int x = getBounds().getX() + 2;
int y = getBounds().getY() - height;
Tesselator tesselator = Tesselator.getInstance();
@@ -182,6 +197,12 @@ public class OverlaySearchField extends TextFieldWidget implements TextFieldWidg
fillGradient(pose, bufferBuilder, x + width - 1, y + 1, x + width, y + height - 1, 400, color1, color2);
fillGradient(pose, bufferBuilder, x, y, x + width, y + 1, 400, color1, color1);
fillGradient(pose, bufferBuilder, x, y + height - 1, x + width, y + height, 400, color2, color2);
+
+ if (hasProgress) {
+ int progressWidth = (int) Math.round(width * this.progress.doubleValue());
+ fillGradient(pose, bufferBuilder, x + 1, y + height - 3, x + progressWidth - 1, y + height - 1, 400, 0xffffffff, 0xffffffff);
+ }
+
bufferBuilder.end();
BufferUploader.end(bufferBuilder);
poses.pushPose();
@@ -189,8 +210,8 @@ public class OverlaySearchField extends TextFieldWidget implements TextFieldWidg
for (int i = 0; i < sequences.size(); i++) {
Pair<HintProvider, FormattedCharSequence> pair = sequences.get(i);
int lineWidth = font.drawShadow(poses, pair.getSecond(), x + 3, y + 3 + font.lineHeight * i, -1);
- if (new Rectangle(x + 3, y + 3 + font.lineHeight * i, lineWidth, font.lineHeight).contains(int_1, int_2)) {
- Tooltip tooltip = pair.getFirst().provideTooltip(new Point(int_1, int_2));
+ if (new Rectangle(x + 3, y + 3 + font.lineHeight * i, lineWidth, font.lineHeight).contains(mouseX, mouseY)) {
+ Tooltip tooltip = pair.getFirst().provideTooltip(new Point(mouseX, mouseY));
if (tooltip != null) {
tooltip.queue();
}
diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java
index 6c401dd83..fac2fbb6a 100644
--- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java
+++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java
@@ -55,6 +55,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.*;
+import java.util.concurrent.CopyOnWriteArrayList;
@ApiStatus.Internal
@Environment(EnvType.CLIENT)
@@ -63,7 +64,7 @@ public class ScreenRegistryImpl implements ScreenRegistry {
private List<DraggableStackProvider<Screen>> draggableStacksProviders = new ArrayList<>();
private List<DraggableStackVisitor<Screen>> draggableStacksVisitors = new ArrayList<>();
private List<FocusedStackProvider> focusedStackProviders = new ArrayList<>();
- private List<OverlayDecider> deciders = new ArrayList<>();
+ private List<OverlayDecider> deciders = new CopyOnWriteArrayList<>();
private Map<Class<?>, List<OverlayDecider>> cache = new HashMap<>();
private ExclusionZones exclusionZones;
private Class<? extends Screen> tmpScreen;
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 611f4f944..249ba8a2c 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
@@ -249,6 +249,7 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager<
reloading = true;
long startTime = Util.getMillis();
+ // Pre Reload
try (SectionClosable startReloadAll = section(stage, "start-reload/");
PerformanceLogger.Plugin perfLogger = RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.stage("Reload Initialization")) {
for (Reloadable<P> reloadable : reloadables) {
@@ -262,23 +263,64 @@ public class PluginManagerImpl<P extends REIPlugin<?>> implements PluginManager<
}
}
+ // Sort Plugins
List<PluginWrapper<P>> plugins = new ArrayList<>(getPluginWrapped().toList());
plugins.sort(Comparator.comparingDouble(PluginWrapper<P>::getPriority).reversed());
RoughlyEnoughItemsCore.LOGGER.info("Reloading Plugin Manager [%s] stage [%s], registered %d plugins: %s", name(pluginClass), stage.toString(), plugins.size(), CollectionUtils.mapAndJoinToString(plugins, PluginWrapper::getPluginProviderName, ", "));
Collections.reverse(plugins);
+ // Reload
for (Reloadable<P> reloadable : getReloadables()) {
Class<?> reloadableClass = reloadable.getClass();
try (SectionClosable reloadablePlugin = section(stage, "reloadable-plugin/" + name(reloadableClass) + "/");
PerformanceLogger.Plugin perfLogger = RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.stage(name(reloadableClass))) {
+ try (PerformanceLogger.Plugin.Inner inner = perfLogger.stage("reloadable-plugin/" + name(reloadableClass) + "/prompt-others-before")) {
+ for (Reloadable<P> listener : reloadables) {
+ try {
+ listener.beforeReloadable(stage, reloadable);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+ }
+
pluginSection(stage, "reloadable-plugin/" + name(reloadableClass) + "/", plugins, reloadable, plugin -> {
try (PerformanceLogger.Plugin.Inner inner = perfLogger.plugin(new Pair<>(plugin.provider, plugin.plugin))) {
- reloadable.acceptPlugin(plugin.plugin, stage);
+ for (Reloadable<P> listener : reloadables) {
+ try {
+ listener.beforeReloadablePlugin(stage, reloadable, plugin.plugin);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+
+ try {
+ reloadable.acceptPlugin(plugin.plugin, stage);
+ } finally {
+ for (Reloadable<P> listener : reloadables) {
+ try {
+ listener.afterReloadablePlugin(stage, reloadable, plugin.plugin);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+ }
}
});
+
+ try (PerformanceLogger.Plugin.Inner inner = perfLogger.stage("reloadable-plugin/" + name(reloadableClass) + "/prompt-others-after")) {
+ for (Reloadable<P> listener : reloadables) {
+ try {
+ listener.afterReloadable(stage, reloadable);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ }
+ }
}
}
+ // Post Reload
try (SectionClosable endReloadAll = section(stage, "end-reload/");
PerformanceLogger.Plugin perfLogger = RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.stage("Reload Finalization")) {
for (Reloadable<P> reloadable : reloadables) {
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java
index 92bde75ff..8a2770312 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java
@@ -24,6 +24,9 @@
package me.shedaniel.rei.plugin.client.runtime;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import it.unimi.dsi.fastutil.doubles.DoubleIntMutablePair;
+import it.unimi.dsi.fastutil.doubles.DoubleIntPair;
import me.shedaniel.math.Color;
import me.shedaniel.math.Point;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
@@ -31,19 +34,41 @@ import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.plugins.REIPlugin;
import me.shedaniel.rei.api.common.registry.ReloadStage;
import me.shedaniel.rei.api.common.registry.Reloadable;
+import me.shedaniel.rei.api.common.util.ImmutableTextComponent;
import me.shedaniel.rei.impl.client.gui.hints.HintProvider;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.Triple;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.stream.Collectors;
public class PluginStageExecutionWatcher implements HintProvider {
- private final Map<PluginManager<?>, Set<ReloadStage>> allStages = new HashMap<>();
+ private final Map<PluginManager<?>, PluginManagerData> allStages = new HashMap<>();
+
+ private static class PluginManagerData {
+ private final PluginManager<?> manager;
+ private final Map<ReloadStage, List<Reloadable<?>>> beganStages = new HashMap<>();
+ private final Set<ReloadStage> finishedStages = new HashSet<>();
+
+ public PluginManagerData(PluginManager<?> manager) {
+ this.manager = manager;
+ }
+
+ private void clear() {
+ beganStages.clear();
+ finishedStages.clear();
+ }
+ }
public <T extends REIPlugin<?>> Reloadable<? extends T> reloadable(PluginManager<?> manager) {
return new Reloadable<>() {
+ private PluginManagerData data() {
+ return allStages.computeIfAbsent(manager, PluginManagerData::new);
+ }
+
@Override
public void startReload() {
for (ReloadStage stage : ReloadStage.values()) {
@@ -54,9 +79,31 @@ public class PluginStageExecutionWatcher implements HintProvider {
@Override
public void startReload(ReloadStage stage) {
synchronized (allStages) {
- Set<ReloadStage> stages = allStages.computeIfAbsent(manager, $ -> new HashSet<>());
- if (stage.ordinal() == 0) stages.clear();
- stages.add(stage);
+ if (manager == PluginManager.getInstance() && stage.ordinal() == 0) {
+ allStages.clear();
+ }
+ data().beganStages.put(stage, new ArrayList<>());
+ }
+ }
+
+ @Override
+ public void endReload() {
+ for (ReloadStage stage : ReloadStage.values()) {
+ endReload(stage);
+ }
+ }
+
+ @Override
+ public void endReload(ReloadStage stage) {
+ synchronized (allStages) {
+ data().finishedStages.add(stage);
+ }
+ }
+
+ @Override
+ public void beforeReloadable(ReloadStage stage, Reloadable<T> other) {
+ synchronized (allStages) {
+ data().beganStages.get(stage).add(other);
}
}
};
@@ -65,21 +112,102 @@ public class PluginStageExecutionWatcher implements HintProvider {
public Set<ReloadStage> notVisited() {
synchronized (allStages) {
Set<ReloadStage> notVisited = new HashSet<>(Arrays.asList(ReloadStage.values()));
- notVisited.removeIf(stage -> allStages.values().stream().allMatch(stages -> stages.contains(stage)));
+ notVisited.removeIf(stage -> allStages.values().stream().allMatch(data -> data.finishedStages.contains(stage)));
return notVisited;
}
}
+ private int lastStep;
+ private Double lastProgress;
+
@Override
public List<Component> provide() {
+ List<ReloadStage> stages = Arrays.asList(ReloadStage.values());
Set<ReloadStage> notVisited = notVisited();
+ int allManagers = PluginManager.getActiveInstances().size();
+ DoubleIntPair[] progresses = new DoubleIntPair[allManagers];
+ Triple<PluginManager<?>, ReloadStage, Reloadable<?>> current = null;
+ int i = 0;
+
+ for (PluginManager<? extends REIPlugin<?>> manager : PluginManager.getActiveInstances()) {
+ PluginManagerData data = allStages.get(manager);
+ int index = i++;
+
+ if (data == null) {
+ progresses[index] = DoubleIntPair.of(0, 0);
+ continue;
+ }
+
+ boolean allDone = data.finishedStages.size() == stages.size();
+ if (allDone) {
+ progresses[index] = DoubleIntPair.of(stages.size(), stages.size());
+ } else {
+ DoubleIntMutablePair pair = new DoubleIntMutablePair(0, 0);
+ for (ReloadStage stage : stages) {
+ List<Reloadable<?>> reloadables = data.beganStages.get(stage);
+ pair.right(pair.rightInt() + 1);
+
+ if (reloadables == null) {
+ continue;
+ }
+
+ boolean finished = data.finishedStages.contains(stage);
+
+ if (finished) {
+ pair.left(pair.leftDouble() + 1);
+ } else {
+ pair.left(pair.leftDouble() + (reloadables.size() / (double) manager.getReloadables().size()));
+
+ if (!reloadables.isEmpty()) {
+ Reloadable<?> currentReloadable = Iterables.getLast(reloadables);
+ current = Triple.of(manager, stage, currentReloadable);
+ }
+ }
+ }
+ for (Map.Entry<ReloadStage, List<Reloadable<?>>> stageSetEntry : data.beganStages.entrySet()) {
+ ReloadStage stage = stageSetEntry.getKey();
+
+ }
+ progresses[index] = pair;
+ }
+ }
+
if (notVisited.isEmpty()) {
+ lastProgress = null;
return Collections.emptyList();
} else {
- return ImmutableList.of(new TranslatableComponent("text.rei.not.fully.initialized"));
+ double total = 0;
+ int j = 0;
+ for (DoubleIntPair pair : progresses) {
+ total += pair == null || pair.rightInt() == 0 ? 0 : pair.leftDouble() / pair.rightInt();
+ }
+ double average = total / progresses.length;
+ lastProgress = average;
+ String progress;
+ String currentTask;
+ if (current != null) {
+ int managerIndex = PluginManager.getActiveInstances().indexOf(current.getLeft());
+ lastStep = managerIndex + 1 + current.getMiddle().ordinal() * allManagers;
+ }
+ progress = String.format("Step %d/%d (%s%%):", lastStep, allManagers * stages.size(), Math.round(average * 100));
+ if (current == null) {
+ currentTask = "Waiting";
+ } else {
+ currentTask = getSimpleName(current.getRight().getClass());
+ }
+ return ImmutableList.of(new TranslatableComponent("text.rei.not.fully.initialized"),
+ new ImmutableTextComponent(progress), new ImmutableTextComponent(currentTask));
}
}
+ private static <P> String getSimpleName(Class<? extends P> clazz) {
+ String name = clazz.getName();
+ name = name.contains(".") ? StringUtils.substringAfterLast(name, ".") : name;
+ name = name.replace("Impl", "");
+ name = name.replace("$", ".");
+ return name;
+ }
+
@Override
@Nullable
public Tooltip provideTooltip(Point mouse) {
@@ -87,6 +215,12 @@ public class PluginStageExecutionWatcher implements HintProvider {
}
@Override
+ @Nullable
+ public Double getProgress() {
+ return lastProgress;
+ }
+
+ @Override
public Color getColor() {
return Color.ofTransparent(0x50ff1500);
}