diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-10-28 15:12:18 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-10-28 15:12:18 +0800 |
| commit | 6b44b3e633e009d9d3fdedfa02b46db34dd5b1ae (patch) | |
| tree | d00eaeabc27639a717593d0613c7a381fb341eb9 /runtime | |
| parent | e3eebe08fac49d1924670565bc4e34b151ef395d (diff) | |
| parent | b68e07108e21e4f1f231dfccac6c095c22b9a695 (diff) | |
| download | RoughlyEnoughItems-6b44b3e633e009d9d3fdedfa02b46db34dd5b1ae.tar.gz RoughlyEnoughItems-6b44b3e633e009d9d3fdedfa02b46db34dd5b1ae.tar.bz2 RoughlyEnoughItems-6b44b3e633e009d9d3fdedfa02b46db34dd5b1ae.zip | |
Merge remote-tracking branch 'origin/6.x-1.17' into 7.x-1.18
# Conflicts:
# gradle.properties
# settings.gradle
Diffstat (limited to 'runtime')
41 files changed, 1552 insertions, 190 deletions
diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 6bab2c9d8..654552028 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -23,6 +23,7 @@ package me.shedaniel.rei; +import com.google.common.collect.ImmutableList; import dev.architectury.platform.Platform; import dev.architectury.registry.ReloadListenerRegistry; import dev.architectury.utils.Env; @@ -50,6 +51,12 @@ import me.shedaniel.rei.impl.common.entry.comparison.ItemComparatorRegistryImpl; import me.shedaniel.rei.impl.common.entry.comparison.NbtHasherProviderImpl; import me.shedaniel.rei.impl.common.entry.type.EntryTypeRegistryImpl; import me.shedaniel.rei.impl.common.fluid.FluidSupportProviderImpl; +import me.shedaniel.rei.impl.common.logging.FileLogger; +import me.shedaniel.rei.impl.common.logging.Log4JLogger; +import me.shedaniel.rei.impl.common.logging.Logger; +import me.shedaniel.rei.impl.common.logging.MultiLogger; +import me.shedaniel.rei.impl.common.logging.performance.PerformanceLogger; +import me.shedaniel.rei.impl.common.logging.performance.PerformanceLoggerImpl; import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl; import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl; import me.shedaniel.rei.impl.common.transfer.MenuInfoRegistryImpl; @@ -58,7 +65,6 @@ import net.minecraft.server.packs.PackType; import net.minecraft.util.Unit; import org.apache.commons.lang3.mutable.MutableLong; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.ApiStatus; import java.util.function.Function; @@ -67,7 +73,11 @@ import java.util.function.UnaryOperator; @ApiStatus.Internal public class RoughlyEnoughItemsCore { @ApiStatus.Internal - public static final Logger LOGGER = LogManager.getFormatterLogger("REI"); + public static final Logger LOGGER = new MultiLogger(ImmutableList.of( + new FileLogger(Platform.getGameFolder().resolve("logs/rei.log")), + new Log4JLogger(LogManager.getFormatterLogger("REI")) + )); + public static final PerformanceLogger PERFORMANCE_LOGGER = new PerformanceLoggerImpl(); static { attachCommonInternals(); @@ -123,13 +133,13 @@ public class RoughlyEnoughItemsCore { } try { for (PluginManager<? extends REIPlugin<?>> instance : PluginManager.getActiveInstances()) { - instance.view().pre(); + instance.view().pre(stage); } for (PluginManager<? extends REIPlugin<?>> instance : PluginManager.getActiveInstances()) { instance.startReload(stage); } for (PluginManager<? extends REIPlugin<?>> instance : PluginManager.getActiveInstances()) { - instance.view().post(); + instance.view().post(stage); } } catch (Throwable throwable) { throwable.printStackTrace(); @@ -144,7 +154,10 @@ 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(() -> RoughlyEnoughItemsCore._reloadPlugins(null), executor2); + return preparationBarrier.wait(Unit.INSTANCE).thenRunAsync(() -> { + PERFORMANCE_LOGGER.clear(); + RoughlyEnoughItemsCore._reloadPlugins(null); + }, executor2); }); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index a411fcb77..094bbe4ea 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -56,6 +56,7 @@ import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.ClientInternals; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; +import me.shedaniel.rei.impl.client.entry.renderer.EntryRendererRegistryImpl; import me.shedaniel.rei.impl.client.favorites.DelegatingFavoriteEntryProviderImpl; import me.shedaniel.rei.impl.client.favorites.FavoriteEntryTypeRegistryImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; @@ -118,6 +119,9 @@ public class RoughlyEnoughItemsCoreClient { private static final ExecutorService RELOAD_PLUGINS = Executors.newSingleThreadScheduledExecutor(task -> { Thread thread = new Thread(task, "REI-ReloadPlugins"); thread.setDaemon(true); + thread.setUncaughtExceptionHandler(($, exception) -> { + RoughlyEnoughItemsCore.LOGGER.throwException(exception); + }); return thread; }); @@ -173,6 +177,7 @@ public class RoughlyEnoughItemsCoreClient { usedTime ); }, + new EntryRendererRegistryImpl(), new ViewsImpl(), new SearchProviderImpl(), new ConfigManagerImpl(), @@ -269,8 +274,14 @@ 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(startReload, ReloadStage.START)); - ClientRecipeUpdateEvent.EVENT.register(recipeManager -> reloadPlugins(endReload, Platform.isFabric() ? ReloadStage.END : null)); + PRE_UPDATE_RECIPES.register(recipeManager -> { + RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); + reloadPlugins(startReload, ReloadStage.START); + }); + ClientRecipeUpdateEvent.EVENT.register(recipeManager -> { + if (!Platform.isFabric()) RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); + reloadPlugins(endReload, Platform.isFabric() ? ReloadStage.END : null); + }); ClientGuiEvent.INIT_POST.register((screen, access) -> { REIRuntimeImpl.getInstance().setPreviousScreen(screen); if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof AbstractContainerScreen) { diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 8973e6a51..545cdda1e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -24,6 +24,7 @@ package me.shedaniel.rei; import dev.architectury.networking.NetworkManager; +import dev.architectury.networking.transformers.SplitPacketTransformer; import io.netty.buffer.Unpooled; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; @@ -41,6 +42,8 @@ import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.inventory.RecipeBookMenu; import net.minecraft.world.item.ItemStack; +import java.util.Collections; + public class RoughlyEnoughItemsNetwork { public static final ResourceLocation DELETE_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "delete_item"); public static final ResourceLocation CREATE_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "create_item"); @@ -50,7 +53,7 @@ public class RoughlyEnoughItemsNetwork { public static final ResourceLocation NOT_ENOUGH_ITEMS_PACKET = new ResourceLocation("roughlyenoughitems", "og_not_enough"); public static void onInitialize() { - NetworkManager.registerReceiver(NetworkManager.c2s(), DELETE_ITEMS_PACKET, (buf, context) -> { + NetworkManager.registerReceiver(NetworkManager.c2s(), DELETE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> { ServerPlayer player = (ServerPlayer) context.getPlayer(); if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { player.displayClientMessage(new TranslatableComponent("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); @@ -62,7 +65,7 @@ public class RoughlyEnoughItemsNetwork { menu.broadcastChanges(); } }); - NetworkManager.registerReceiver(NetworkManager.c2s(), CREATE_ITEMS_PACKET, (buf, context) -> { + NetworkManager.registerReceiver(NetworkManager.c2s(), CREATE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> { ServerPlayer player = (ServerPlayer) context.getPlayer(); if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { player.displayClientMessage(new TranslatableComponent("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); @@ -75,7 +78,7 @@ public class RoughlyEnoughItemsNetwork { player.displayClientMessage(new TranslatableComponent("text.rei.failed_cheat_items"), false); } }); - NetworkManager.registerReceiver(NetworkManager.c2s(), CREATE_ITEMS_GRAB_PACKET, (buf, context) -> { + NetworkManager.registerReceiver(NetworkManager.c2s(), CREATE_ITEMS_GRAB_PACKET, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> { ServerPlayer player = (ServerPlayer) context.getPlayer(); if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) { player.displayClientMessage(new TranslatableComponent("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false); @@ -94,7 +97,7 @@ public class RoughlyEnoughItemsNetwork { menu.broadcastChanges(); NetworkManager.sendToPlayer(player, RoughlyEnoughItemsNetwork.CREATE_ITEMS_MESSAGE_PACKET, new FriendlyByteBuf(Unpooled.buffer()).writeItem(itemStack.copy()).writeUtf(player.getScoreboardName(), 32767)); }); - NetworkManager.registerReceiver(NetworkManager.c2s(), MOVE_ITEMS_PACKET, (packetByteBuf, context) -> { + NetworkManager.registerReceiver(NetworkManager.c2s(), MOVE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (packetByteBuf, context) -> { ServerPlayer player = (ServerPlayer) context.getPlayer(); CategoryIdentifier<Display> category = CategoryIdentifier.of(packetByteBuf.readResourceLocation()); AbstractContainerMenu container = player.containerMenu; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java index 12bf9da50..7fb13845a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java @@ -29,7 +29,7 @@ import me.shedaniel.rei.impl.client.gui.screen.WarningAndErrorScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; -import java.util.function.Consumer; +import java.util.function.UnaryOperator; public class ErrorDisplayer { public void onInitializeClient() { @@ -46,18 +46,15 @@ public class ErrorDisplayer { } }); warningAndErrorScreen.setParent(screen); - try { - if (minecraft.screen != null) minecraft.screen.removed(); - } catch (Throwable ignored) { - } - minecraft.screen = null; - minecraft.setScreen(warningAndErrorScreen); + return warningAndErrorScreen; } + + return null; }); } @ExpectPlatform - public static void registerGuiInit(Consumer<Screen> consumer) { + public static void registerGuiInit(UnaryOperator<Screen> consumer) { throw new AssertionError(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index 07a94a0b3..e80e5f572 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -43,6 +43,7 @@ import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.hints.HintProvider; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; +import me.shedaniel.rei.impl.client.search.argument.Argument; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -216,6 +217,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public void startReload() { + Argument.SEARCH_CACHE.clear(); getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); lastDisplayScreen.clear(); } @@ -227,6 +229,7 @@ public class REIRuntimeImpl implements REIRuntime { @Override public void endReload(ReloadStage stage) { + Argument.SEARCH_CACHE.clear(); getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index f582734e2..e6eefa6b6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -63,6 +63,7 @@ import me.shedaniel.rei.impl.client.entry.filtering.FilteringRule; import me.shedaniel.rei.impl.client.entry.filtering.rules.ManualFilteringRule; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.credits.CreditsScreen; +import me.shedaniel.rei.impl.client.gui.performance.entry.PerformanceEntry; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; @@ -340,6 +341,7 @@ public class ConfigManagerImpl implements ConfigManager { builder.setGlobalizedExpanded(false); if (Minecraft.getInstance().getConnection() != null && Minecraft.getInstance().getConnection().getRecipeManager() != null) { builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ReloadPluginsEntry(220)); + builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new PerformanceEntry(220)); } return builder.setAfterInitConsumer(screen -> { TextListEntry feedbackEntry = ConfigEntryBuilder.create().startTextDescription( diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 089819553..fba1fd4c2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -493,7 +493,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private EntryPanelOrderingConfig entryPanelOrdering = EntryPanelOrderingConfig.REGISTRY_ASCENDING; @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99) - private int maxRecipesPerPage = 15; + private int maxRecipesPerPage = 3; @Comment("Declares whether entry rendering time should be debugged.") private boolean debugRenderTimeRequired = false; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java index a96680983..6452e883c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java @@ -48,7 +48,10 @@ import java.util.Optional; @ApiStatus.Internal public class ReloadPluginsEntry extends AbstractConfigListEntry<Unit> { private int width; - private AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, button -> RoughlyEnoughItemsCoreClient.reloadPlugins(null, null)) { + private AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, button -> { + RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); + RoughlyEnoughItemsCoreClient.reloadPlugins(null, null); + }) { @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { if (PluginManager.areAnyReloading()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringContextImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringContextImpl.java index 3bf154c6b..1d52db2d9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringContextImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/FilteringContextImpl.java @@ -46,7 +46,7 @@ public class FilteringContextImpl implements FilteringContext { public final Map<FilteringContextType, Set<HashedEntryStackWrapper>> stacks; private final Map<FilteringContextType, Collection<EntryStack<?>>> cachedStacks; - public FilteringContextImpl(List<EntryStack<?>> allStacks) { + public FilteringContextImpl(Collection<EntryStack<?>> allStacks) { this.stacks = Maps.newHashMap(); this.cachedStacks = Maps.newHashMap(); for (FilteringContextType type : FilteringContextType.values()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java new file mode 100644 index 000000000..62b3235a2 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/renderer/EntryRendererRegistryImpl.java @@ -0,0 +1,66 @@ +/* + * 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.impl.client.entry.renderer; + +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; +import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; +import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer; +import me.shedaniel.rei.api.client.entry.renderer.EntryRendererProvider; +import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry; +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.EntryType; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Objects; + +public class EntryRendererRegistryImpl implements EntryRendererRegistry { + private final Multimap<EntryType<?>, EntryRendererProvider<?>> providers = Multimaps.newListMultimap(new Reference2ObjectOpenHashMap<>(), ArrayList::new); + + @Override + public <T> void register(EntryType<T> type, EntryRendererProvider<T> provider) { + this.providers.put(type, provider); + } + + @Override + public <T> EntryRenderer<T> get(EntryStack<T> stack) { + EntryRenderer<T> renderer = stack.getDefinition().getRenderer(); + for (EntryRendererProvider<T> provider : (Collection<EntryRendererProvider<T>>) (Collection<? extends EntryRendererProvider<?>>) providers.get(stack.getType())) { + |
