From 2318a37d8482498bdec25947e15177ba77996cb8 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 27 Aug 2021 22:36:16 +0800 Subject: Fix REI not initiated issues, and server crash issues --- .../rei/RoughlyEnoughItemsCoreClient.java | 2 +- .../rei/impl/client/gui/hints/HintProvider.java | 3 + .../client/runtime/DefaultClientRuntimePlugin.java | 14 ++++ .../runtime/PluginStageExecutionWatcher.java | 89 ++++++++++++++++++++++ .../client/runtime/SearchBarHighlightWatcher.java | 55 +++++++++++++ .../common/runtime/DefaultRuntimePlugin.java | 9 --- .../runtime/PluginStageExecutionWatcher.java | 83 -------------------- .../common/runtime/SearchBarHighlightWatcher.java | 55 ------------- 8 files changed, 162 insertions(+), 148 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/PluginStageExecutionWatcher.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/SearchBarHighlightWatcher.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 2b3a9aef4..a411fcb77 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -269,7 +269,7 @@ public class RoughlyEnoughItemsCoreClient { final ResourceLocation recipeButtonTex = new ResourceLocation("textures/gui/recipe_button.png"); MutableLong startReload = new MutableLong(-1); MutableLong endReload = new MutableLong(-1); - PRE_UPDATE_RECIPES.register(recipeManager -> reloadPlugins(endReload, ReloadStage.START)); + PRE_UPDATE_RECIPES.register(recipeManager -> reloadPlugins(startReload, ReloadStage.START)); ClientRecipeUpdateEvent.EVENT.register(recipeManager -> reloadPlugins(endReload, Platform.isFabric() ? ReloadStage.END : null)); ClientGuiEvent.INIT_POST.register((screen, access) -> { REIRuntimeImpl.getInstance().setPreviousScreen(screen); 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 d66c63387..e34544294 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 @@ -26,11 +26,14 @@ package me.shedaniel.rei.impl.client.gui.hints; import me.shedaniel.math.Color; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.List; +@Environment(EnvType.CLIENT) public interface HintProvider { List provide(); 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 22bd239b4..c9c57d4ab 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 @@ -51,8 +51,12 @@ import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry; import me.shedaniel.rei.api.client.util.ClientEntryStacks; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.plugins.REIPlugin; +import me.shedaniel.rei.api.common.registry.Reloadable; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.ClientHelperImpl; +import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.screen.AbstractDisplayViewingScreen; import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; @@ -76,6 +80,16 @@ import java.util.function.Function; @Environment(EnvType.CLIENT) @ApiStatus.Internal public class DefaultClientRuntimePlugin implements REIClientPlugin { + @SuppressWarnings("rawtypes") + public DefaultClientRuntimePlugin() { + PluginStageExecutionWatcher watcher = new PluginStageExecutionWatcher(); + for (PluginManager> instance : PluginManager.getActiveInstances()) { + instance.registerReloadable((Reloadable) watcher.reloadable(instance)); + } + REIRuntimeImpl.getInstance().addHintProvider(watcher); + REIRuntimeImpl.getInstance().addHintProvider(new SearchBarHighlightWatcher()); + } + @Override public void registerEntries(EntryRegistry registry) { if (ClientHelperImpl.getInstance().isAprilFools.get()) { 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 new file mode 100644 index 000000000..10326394c --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/PluginStageExecutionWatcher.java @@ -0,0 +1,89 @@ +/* + * 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.client.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.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.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 HintProvider { + private Map, Set> allStages = new HashMap<>(); + + public > Reloadable reloadable(PluginManager manager) { + return new Reloadable<>() { + @Override + public void startReload() { + for (ReloadStage stage : ReloadStage.values()) { + startReload(stage); + } + } + + @Override + public void startReload(ReloadStage stage) { + Set stages = allStages.computeIfAbsent(manager, $ -> new HashSet<>()); + if (stage.ordinal() == 0) stages.clear(); + stages.add(stage); + } + }; + } + + public Set notVisited() { + Set notVisited = new HashSet<>(Arrays.asList(ReloadStage.values())); + notVisited.removeIf(stage -> allStages.values().stream().allMatch(stages -> stages.contains(stage))); + return notVisited; + } + + @Override + public List provide() { + Set 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/client/runtime/SearchBarHighlightWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/SearchBarHighlightWatcher.java new file mode 100644 index 000000000..0447bde21 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/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.client.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 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); + } +} 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 08911b34b..60adc004c 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,9 +29,7 @@ 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.minecraft.resources.ResourceLocation; @@ -44,13 +42,6 @@ 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 deleted file mode 100644 index c92020949..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/PluginStageExecutionWatcher.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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>, HintProvider { - private Set 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 notVisited() { - Set notVisited = new HashSet<>(Arrays.asList(ReloadStage.values())); - notVisited.removeAll(stages); - return notVisited; - } - - @Override - public List provide() { - Set 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 deleted file mode 100644 index 08dd06ea0..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/common/runtime/SearchBarHighlightWatcher.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 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); - } -} -- cgit