From ddb48e2032d1986709cad973067693eec3118504 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 26 Oct 2024 16:55:52 +0800 Subject: Update to 1.21.2 (Please read Primer) https://hackmd.io/@shedaniel/rei17_primer --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 22 +- .../rei/RoughlyEnoughItemsCoreClient.java | 71 ++++-- .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 52 +--- .../rei/impl/client/ClientHelperImpl.java | 2 +- .../rei/impl/client/config/ConfigManagerImpl.java | 5 +- .../client/config/addon/ConfigAddonsScreen.java | 3 +- .../client/config/entries/ConfigAddonsEntry.java | 4 +- .../config/entries/FilteringRulesScreen.java | 3 +- .../client/config/entries/FilteringScreen.java | 37 ++- .../rei/impl/client/gui/RecipeDisplayExporter.java | 15 +- .../impl/client/gui/config/REIConfigScreen.java | 2 +- .../gui/config/components/ConfigGroupWidget.java | 2 +- .../gui/config/components/ConfigOptionWidget.java | 6 +- .../config/options/preview/InterfacePreviewer.java | 4 +- .../config/options/preview/TooltipPreviewer.java | 47 ++-- .../gui/craftable/CraftableFilterCalculator.java | 27 +-- .../client/gui/error/ErrorsEntryListWidget.java | 3 +- .../rei/impl/client/gui/modules/Menu.java | 7 +- .../client/gui/modules/entries/SubMenuEntry.java | 14 +- .../gui/modules/entries/ToggleMenuEntry.java | 12 +- .../gui/performance/DisplayRegistryInfoScreen.java | 2 +- .../performance/entry/SubCategoryListEntry.java | 3 +- .../gui/screen/AbstractDisplayViewingScreen.java | 15 +- .../gui/screen/CompositeDisplayViewingScreen.java | 7 +- .../gui/screen/DefaultDisplayViewingScreen.java | 15 +- .../SearchFilterSyntaxHighlightingScreen.java | 61 ----- .../gui/screen/UncertainDisplayViewingScreen.java | 8 +- .../collapsible/CollapsibleEntriesScreen.java | 8 +- .../screen/collapsible/CollapsibleEntryWidget.java | 25 +- .../CustomCollapsibleEntrySelectionScreen.java | 35 ++- .../gui/screen/generic/OptionEntriesScreen.java | 3 +- .../gui/toast/CopyRecipeIdentifierToast.java | 38 ++- .../gui/toast/ExportRecipeIdentifierToast.java | 38 ++- .../client/gui/widget/CachedEntryListRender.java | 20 +- .../impl/client/gui/widget/ConfigButtonWidget.java | 3 +- .../client/gui/widget/DisplayCompositeWidget.java | 6 +- .../client/gui/widget/DisplayTooltipComponent.java | 6 +- .../widget/DynamicErrorFreeEntryListWidget.java | 105 ++++---- .../rei/impl/client/gui/widget/EntryWidget.java | 21 +- .../rei/impl/client/gui/widget/HoleWidget.java | 73 +----- .../impl/client/gui/widget/InternalWidgets.java | 5 - .../rei/impl/client/gui/widget/QueuedTooltip.java | 16 ++ .../impl/client/gui/widget/TabContainerWidget.java | 14 +- .../rei/impl/client/gui/widget/TabWidget.java | 11 +- .../impl/client/gui/widget/UpdatedListWidget.java | 18 +- .../client/gui/widget/basewidgets/ArrowWidget.java | 7 +- .../gui/widget/basewidgets/BurningFireWidget.java | 7 +- .../gui/widget/basewidgets/ButtonWidget.java | 65 +---- .../basewidgets/FillRectangleDrawableConsumer.java | 25 +- .../client/gui/widget/basewidgets/PanelWidget.java | 64 +---- .../gui/widget/basewidgets/TextFieldWidget.java | 33 ++- .../basewidgets/TexturedDrawableConsumer.java | 27 +-- .../gui/widget/entrylist/CachingEntryRenderer.java | 7 +- .../widget/entrylist/CollapsedEntriesTooltip.java | 10 +- .../widget/entrylist/PaginatedEntryListWidget.java | 5 +- .../widget/entrylist/ScrolledEntryListWidget.java | 7 +- .../favorites/history/DisplayHistoryManager.java | 20 +- .../favorites/history/DisplayHistoryWidget.java | 105 ++++---- .../panel/FadingFavoritesPanelButton.java | 6 +- .../gui/widget/favorites/panel/FavoritesPanel.java | 6 +- .../panel/FavoritesTogglePanelButton.java | 3 +- .../gui/widget/region/EntryStacksRegionWidget.java | 9 +- .../gui/widget/region/RegionRenderingDebugger.java | 7 +- .../display/DisplayGeneratorsRegistryImpl.java | 66 +++++ .../impl/client/registry/display/DisplayKey.java | 60 ----- .../registry/display/DisplayRegistryImpl.java | 266 ++++++++++----------- .../client/registry/display/DisplaysHolder.java | 51 ---- .../registry/display/DisplaysHolderImpl.java | 148 ------------ .../impl/client/registry/display/RemappingMap.java | 124 ---------- .../impl/client/transfer/MissingStacksTooltip.java | 9 +- .../client/transfer/SimpleTransferHandlerImpl.java | 31 +-- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 35 ++- .../display/DisplaySerializerRegistryImpl.java | 103 ++++++-- .../rei/impl/common/entry/EntryIngredientImpl.java | 22 -- .../comparison/FluidComparatorRegistryImpl.java | 4 +- .../comparison/ItemComparatorRegistryImpl.java | 4 +- .../settings/EntrySettingsAdapterRegistryImpl.java | 8 +- .../common/entry/type/EntryTypeRegistryImpl.java | 4 +- .../entry/type/types/BuiltinEntryDefinition.java | 24 +- .../common/fluid/FluidSupportProviderImpl.java | 4 +- .../impl/common/networking/DisplaySyncPacket.java | 131 ++++++++++ .../rei/impl/common/plugins/PluginManagerImpl.java | 7 +- .../common/registry/RecipeManagerContextImpl.java | 59 ----- .../registry/displays/AbstractDisplayRegistry.java | 83 +++++++ .../registry/displays/DisplayConsumerImpl.java | 107 +++++++++ .../impl/common/registry/displays/DisplayKey.java | 60 +++++ .../common/registry/displays/DisplaysHolder.java | 49 ++++ .../registry/displays/DisplaysHolderImpl.java | 147 ++++++++++++ .../common/registry/displays/RemappingMap.java | 124 ++++++++++ .../displays/ServerDisplayRegistryImpl.java | 260 ++++++++++++++++++++ .../rei/impl/common/transfer/InputSlotCrafter.java | 45 ++-- .../common/transfer/LegacyInputSlotCrafter.java | 113 --------- .../impl/common/transfer/MenuInfoRegistryImpl.java | 151 ------------ .../impl/common/transfer/NewInputSlotCrafter.java | 4 +- .../common/transfer/SlotAccessorRegistryImpl.java | 4 +- .../rei/impl/common/util/InstanceHelper.java | 29 +-- .../me/shedaniel/rei/impl/init/PluginDetector.java | 2 - .../autocrafting/DefaultCategoryHandler.java | 193 --------------- .../plugin/client/entry/FluidEntryDefinition.java | 22 +- .../plugin/client/entry/ItemEntryDefinition.java | 41 ++-- .../client/runtime/DefaultClientRuntimePlugin.java | 37 ++- .../common/runtime/DefaultRuntimePlugin.java | 4 +- .../rei/plugin/test/REITestCommonPlugin.java | 62 +++++ .../shedaniel/rei/plugin/test/REITestPlugin.java | 36 --- .../roughlyenoughitems/textures/gui/button.png | Bin 7903 -> 0 bytes .../textures/gui/button_dark.png | Bin 5111 -> 0 bytes .../textures/gui/sprites/widget/button_dark.png | Bin 0 -> 2894 bytes .../gui/sprites/widget/button_dark.png.mcmeta | 10 + .../gui/sprites/widget/button_disabled_dark.png | Bin 0 -> 1823 bytes .../sprites/widget/button_disabled_dark.png.mcmeta | 10 + .../gui/sprites/widget/button_highlighted_dark.png | Bin 0 -> 2922 bytes .../widget/button_highlighted_dark.png.mcmeta | 10 + .../textures/gui/sprites/widget/panel_default.png | Bin 0 -> 559 bytes .../gui/sprites/widget/panel_default.png.mcmeta | 10 + .../gui/sprites/widget/panel_default_dark.png | Bin 0 -> 572 bytes .../sprites/widget/panel_default_dark.png.mcmeta | 10 + .../textures/gui/sprites/widget/panel_lighter.png | Bin 0 -> 536 bytes .../gui/sprites/widget/panel_lighter.png.mcmeta | 10 + .../gui/sprites/widget/panel_lighter_dark.png | Bin 0 -> 491 bytes .../sprites/widget/panel_lighter_dark.png.mcmeta | 10 + .../textures/gui/sprites/widget/panel_none.png | Bin 0 -> 274 bytes .../gui/sprites/widget/panel_none.png.mcmeta | 10 + .../gui/sprites/widget/panel_none_dark.png | Bin 0 -> 274 bytes .../gui/sprites/widget/panel_none_dark.png.mcmeta | 10 + .../textures/gui/sprites/widget/panel_slot.png | Bin 0 -> 419 bytes .../gui/sprites/widget/panel_slot.png.mcmeta | 10 + .../gui/sprites/widget/panel_slot_dark.png | Bin 0 -> 475 bytes .../gui/sprites/widget/panel_slot_dark.png.mcmeta | 10 + 128 files changed, 2070 insertions(+), 2080 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/SearchFilterSyntaxHighlightingScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayGeneratorsRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayKey.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolder.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplaysHolderImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/RemappingMap.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/networking/DisplaySyncPacket.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/RecipeManagerContextImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/AbstractDisplayRegistry.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/DisplayConsumerImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/DisplayKey.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/DisplaysHolder.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/DisplaysHolderImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/RemappingMap.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/registry/displays/ServerDisplayRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/transfer/LegacyInputSlotCrafter.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/common/transfer/MenuInfoRegistryImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/autocrafting/DefaultCategoryHandler.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/plugin/test/REITestCommonPlugin.java delete mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/button.png delete mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/button_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/button_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/button_dark.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/button_disabled_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/button_disabled_dark.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/button_highlighted_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/button_highlighted_dark.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_default.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_default.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_default_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_default_dark.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_lighter.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_lighter.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_lighter_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_lighter_dark.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_none.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_none.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_none_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_none_dark.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_slot.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_slot.png.mcmeta create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_slot_dark.png create mode 100644 runtime/src/main/resources/assets/roughlyenoughitems/textures/gui/sprites/widget/panel_slot_dark.png.mcmeta (limited to 'runtime/src') diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 8f4738fe9..0e771ac4b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -30,9 +30,7 @@ import dev.architectury.registry.ReloadListenerRegistry; import dev.architectury.utils.Env; import dev.architectury.utils.EnvExecutor; import me.shedaniel.rei.api.common.entry.type.EntryType; -import me.shedaniel.rei.api.common.plugins.PluginView; -import me.shedaniel.rei.api.common.plugins.REIPlugin; -import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.api.common.plugins.REICommonPlugin; import me.shedaniel.rei.impl.Internals; import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.category.CategoryIdentifierImpl; @@ -52,8 +50,7 @@ import me.shedaniel.rei.impl.common.logging.performance.PerformanceLoggerImpl; import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl; import me.shedaniel.rei.impl.common.plugins.ReloadInterruptionContext; import me.shedaniel.rei.impl.common.plugins.ReloadManagerImpl; -import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl; -import me.shedaniel.rei.impl.common.transfer.MenuInfoRegistryImpl; +import me.shedaniel.rei.impl.common.registry.displays.ServerDisplayRegistryImpl; import me.shedaniel.rei.impl.common.transfer.SlotAccessorRegistryImpl; import me.shedaniel.rei.impl.common.util.InstanceHelper; import me.shedaniel.rei.impl.init.PluginDetector; @@ -72,7 +69,6 @@ import java.util.ServiceLoader; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; -import java.util.function.UnaryOperator; @ApiStatus.Internal public class RoughlyEnoughItemsCore { @@ -134,31 +130,25 @@ public class RoughlyEnoughItemsCore { Internals.attachInstance(NbtHasherProviderImpl.INSTANCE, Internals.NbtHasherProvider.class); Internals.attachInstance(EntryIngredientImpl.INSTANCE, Internals.EntryIngredientProvider.class); Internals.attachInstanceSupplier(new PluginManagerImpl<>( - REIPlugin.class, - UnaryOperator.identity(), + REICommonPlugin.class, + new SlotAccessorRegistryImpl(), new EntryTypeRegistryImpl(), new EntrySettingsAdapterRegistryImpl(), - new RecipeManagerContextImpl<>(), new ItemComparatorRegistryImpl(), new FluidComparatorRegistryImpl(), new DisplaySerializerRegistryImpl(), + new ServerDisplayRegistryImpl(), new FluidSupportProviderImpl()), "commonPluginManager"); - Internals.attachInstanceSupplier(new PluginManagerImpl<>( - REIServerPlugin.class, - view -> view.then(PluginView.getInstance()), - new MenuInfoRegistryImpl(), - new SlotAccessorRegistryImpl()), "serverPluginManager"); } public void onInitialize() { PluginDetector detector = getPluginDetector(); detector.detectCommonPlugins(); - detector.detectServerPlugins(); RoughlyEnoughItemsNetwork.onInitialize(); if (Platform.getEnvironment() == Env.SERVER) { MutableLong lastReload = new MutableLong(-1); - ReloadListenerRegistry.register(PackType.SERVER_DATA, (preparationBarrier, resourceManager, profilerFiller, profilerFiller2, executor, executor2) -> { + ReloadListenerRegistry.register(PackType.SERVER_DATA, (preparationBarrier, resourceManager, executor, executor2) -> { return preparationBarrier.wait(Unit.INSTANCE).thenRunAsync(() -> { ReloadManagerImpl.reloadPlugins(null, ReloadInterruptionContext.ofNever()); }, executor2); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index f3e1f4ddf..8e6e00227 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -33,6 +33,7 @@ import dev.architectury.event.events.client.ClientPlayerEvent; import dev.architectury.event.events.client.ClientRecipeUpdateEvent; import dev.architectury.event.events.client.ClientScreenInputEvent; import dev.architectury.networking.NetworkManager; +import dev.architectury.networking.transformers.SplitPacketTransformer; import dev.architectury.utils.value.BooleanValue; import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; @@ -48,17 +49,19 @@ import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; import me.shedaniel.rei.api.client.registry.screen.ClickArea; import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.plugins.PluginView; -import me.shedaniel.rei.api.common.plugins.REIPlugin; +import me.shedaniel.rei.api.common.plugins.REICommonPlugin; import me.shedaniel.rei.api.common.registry.ReloadStage; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.ClientInternals; +import me.shedaniel.rei.impl.client.ClientHelperImpl; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; import me.shedaniel.rei.impl.client.config.addon.ConfigAddonRegistryImpl; @@ -86,10 +89,12 @@ import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.entry.type.EntryRegistryImpl; import me.shedaniel.rei.impl.common.entry.type.collapsed.CollapsibleEntryRegistryImpl; import me.shedaniel.rei.impl.common.entry.type.types.EmptyEntryDefinition; +import me.shedaniel.rei.impl.common.networking.DisplaySyncPacket; import me.shedaniel.rei.impl.common.plugins.PluginManagerImpl; import me.shedaniel.rei.impl.common.plugins.ReloadManagerImpl; import me.shedaniel.rei.impl.common.util.InstanceHelper; import me.shedaniel.rei.impl.common.util.IssuesDetector; +import me.shedaniel.rei.plugin.test.REITestCommonPlugin; import me.shedaniel.rei.plugin.test.REITestPlugin; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -100,36 +105,32 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.CraftingScreen; -import net.minecraft.client.gui.screens.recipebook.GhostRecipe; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.resources.language.I18n; import net.minecraft.core.RegistryAccess; import net.minecraft.data.models.blockstates.PropertyDispatch; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundRecipeBookAddPacket; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResult; -import net.minecraft.world.inventory.CraftingMenu; -import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.item.crafting.Ingredient; -import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.RecipeAccess; +import net.minecraft.world.item.crafting.display.RecipeDisplayEntry; +import net.minecraft.world.item.crafting.display.RecipeDisplayId; import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.ConcurrentModificationException; -import java.util.List; +import java.util.*; import java.util.function.*; import java.util.stream.Stream; @Environment(EnvType.CLIENT) public class RoughlyEnoughItemsCoreClient { - public static final Event> PRE_UPDATE_RECIPES = EventFactory.createLoop(); + public static final Event> PRE_UPDATE_RECIPES = EventFactory.createLoop(); public static final Event POST_UPDATE_TAGS = EventFactory.createLoop(); public static boolean isLeftMousePressed = false; @@ -209,7 +210,6 @@ public class RoughlyEnoughItemsCoreClient { ClientInternals.attachInstanceSupplier(new FilteringRuleTypeRegistryImpl(), "filteringRuleTypeRegistry"); ClientInternals.attachInstanceSupplier(new PluginManagerImpl<>( REIClientPlugin.class, - view -> view.then(PluginView.getInstance()), new EntryRendererRegistryImpl(), new ViewsImpl(), new InputMethodRegistryImpl(), @@ -246,7 +246,8 @@ public class RoughlyEnoughItemsCoreClient { NetworkManager.registerReceiver(NetworkManager.s2c(), RoughlyEnoughItemsNetwork.NOT_ENOUGH_ITEMS_PACKET, (buf, context) -> { Screen currentScreen = Minecraft.getInstance().screen; if (currentScreen instanceof CraftingScreen craftingScreen) { - RecipeBookComponent recipeBookGui = craftingScreen.getRecipeBookComponent(); + // TODO: Recipe Ghost + /*RecipeBookComponent recipeBookGui = craftingScreen.getRecipeBookComponent(); GhostRecipe ghostSlots = recipeBookGui.ghostRecipe; ghostSlots.clear(); @@ -269,14 +270,16 @@ public class RoughlyEnoughItemsCoreClient { Slot slot = container.getSlot(i + container.getResultSlotIndex() + 1); ghostSlots.addIngredient(Ingredient.of(stacks.toArray(new ItemStack[0])), slot.x, slot.y); } - } + }*/ } }); + NetworkManager.registerReceiver(NetworkManager.s2c(), DisplaySyncPacket.TYPE, DisplaySyncPacket.STREAM_CODEC, List.of(new SplitPacketTransformer()), DisplaySyncPacket::handle); } private void loadTestPlugins() { - if (System.getProperty("rei.test", "false").equals("true")) { + if (System.getProperty("rei.test", "false").equals("true") || true) { PluginView.getClientInstance().registerPlugin(new REITestPlugin()); + PluginView.getInstance().registerPlugin(new REITestCommonPlugin()); } } @@ -308,22 +311,42 @@ public class RoughlyEnoughItemsCoreClient { Minecraft client = Minecraft.getInstance(); final ResourceLocation recipeButtonTex = ResourceLocation.withDefaultNamespace("textures/gui/recipe_button.png"); MutableLong endReload = new MutableLong(-1); - PRE_UPDATE_RECIPES.register((recipeManager, registryAccess) -> { + PRE_UPDATE_RECIPES.register((recipeAccess, registryAccess) -> { reloadPlugins(null, ReloadStage.START, registryAccess); }); ClientRecipeUpdateEvent.EVENT.register(recipeManager -> { reloadPlugins(endReload, ReloadStage.END); }); + ClientRecipeUpdateEvent.ADD.register((recipeAccess, entries) -> { + if (ClientHelperImpl.getInstance().canUsePackets()) { + return; + } + + InternalLogger.getInstance().debug("Received server's request to add %d recipes.", entries.size()); + DisplayRegistryImpl registry = (DisplayRegistryImpl) DisplayRegistry.getInstance(); + List mapped = CollectionUtils.map(entries, ClientboundRecipeBookAddPacket.Entry::contents); + registry.addJob(() -> registry.addRecipes(mapped)); + }); + ClientRecipeUpdateEvent.REMOVE.register((recipeAccess, entries) -> { + if (ClientHelperImpl.getInstance().canUsePackets()) { + return; + } + + InternalLogger.getInstance().debug("Received server's request to remove %d recipes.", entries.size()); + DisplayRegistryImpl registry = (DisplayRegistryImpl) DisplayRegistry.getInstance(); + Set ids = new HashSet<>(entries); + registry.addJob(() -> registry.removeRecipes(ids)); + }); ClientPlayerEvent.CLIENT_PLAYER_QUIT.register(player -> { InternalLogger.getInstance().debug("Player quit, clearing reload tasks!"); endReload.setValue(-1); ReloadManagerImpl.terminateReloadTasks(); }); ClientGuiEvent.INIT_PRE.register((screen, access) -> { - List stages = ((PluginManagerImpl>) PluginManager.getInstance()).getObservedStages(); + List stages = ((PluginManagerImpl) PluginManager.getInstance()).getObservedStages(); if (Minecraft.getInstance().level != null && Minecraft.getInstance().player != null && stages.contains(ReloadStage.START) - && !stages.contains(ReloadStage.END) && !PluginManager.areAnyReloading() && screen instanceof AbstractContainerScreen) { + && !stages.contains(ReloadStage.END) && !PluginManager.areAnyReloading() && screen instanceof AbstractContainerScreen) { if (ReloadManagerImpl.countRunningReloadTasks() > 0) { return EventResult.pass(); } @@ -374,7 +397,7 @@ public class RoughlyEnoughItemsCoreClient { return EventResult.pass(); resetFocused(screen); if (REIRuntime.getInstance().isOverlayVisible() && getOverlay().mouseReleased(mouseX, mouseY, button) - && resetFocused(screen)) { + && resetFocused(screen)) { return EventResult.interruptFalse(); } return EventResult.pass(); @@ -384,7 +407,7 @@ public class RoughlyEnoughItemsCoreClient { return EventResult.pass(); resetFocused(screen); if (REIRuntime.getInstance().isOverlayVisible() && getOverlay().mouseScrolled(mouseX, mouseY, amountX, amountY) - && resetFocused(screen)) + && resetFocused(screen)) return EventResult.interruptFalse(); return EventResult.pass(); }); @@ -400,7 +423,7 @@ public class RoughlyEnoughItemsCoreClient { } resetFocused(screen); if (getOverlay().charTyped(character, keyCode) - && resetFocused(screen)) + && resetFocused(screen)) return EventResult.interruptFalse(); return EventResult.pass(); }); @@ -409,7 +432,7 @@ public class RoughlyEnoughItemsCoreClient { return EventResult.pass(); resetFocused(screen); if (getOverlay().mouseDragged(mouseX1, mouseY1, button, mouseX2, mouseY2) - && resetFocused(screen)) + && resetFocused(screen)) return EventResult.interruptFalse(); return EventResult.pass(); }); @@ -431,7 +454,7 @@ public class RoughlyEnoughItemsCoreClient { } resetFocused(screen); if (getOverlay().keyPressed(i, i1, i2) - && resetFocused(screen)) + && resetFocused(screen)) return EventResult.interruptFalse(); return EventResult.pass(); }); @@ -447,7 +470,7 @@ public class RoughlyEnoughItemsCoreClient { } resetFocused(screen); if (getOverlay().keyReleased(i, i1, i2) - && resetFocused(screen)) + && resetFocused(screen)) return EventResult.interruptFalse(); return EventResult.pass(); }); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 399850cf2..a1305b421 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -25,6 +25,8 @@ package me.shedaniel.rei; import dev.architectury.networking.NetworkManager; import dev.architectury.networking.transformers.SplitPacketTransformer; +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; import io.netty.buffer.Unpooled; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; @@ -34,14 +36,15 @@ import me.shedaniel.rei.api.common.entry.InputIngredient; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessorRegistry; +import me.shedaniel.rei.impl.common.networking.DisplaySyncPacket; import me.shedaniel.rei.impl.common.transfer.InputSlotCrafter; -import me.shedaniel.rei.impl.common.transfer.LegacyInputSlotCrafter; import me.shedaniel.rei.impl.common.transfer.NewInputSlotCrafter; import net.minecraft.ChatFormatting; +import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -57,7 +60,6 @@ import net.minecraft.world.item.ItemStack; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; public class RoughlyEnoughItemsNetwork { public static final ResourceLocation DELETE_ITEMS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "delete_item"); @@ -65,9 +67,9 @@ public class RoughlyEnoughItemsNetwork { public static final ResourceLocation CREATE_ITEMS_HOTBAR_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_hotbar"); public static final ResourceLocation CREATE_ITEMS_GRAB_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_grab"); public static final ResourceLocation CREATE_ITEMS_MESSAGE_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "ci_msg"); - public static final ResourceLocation MOVE_ITEMS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "move_items"); public static final ResourceLocation MOVE_ITEMS_NEW_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "move_items_new"); public static final ResourceLocation NOT_ENOUGH_ITEMS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "og_not_enough"); + public static final ResourceLocation SYNC_DISPLAYS_PACKET = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "sync_displays"); public static void onInitialize() { NetworkManager.registerReceiver(NetworkManager.c2s(), DELETE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (buf, context) -> { @@ -140,39 +142,6 @@ public class RoughlyEnoughItemsNetwork { player.displayClientMessage(Component.translatable("text.rei.failed_cheat_items"), false); } }); - NetworkManager.registerReceiver(NetworkManager.c2s(), MOVE_ITEMS_PACKET, Collections.singletonList(new SplitPacketTransformer()), (packetByteBuf, context) -> { - ServerPlayer player = (ServerPlayer) context.getPlayer(); - CategoryIdentifier category = CategoryIdentifier.of(packetByteBuf.readResourceLocation()); - AbstractContainerMenu container = player.containerMenu; - InventoryMenu playerContainer = player.inventoryMenu; - try { - boolean shift = packetByteBuf.readBoolean(); - try { - LegacyInputSlotCrafter crafter = LegacyInputSlotCrafter.start(category, container, player, packetByteBuf.readNbt(), shift); - } catch (InputSlotCrafter.NotEnoughMaterialsException e) { - if (!(container instanceof RecipeBookMenu)) { - return; - } - // TODO Implement Ghost Recipes - /*FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); - buf.writeInt(input.size()); - for (List stacks : input) { - buf.writeInt(stacks.size()); - for (ItemStack stack : stacks) { - buf.writeItem(stack); - } - } - NetworkManager.sendToPlayer(player, NOT_ENOUGH_ITEMS_PACKET, buf);*/ - } catch (IllegalStateException e) { - player.sendSystemMessage(Component.translatable(e.getMessage()).withStyle(ChatFormatting.RED)); - } catch (Exception e) { - player.sendSystemMessage(Component.translatable("error.rei.internal.error", e.getMessage()).withStyle(ChatFormatting.RED)); - e.printStackTrace(); - } - } catch (Exception e) { - e.printStackTrace(); - } - }); NetworkManager.registerReceiver(NetworkManager.c2s(), MOVE_ITEMS_NEW_PACKET, Collections.singletonList(new SplitPacketTransformer()), (packetByteBuf, context) -> { ServerPlayer player = (ServerPlayer) context.getPlayer(); CategoryIdentifier category = CategoryIdentifier.of(packetByteBuf.readResourceLocation()); @@ -184,7 +153,7 @@ public class RoughlyEnoughItemsNetwork { CompoundTag nbt = packetByteBuf.readNbt(); int version = nbt.getInt("Version"); if (version != 1) throw new IllegalStateException("Server and client REI protocol version mismatch! Server: 1, Client: " + version); - List> inputs = readInputs(nbt.getList("Inputs", Tag.TAG_COMPOUND)); + List> inputs = readInputs(context.registryAccess(), nbt.getList("Inputs", Tag.TAG_COMPOUND)); List input = readSlots(container, player, nbt.getList("InputSlots", Tag.TAG_COMPOUND)); List inventory = readSlots(container, player, nbt.getList("InventorySlots", Tag.TAG_COMPOUND)); NewInputSlotCrafter crafter = new NewInputSlotCrafter<>(container, input, inventory, inputs); @@ -203,6 +172,9 @@ public class RoughlyEnoughItemsNetwork { e.printStackTrace(); } }); + if (Platform.getEnvironment() == Env.SERVER) { + NetworkManager.registerS2CPayloadType(DisplaySyncPacket.TYPE, DisplaySyncPacket.STREAM_CODEC, List.of(new SplitPacketTransformer())); + } } private static List readSlots(AbstractContainerMenu menu, Player player, ListTag tag) { @@ -213,11 +185,11 @@ public class RoughlyEnoughItemsNetwork { return slots; } - private static List> readInputs(ListTag tag) { + private static List> readInputs(RegistryAccess registryAccess, ListTag tag) { List> inputs = new ArrayList<>(); for (Tag t : tag) { CompoundTag compoundTag = (CompoundTag) t; - InputIngredient> stacks = InputIngredient.of(compoundTag.getInt("Index"), EntryIngredient.read(compoundTag.getList("Ingredient", Tag.TAG_COMPOUND))); + InputIngredient> stacks = InputIngredient.of(compoundTag.getInt("Index"), EntryIngredient.codec().parse(registryAccess.createSerializationContext(NbtOps.INSTANCE), compoundTag.getList("Ingredient", Tag.TAG_COMPOUND)).getOrThrow()); inputs.add(InputIngredient.withType(stacks, VanillaEntryTypes.ITEM)); } return inputs; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 2a489e9f0..7591124f3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -368,7 +368,7 @@ public class ClientHelperImpl implements ClientHelper { @Override public boolean canUseMovePackets() { - return NetworkManager.canServerReceive(RoughlyEnoughItemsNetwork.MOVE_ITEMS_PACKET); + return NetworkManager.canServerReceive(RoughlyEnoughItemsNetwork.MOVE_ITEMS_NEW_PACKET); } public void onInitializeClient() { 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 af3720cec..d6cd1418d 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 @@ -26,6 +26,7 @@ package me.shedaniel.rei.impl.client.config; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.gui.ConfigScreenProvider; @@ -165,11 +166,11 @@ public class ConfigManagerImpl implements ConfigManager { } }); builder.registerDeserializer(Tag.class, EntryStackProvider.class, (value, marshaller) -> { - return EntryStackProvider.defer((CompoundTag) value); + return EntryStackProvider.defer(value); }); builder.registerDeserializer(String.class, EntryStackProvider.class, (value, marshaller) -> { try { - return EntryStackProvider.defer(TagParser.parseTag(value)); + return EntryStackProvider.defer(new TagParser(new StringReader(value)).readValue()); } catch (CommandSyntaxException e) { e.printStackTrace(); return EntryStackProvider.ofStack(EntryStack.empty()); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java index fdbc3166e..6b973084a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/addon/ConfigAddonsScreen.java @@ -35,6 +35,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; @@ -129,7 +130,7 @@ public class ConfigAddonsScreen extends Screen { @Override public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { super.renderWidget(graphics, mouseX, mouseY, delta); - graphics.blit(InternalTextures.CHEST_GUI_TEXTURE, getX() + 3, getY() + 3, 0, 0, 14, 14); + graphics.blit(RenderType::guiTextured, InternalTextures.CHEST_GUI_TEXTURE, getX() + 3, getY() + 3, 0, 0, 14, 14, 256, 256); } }; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigAddonsEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigAddonsEntry.java index 37b15dc14..4f159713d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigAddonsEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigAddonsEntry.java @@ -55,7 +55,7 @@ public class ConfigAddonsEntry extends AbstractConfigListEntry { super(Component.empty(), false); this.width = width; this.buttonWidget.setMessage(REIRuntime.getInstance().getPreviousContainerScreen() != null && Minecraft.getInstance().getConnection() != null - && Minecraft.getInstance().getConnection().getRecipeManager() != null ? Component.translatable("text.rei.addons") + && Minecraft.getInstance().getConnection().registryAccess() != null ? Component.translatable("text.rei.addons") : Component.translatable("config.roughlyenoughitems.filteredEntries.loadWorldFirst")); } @@ -78,7 +78,7 @@ public class ConfigAddonsEntry extends AbstractConfigListEntry { super.render(graphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); Window window = Minecraft.getInstance().getWindow(); this.buttonWidget.active = REIRuntime.getInstance().getPreviousContainerScreen() != null && Minecraft.getInstance().getConnection() != null - && Minecraft.getInstance().getConnection().getRecipeManager() != null && this.isEditable(); + && Minecraft.getInstance().getConnection().registryAccess() != null && this.isEditable(); this.buttonWidget.setY(y); this.buttonWidget.setX(x + entryWidth / 2 - width / 2); this.buttonWidget.setWidth(width); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java index c4ef56604..34b10136f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java @@ -45,6 +45,7 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; @@ -188,7 +189,7 @@ public class FilteringRulesScreen extends Screen { @Override public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) { super.renderWidget(graphics, mouseX, mouseY, delta); - graphics.blit(InternalTextures.CHEST_GUI_TEXTURE, getX() + 3, getY() + 3, 0, 0, 14, 14); + graphics.blit(RenderType::guiTextured, InternalTextures.CHEST_GUI_TEXTURE, getX() + 3, getY() + 3, 0, 0, 14, 14, 256, 256); } }; { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java index 0d3db41b0..442326252 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java @@ -26,9 +26,8 @@ package me.shedaniel.rei.impl.client.config.entries; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.VertexConsumer; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.api.scroll.ScrollingContainer; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -52,7 +51,7 @@ import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.world.item.Item; @@ -140,7 +139,7 @@ public class FilteringScreen extends Screen { FilteringListEntry entry = entries.get(i); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); if (entry.isSelected() && !entry.isFiltered()) { - configFiltered.add(stack); + configFiltered.add(stack); entry.dirty = true; } } @@ -155,7 +154,7 @@ public class FilteringScreen extends Screen { EntryStack stack = entryStacks.get(i); FilteringListEntry entry = entries.get(i); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); - if (entry.isSelected() && configFiltered.remove(stack)) { + if (entry.isSelected() && configFiltered.remove(stack)) { entry.dirty = true; } } @@ -219,7 +218,7 @@ public class FilteringScreen extends Screen { UpdatedListWidget.renderAs(minecraft, width, height, bounds.y, height, graphics, delta); if (bounds.isEmpty()) return; - ScissorsHandler.INSTANCE.scissor(bounds); + graphics.enableScissor(bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY()); for (FilteringListEntry entry : entries) entry.clearStacks(); int skip = Math.max(0, Mth.floor(scrolling.scrollAmount() / (float) entrySize())); @@ -238,7 +237,7 @@ public class FilteringScreen extends Screen { } manager.render(graphics, mouseX, mouseY, delta); updatePosition(delta); - scrolling.renderScrollBar(graphics, 0, 1.0F, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8F : 1F); + scrolling.renderScrollBar(graphics, 0, REIRuntime.getInstance().isDarkThemeEnabled() ? 0.8F : 1F); graphics.pose().pushPose(); graphics.pose().translate(0, 0, 300); this.searchField.render(graphics, mouseX, mouseY, delta); @@ -248,19 +247,15 @@ public class FilteringScreen extends Screen { this.showButton.render(graphics, mouseX, mouseY, delta); graphics.pose().popPose(); - ScissorsHandler.INSTANCE.removeLastScissor(); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR); - RenderSystem.enableBlend(); - RenderSystem.blendFuncSeparate(770, 771, 0, 1); - RenderSystem.setShader(GameRenderer::getPositionTexColorShader); - Matrix4f matrix = graphics.pose().last().pose(); - buffer.addVertex(matrix, 0, bounds.y + 4, 0.0F).setUv(0.0F, 1.0F).setColor(0, 0, 0, 0); - buffer.addVertex(matrix, width, bounds.y + 4, 0.0F).setUv(1.0F, 1.0F).setColor(0, 0, 0, 0); - buffer.addVertex(matrix, width, bounds.y, 0.0F).setUv(1.0F, 0.0F).setColor(0, 0, 0, 255); - buffer.addVertex(matrix, 0, bounds.y, 0.0F).setUv(0.0F, 0.0F).setColor(0, 0, 0, 255); - BufferUploader.drawWithShader(buffer.buildOrThrow()); - RenderSystem.disableBlend(); + graphics.disableScissor(); + graphics.drawSpecial(source -> { + Matrix4f matrix = graphics.pose().last().pose(); + VertexConsumer buffer = source.getBuffer(RenderType.gui()); + buffer.addVertex(matrix, 0, bounds.y + 4, 0.0F).setColor(0, 0, 0, 0); + buffer.addVertex(matrix, width, bounds.y + 4, 0.0F).setColor(0, 0, 0, 0); + buffer.addVertex(matrix, width, bounds.y, 0.0F).setColor(0, 0, 0, 255); + buffer.addVertex(matrix, 0, bounds.y, 0.0F).setColor(0, 0, 0, 255); + }); this.backButton.render(graphics, mouseX, mouseY, delta); @@ -322,7 +317,7 @@ public class FilteringScreen extends Screen { public boolean matches(EntryStack stack) { EntrySerializer serializer = stack.getDefinition().getSerializer(); - if (serializer == null || !serializer.supportReading() || !serializer.supportSaving()) { + if (serializer == null) { return false; } return lastFilter.test(stack); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/RecipeDisplayExporter.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/RecipeDisplayExporter.java index ceb346dea..9183eed9a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/RecipeDisplayExporter.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/RecipeDisplayExporter.java @@ -23,13 +23,13 @@ package me.shedaniel.rei.impl.client.gui; +import com.mojang.blaze3d.ProjectionType; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.pipeline.TextureTarget; import com.mojang.blaze3d.platform.Lighting; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.VertexSorting; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Widget; import me.shedaniel.rei.impl.client.gui.toast.ExportRecipeIdentifierToast; @@ -82,16 +82,16 @@ public final class RecipeDisplayExporter { private static void exportRecipe(Rectangle rectangle, DisplaySpec display, List widgets) { Minecraft client = Minecraft.getInstance(); Window window = client.getWindow(); - RenderTarget renderTarget = new TextureTarget(window.getWidth(), window.getHeight(), true, false); + RenderTarget renderTarget = new TextureTarget(window.getWidth(), window.getHeight(), true); + renderTarget.setClearColor(0, 0, 0, 0); renderTarget.bindWrite(true); - RenderSystem.clear(256, Minecraft.ON_OSX); + RenderSystem.clear(256); Matrix4f matrix4f = new Matrix4f().setOrtho(0.0F, (float) ((double) window.getWidth() / window.getGuiScale()), (float) ((double) window.getHeight() / window.getGuiScale()), 0.0F, 1000.0F, 3000.0F); - RenderSystem.setProjectionMatrix(matrix4f, VertexSorting.ORTHOGRAPHIC_Z); + RenderSystem.setProjectionMatrix(matrix4f, ProjectionType.ORTHOGRAPHIC); Matrix4fStack poseStack = RenderSystem.getModelViewStack(); poseStack.pushMatrix(); poseStack.identity(); poseStack.translate(0.0F, 0.0F, -2000.0F); - RenderSystem.applyModelViewMatrix(); Lighting.setupFor3DItems(); GuiGraphics graphics = new GuiGraphics(client, client.renderBuffers().bufferSource()); for (Widget widget : widgets) { @@ -107,7 +107,7 @@ public final class RecipeDisplayExporter { NativeImage strippedImage = new NativeImage(outWidth, outHeight, false); for (int y = 0; y < outHeight; ++y) { for (int x = 0; x < outWidth; ++x) { - strippedImage.setPixelRGBA(x, y, nativeImage.getPixelRGBA(x + (int) (rectangle.x * window.getGuiScale()), y + (int) (rectangle.y * window.getGuiScale()))); + strippedImage.setPixel(x, y, nativeImage.getPixel(x + (int) (rectangle.x * window.getGuiScale()), y + (int) (rectangle.y * window.getGuiScale()))); } } Util.ioPool().execute(() -> { @@ -124,9 +124,8 @@ public final class RecipeDisplayExporter { }); renderTarget.destroyBuffers(); - Minecraft.getInstance().levelRenderer.graphicsChanged(); + // Minecraft.getInstance().levelRenderer.graphicsChanged(); Minecraft.getInstance().getMainRenderTarget().bindWrite(true); poseStack.popMatrix(); - RenderSystem.applyModelViewMatrix(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java index 5abce4d44..af8ae2132 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/REIConfigScreen.java @@ -112,7 +112,7 @@ public class REIConfigScreen extends Screen implements ConfigAccess { } private void cleanRequiresLevel() { - if (!(REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null || Minecraft.getInstance().getConnection().getRecipeManager() == null)) { + if (!(REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null)) { return; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java index 30a12206b..3fc908a54 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigGroupWidget.java @@ -68,7 +68,7 @@ public class ConfigGroupWidget { WidgetWithBounds contents; if (applyPreview) { - applyPreview = REIRuntime.getInstance().getPreviousContainerScreen() != null && Minecraft.getInstance().getConnection() != null && Minecraft.getInstance().getConnection().getRecipeManager() != null; + applyPreview = REIRuntime.getInstance().getPreviousContainerScreen() != null && Minecraft.getInstance().getConnection() != null; } if (applyPreview && SPECIAL_GROUPS.containsKey(entry.getId())) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java index 265a78d72..efb37f455 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/components/ConfigOptionWidget.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.impl.client.gui.config.components; -import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.api.animator.NumberAnimator; import me.shedaniel.clothconfig2.api.animator.ValueAnimator; import me.shedaniel.math.Point; @@ -128,10 +127,11 @@ public class ConfigOptionWidget { this.previewLabel.render(graphics, mouseX, mouseY, delta); if (this.preview != null && this.previewHeight.value() > 0.1f) { - ScissorsHandler.INSTANCE.scissor(MatrixUtils.transform(graphics.pose().last().pose(), new Rectangle(0, 24 + 12 * split.size() - (nextLinePreview ? 0 : 12), width, this.previewHeight.value()))); + Rectangle rectangle = MatrixUtils.transform(graphics.pose().last().pose(), new Rectangle(0, 24 + 12 * split.size() - (nextLinePreview ? 0 : 12), width, this.previewHeight.value())); + graphics.enableScissor(rectangle.x, rectangle.y, rectangle.getMaxX(), rectangle.getMaxY()); this.previewTranslation = new Matrix4f().translate(0, 12 + 12 * split.size(), 100); this.preview.render(graphics, mouseX, mouseY, delta); - ScissorsHandler.INSTANCE.removeLastScissor(); + graphics.disableScissor(); } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java index 85a5fc640..e314ba4c0 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/InterfacePreviewer.java @@ -80,8 +80,8 @@ public class InterfacePreviewer { ((PanelWidget) panel).setDarkBackgroundAlpha(themeAlpha); }).rendering(panel -> { RecipeBorderType type = access.get(AllREIConfigOptions.RECIPE_BORDER); - panel.yTextureOffset(type.getYOffset()); - return type.isRendering(); + panel.texture(type); + return true; })); Point startingPoint = new Point(displayBounds.x + 6, displayBounds.y + 6); widgets.add(Util.make(Widgets.createArrow(new Point(startingPoint.x + 58, startingPoint.y + 18)), arrow -> { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreviewer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreviewer.java index c1234fe9d..daadcc968 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreviewer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/preview/TooltipPreviewer.java @@ -23,8 +23,7 @@ package me.shedaniel.rei.impl.client.gui.config.options.preview; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.VertexConsumer; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; @@ -37,7 +36,7 @@ import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigOptions; import me.shedaniel.rei.impl.client.gui.config.options.ConfigUtils; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.resources.language.I18n; import net.minecraft.util.FormattedCharSequence; import net.minecraft.world.item.ItemStack; @@ -78,24 +77,20 @@ public class TooltipPreviewer { stack.getRenderer().render(stack, graphics, new Rectangle(width / 2 - 12, 0, 24, 24), mouseX, mouseY, delta); graphics.pose().translate(0, 0, -400); - Tesselator tesselator = Tesselator.getInstance(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); - BufferBuilder bufferBuilder = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR); - Matrix4f matrix4f = graphics.pose().last().pose(); - fillGradient(matrix4f, bufferBuilder, tX - 3, tY - 4, tX + tWidth + 3, tY - 3, 400, -267386864, -267386864); - fillGradient(matrix4f, bufferBuilder, tX - 3, tY + tHeight + 3, tX + tWidth + 3, tY + tHeight + 4, 400, -267386864, -267386864); - fillGradient(matrix4f, bufferBuilder, tX - 3, tY - 3, tX + tWidth + 3, tY + tHeight + 3, 400, -267386864, -267386864); - fillGradient(matrix4f, bufferBuilder, tX - 4, tY - 3, tX - 3, tY + tHeight + 3, 400, -267386864, -267386864); - fillGradient(matrix4f, bufferBuilder, tX + tWidth + 3, tY - 3, tX + tWidth + 4, tY + tHeight + 3, 400, -267386864, -267386864); - fillGradient(matrix4f, bufferBuilder, tX - 3, tY - 3 + 1, tX - 3 + 1, tY + tHeight + 3 - 1, 400, 1347420415, 1344798847); - fillGradient(matrix4f, bufferBuilder, tX + tWidth + 2, tY - 3 + 1, tX + tWidth + 3, tY + tHeight + 3 - 1, 400, 1347420415, 1344798847); - fillGradient(matrix4f, bufferBuilder, tX - 3, tY - 3, tX + tWidth + 3, tY - 3 + 1, 400, 1347420415, 1347420415); - fillGradient(matrix4f, bufferBuilder, tX - 3, tY + tHeight + 2, tX + tWidth + 3, tY + tHeight + 3, 400, 1344798847, 1344798847); - RenderSystem.enableDepthTest(); - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - BufferUploader.drawWithShader(bufferBuilder.buildOrThrow()); - RenderSystem.disableBlend(); + int finalTY = tY; + graphics.drawSpecial(source -> { + VertexConsumer buffer = source.getBuffer(RenderType.gui()); + Matrix4f matrix4f = graphics.pose().last().pose(); + fillGradient(matrix4f, buffer, tX - 3, finalTY - 4, tX + tWidth + 3, finalTY - 3, 400, -267386864, -267386864); + fillGradient(matrix4f, buffer, tX - 3, finalTY + tHeight + 3, tX + tWidth + 3, finalTY + tHeight + 4, 400, -267386864, -267386864); + fillGradient(matrix4f, buffer, tX - 3, finalTY - 3, tX + tWidth + 3, finalTY + tHeight + 3, 400, -267386864, -267386864); + fillGradient(matrix4f, buffer, tX - 4, finalTY - 3, tX - 3, finalTY + tHeight + 3, 400, -267386864, -267386864); + fillGradient(matrix4f, buffer, tX + tWidth + 3, finalTY - 3, tX + tWidth + 4, finalTY + tHeight + 3, 400, -267386864, -267386864); + fillGradient(matrix4f, buffer, tX - 3, finalTY - 3 + 1, tX - 3 + 1, finalTY + tHeight + 3 - 1, 400, 1347420415, 1344798847); + fillGradient(matrix4f, buffer, tX + tWidth + 2, finalTY - 3 + 1, tX + tWidth + 3, finalTY + tHeight + 3 - 1, 400, 1347420415, 1344798847); + fillGradient(matrix4f, buffer, tX - 3, finalTY - 3, tX + tWidth + 3, finalTY - 3 + 1, 400, 1347420415, 1347420415); + fillGradient(matrix4f, buffer, tX - 3, finalTY + tHeight + 2, tX + tWidth + 3, finalTY + tHeight + 3, 400, 1344798847, 1344798847); + }); graphics.pose().translate(0, 0, 400); @@ -108,7 +103,7 @@ public class TooltipPreviewer { }), bounds); } - private static void fillGradient(Matrix4f pose, BufferBuilder builder, int x1, int y1, int x2, int y2, int blitOffset, int color1, int color2) { + private static void fillGradient(Matrix4f pose, VertexConsumer buffer, int x1, int y1, int x2, int