aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-02-28 10:05:31 +0800
committershedaniel <daniel@shedaniel.me>2022-02-28 10:05:31 +0800
commit6ff07fe77b6d15157f262a766798e683e55c2c57 (patch)
tree5e9099bf245611d73e4646379ae79ebb45585fb1 /runtime/src/main/java/me/shedaniel/rei/plugin
parente35aa217aa3bbba5653201186add39de871fae07 (diff)
downloadRoughlyEnoughItems-6ff07fe77b6d15157f262a766798e683e55c2c57.tar.gz
RoughlyEnoughItems-6ff07fe77b6d15157f262a766798e683e55c2c57.tar.bz2
RoughlyEnoughItems-6ff07fe77b6d15157f262a766798e683e55c2c57.zip
Add search caching hint
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java1
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java80
2 files changed, 81 insertions, 0 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
index 9101f7648..41c37ce83 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java
@@ -91,6 +91,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin {
}
REIRuntimeImpl.getInstance().addHintProvider(watcher);
REIRuntimeImpl.getInstance().addHintProvider(new SearchBarHighlightWatcher());
+ REIRuntimeImpl.getInstance().addHintProvider(new SearchFilterPrepareWatcher());
}
@Override
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java
new file mode 100644
index 000000000..436f41724
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchFilterPrepareWatcher.java
@@ -0,0 +1,80 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.plugin.client.runtime;
+
+import com.google.common.collect.ImmutableList;
+import it.unimi.dsi.fastutil.ints.IntIntPair;
+import me.shedaniel.math.Color;
+import me.shedaniel.math.Point;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.impl.client.gui.hints.HintProvider;
+import me.shedaniel.rei.impl.client.search.argument.Argument;
+import net.minecraft.Util;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TranslatableComponent;
+import org.apache.commons.lang3.ArrayUtils;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+public class SearchFilterPrepareWatcher implements HintProvider {
+ private Double lastProcess;
+
+ @Override
+ public List<Component> provide() {
+ lastProcess = null;
+ if (Argument.prepareStage != null && Argument.currentStages != null && Argument.prepareStacks != null && Argument.prepareStacks.size() > 100) {
+ if (Util.getEpochMillis() - Argument.prepareStart < 500) return Collections.emptyList();
+ int prepareStageCurrent = Argument.prepareStage.firstInt();
+ int prepareStageTotal = Argument.prepareStage.secondInt();
+ IntIntPair currentStage = ArrayUtils.get(Argument.currentStages, prepareStageCurrent - 1);
+ int currentStageCurrent = currentStage == null ? 0 : currentStage.firstInt();
+ int currentStageTotal = currentStage == null ? 0 : currentStage.secondInt();
+ double prepareStageProgress = prepareStageTotal == 0 ? 0 : prepareStageCurrent / (double) prepareStageTotal;
+ double currentStageProgress = currentStageTotal == 0 ? 0 : currentStageCurrent / (double) currentStageTotal;
+ lastProcess = prepareStageTotal == 0 ? 0 : Math.max(0, prepareStageProgress - (1 - currentStageProgress) / prepareStageTotal);
+ return ImmutableList.of(new TranslatableComponent("text.rei.caching.search"),
+ new TranslatableComponent("text.rei.caching.search.step", prepareStageCurrent, prepareStageTotal, Math.round(lastProcess * 100)));
+ }
+ return Collections.emptyList();
+ }
+
+ @Override
+ @Nullable
+ public Tooltip provideTooltip(Point mouse) {
+ return null;
+ }
+
+ @Override
+ @Nullable
+ public Double getProgress() {
+ return lastProcess;
+ }
+
+ @Override
+ public Color getColor() {
+ return Color.ofTransparent(0x50de38ff);
+ }
+}