aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/main/java/me/shedaniel/rei/plugin
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2021-08-27 05:26:06 +0800
committershedaniel <daniel@shedaniel.me>2021-08-27 05:26:31 +0800
commit113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8 (patch)
treeda371c2c28ec95167aea4ebc91a6ff4a9f5f59b3 /runtime/src/main/java/me/shedaniel/rei/plugin
parenta4776b33fd86731249cf9b02c2ea6fff1bce9350 (diff)
downloadRoughlyEnoughItems-113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8.tar.gz
RoughlyEnoughItems-113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8.tar.bz2
RoughlyEnoughItems-113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8.zip
Add hints for if REI does not initialize properly
Diffstat (limited to 'runtime/src/main/java/me/shedaniel/rei/plugin')
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java11
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/PluginStageExecutionWatcher.java83
-rw-r--r--runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/SearchBarHighlightWatcher.java55
3 files changed, 147 insertions, 2 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java
index 8aeff8a20..08911b34b 100644
--- a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/DefaultRuntimePlugin.java
@@ -29,11 +29,11 @@ import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.type.EntryTypeRegistry;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import me.shedaniel.rei.api.common.fluid.FluidSupportProvider;
+import me.shedaniel.rei.api.common.plugins.PluginManager;
import me.shedaniel.rei.api.common.plugins.REIServerPlugin;
+import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.plugin.client.entry.FluidEntryDefinition;
import me.shedaniel.rei.plugin.client.entry.ItemEntryDefinition;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
@@ -44,6 +44,13 @@ import java.util.stream.Stream;
public class DefaultRuntimePlugin implements REIServerPlugin {
public static final ResourceLocation PLUGIN = new ResourceLocation("roughlyenoughitems", "default_runtime_plugin");
+ public DefaultRuntimePlugin() {
+ PluginStageExecutionWatcher watcher = new PluginStageExecutionWatcher();
+ PluginManager.getInstance().registerReloadable(watcher);
+ REIRuntimeImpl.getInstance().addHintProvider(watcher);
+ REIRuntimeImpl.getInstance().addHintProvider(new SearchBarHighlightWatcher());
+ }
+
@Override
public void registerEntryTypes(EntryTypeRegistry registry) {
registry.register(VanillaEntryTypes.ITEM, new ItemEntryDefinition());
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/PluginStageExecutionWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/PluginStageExecutionWatcher.java
new file mode 100644
index 000000000..c92020949
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/PluginStageExecutionWatcher.java
@@ -0,0 +1,83 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.common.runtime;
+
+import com.google.common.collect.ImmutableList;
+import me.shedaniel.math.Color;
+import me.shedaniel.math.Point;
+import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+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.impl.client.gui.hints.HintProvider;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TranslatableComponent;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public class PluginStageExecutionWatcher implements Reloadable<REIPlugin<?>>, HintProvider {
+ private Set<ReloadStage> stages = new HashSet<>();
+
+ @Override
+ public void startReload() {
+ for (ReloadStage stage : ReloadStage.values()) {
+ startReload(stage);
+ }
+ }
+
+ @Override
+ public void startReload(ReloadStage stage) {
+ if (stage.ordinal() == 0) stages.clear();
+ stages.add(stage);
+ }
+
+ public Set<ReloadStage> notVisited() {
+ Set<ReloadStage> notVisited = new HashSet<>(Arrays.asList(ReloadStage.values()));
+ notVisited.removeAll(stages);
+ return notVisited;
+ }
+
+ @Override
+ public List<Component> provide() {
+ Set<ReloadStage> notVisited = notVisited();
+ if (notVisited.isEmpty()) {
+ return Collections.emptyList();
+ } else {
+ return ImmutableList.of(new TranslatableComponent("text.rei.not.fully.initialized"));
+ }
+ }
+
+ @Override
+ @Nullable
+ public Tooltip provideTooltip(Point mouse) {
+ return Tooltip.create(mouse, new TranslatableComponent("text.rei.not.fully.initialized.tooltip", notVisited().stream().map(Enum::name).collect(Collectors.joining(", "))));
+ }
+
+ @Override
+ public Color getColor() {
+ return Color.ofTransparent(0x50ff1500);
+ }
+}
diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/SearchBarHighlightWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/SearchBarHighlightWatcher.java
new file mode 100644
index 000000000..08dd06ea0
--- /dev/null
+++ b/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/SearchBarHighlightWatcher.java
@@ -0,0 +1,55 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021 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.common.runtime;
+
+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.gui.widget.search.OverlaySearchField;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.TranslatableComponent;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+public class SearchBarHighlightWatcher implements HintProvider {
+ @Override
+ public List<Component> provide() {
+ return OverlaySearchField.isHighlighting ? Collections.singletonList(new TranslatableComponent("text.rei.inventory.highlighting.enabled")) :
+ Collections.emptyList();
+ }
+
+ @Override
+ @Nullable
+ public Tooltip provideTooltip(Point mouse) {
+ return Tooltip.create(mouse, new TranslatableComponent("text.rei.inventory.highlighting.enabled.tooltip"));
+ }
+
+ @Override
+ public Color getColor() {
+ return Color.ofTransparent(0x50f7ed23);
+ }
+}