From 73dd8da0bdda912c7482b34fb0dc4f2d680005bc Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 5 Nov 2023 21:59:21 +0800 Subject: Fix cherrypick --- .../rei/plugin/client/DefaultClientPlugin.java | 14 +++++++------- .../crafting/filler/FireworkRocketRecipeFiller.java | 4 ++-- .../crafting/filler/MapExtendingRecipeFiller.java | 8 ++++---- .../filler/ShieldDecorationRecipeFiller.java | 5 +++-- .../crafting/filler/SuspiciousStewRecipeFiller.java | 4 ++-- .../config/entries/ConfigureCategoriesScreen.java | 10 +++++----- .../client/config/entries/FilteringRulesScreen.java | 2 +- .../filtering/rules/SearchFilteringRuleType.java | 2 +- .../rei/impl/client/gui/config/REIConfigScreen.java | 8 ++------ .../gui/config/options/AllREIConfigOptions.java | 3 +-- .../impl/client/gui/config/options/ConfigUtils.java | 9 ++++----- .../gui/config/options/preview/TooltipPreviewer.java | 12 +++++------- .../screen/collapsible/CollapsibleEntriesScreen.java | 20 +++++++++----------- .../screen/collapsible/CollapsibleEntryWidget.java | 20 +++++++++----------- .../CustomCollapsibleEntrySelectionScreen.java | 19 +++++++++---------- .../impl/client/gui/widget/ConfigButtonWidget.java | 2 +- .../gui/widget/CraftableFilterButtonWidget.java | 2 +- .../impl/client/gui/widget/TabContainerWidget.java | 4 ++-- .../type/collapsed/CollapsibleEntryRegistryImpl.java | 3 +-- .../client/runtime/DefaultClientRuntimePlugin.java | 6 ++---- 20 files changed, 71 insertions(+), 86 deletions(-) diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index 98fc53f73..239b95e2e 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -160,19 +160,19 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin @Override public void registerCollapsibleEntries(CollapsibleEntryRegistry registry) { - registry.group(new ResourceLocation("roughlyenoughitems", "enchanted_book"), new TranslatableComponent("item.minecraft.enchanted_book"), + registry.group(new ResourceLocation("roughlyenoughitems", "enchanted_book"), Component.translatable("item.minecraft.enchanted_book"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().is(Items.ENCHANTED_BOOK)); - registry.group(new ResourceLocation("roughlyenoughitems", "potion"), new TranslatableComponent("item.minecraft.potion"), + registry.group(new ResourceLocation("roughlyenoughitems", "potion"), Component.translatable("item.minecraft.potion"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().is(Items.POTION)); - registry.group(new ResourceLocation("roughlyenoughitems", "splash_potion"), new TranslatableComponent("item.minecraft.splash_potion"), + registry.group(new ResourceLocation("roughlyenoughitems", "splash_potion"), Component.translatable("item.minecraft.splash_potion"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().is(Items.SPLASH_POTION)); - registry.group(new ResourceLocation("roughlyenoughitems", "lingering_potion"), new TranslatableComponent("item.minecraft.lingering_potion"), + registry.group(new ResourceLocation("roughlyenoughitems", "lingering_potion"), Component.translatable("item.minecraft.lingering_potion"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().is(Items.LINGERING_POTION)); - registry.group(new ResourceLocation("roughlyenoughitems", "spawn_egg"), new TranslatableComponent("text.rei.spawn_egg"), + registry.group(new ResourceLocation("roughlyenoughitems", "spawn_egg"), Component.translatable("text.rei.spawn_egg"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().getItem() instanceof SpawnEggItem); - registry.group(new ResourceLocation("roughlyenoughitems", "tipped_arrow"), new TranslatableComponent("item.minecraft.tipped_arrow"), + registry.group(new ResourceLocation("roughlyenoughitems", "tipped_arrow"), Component.translatable("item.minecraft.tipped_arrow"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().is(Items.TIPPED_ARROW)); - registry.group(new ResourceLocation("roughlyenoughitems", "music_disc"), new TranslatableComponent("text.rei.music_disc"), + registry.group(new ResourceLocation("roughlyenoughitems", "music_disc"), Component.translatable("text.rei.music_disc"), stack -> stack.getType() == VanillaEntryTypes.ITEM && stack.castValue().getItem() instanceof RecordItem); } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java index 90357ca88..d4a689df1 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/FireworkRocketRecipeFiller.java @@ -31,7 +31,7 @@ import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay; import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.FireworkRocketRecipe; @@ -72,7 +72,7 @@ public class FireworkRocketRecipeFiller implements CraftingRecipeFiller { - widgets.add(createInfoWidget(bounds, display, new TranslatableComponent("text.rei.crafting.firework.gunpowder.amount"))); + widgets.add(createInfoWidget(bounds, display, Component.translatable("text.rei.crafting.firework.gunpowder.amount"))); }); } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/MapExtendingRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/MapExtendingRecipeFiller.java index 34a892e69..f5771ce5b 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/MapExtendingRecipeFiller.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/MapExtendingRecipeFiller.java @@ -30,7 +30,7 @@ import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomDisplay; import net.minecraft.ChatFormatting; import net.minecraft.client.resources.language.I18n; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.MapExtendingRecipe; @@ -75,9 +75,9 @@ public class MapExtendingRecipeFiller implements CraftingRecipeFiller[] allPatterns = Registry.BANNER_PATTERN.holders().toArray(Holder[]::new); for (int j = 0; j < 2; j++) { - BannerPattern pattern = allPatterns[random.nextInt(allPatterns.length - 1) + 1]; + Holder pattern = allPatterns[random.nextInt(allPatterns.length - 1) + 1]; patternBuilder.addPattern(pattern, colors[random.nextInt(colors.length)]); } ItemStack banner = new ItemStack(bannerOptional.get()); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/SuspiciousStewRecipeFiller.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/SuspiciousStewRecipeFiller.java index bfd82e763..fab4e4e70 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/SuspiciousStewRecipeFiller.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/crafting/filler/SuspiciousStewRecipeFiller.java @@ -27,7 +27,7 @@ import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomShapelessDisplay; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.tags.ItemTags; import net.minecraft.world.item.Items; import net.minecraft.world.item.crafting.SuspiciousStewRecipe; @@ -57,7 +57,7 @@ public class SuspiciousStewRecipeFiller implements CraftingRecipeFiller { - widgets.add(createInfoWidget(bounds, display, new TranslatableComponent("text.rei.crafting.suspicious_stew"))); + widgets.add(createInfoWidget(bounds, display, Component.translatable("text.rei.crafting.suspicious_stew"))); }); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigureCategoriesScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigureCategoriesScreen.java index 6818fa940..d922212e1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigureCategoriesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ConfigureCategoriesScreen.java @@ -55,7 +55,7 @@ public class ConfigureCategoriesScreen extends Screen { public Screen parent; public ConfigureCategoriesScreen(Map, Boolean> filteringQuickCraftCategories, Set> hiddenCategories, List> categoryOrdering) { - super(new TranslatableComponent("config.roughlyenoughitems.configureCategories.title")); + super(Component.translatable("config.roughlyenoughitems.configureCategories.title")); this.filteringQuickCraftCategories = filteringQuickCraftCategories; this.hiddenCategories = hiddenCategories; this.categoryOrdering = categoryOrdering; @@ -236,7 +236,7 @@ public class ConfigureCategoriesScreen extends Screen { }).leftAligned(); } { - this.upButton = new Button(0, 0, 20, 20, new TextComponent("↑"), button -> { + this.upButton = new Button(0, 0, 20, 20, Component.literal("↑"), button -> { int index = categoryOrdering.indexOf(configuration.getCategoryIdentifier()); if (index > 0) { categoryOrdering.remove(index); @@ -245,7 +245,7 @@ public class ConfigureCategoriesScreen extends Screen { resetListEntries(); } }); - this.downButton = new Button(0, 0, 20, 20, new TextComponent("↓"), button -> { + this.downButton = new Button(0, 0, 20, 20, Component.literal("↓"), button -> { int index = categoryOrdering.indexOf(configuration.getCategoryIdentifier()); if (index < categoryOrdering.size() - 1) { categoryOrdering.remove(index); @@ -294,14 +294,14 @@ public class ConfigureCategoriesScreen extends Screen { } boolean shown = !hiddenCategories.contains(configuration.getCategoryIdentifier()); { - Component subtitle = new TranslatableComponent("config.roughlyenoughitems.configureCategories.visibility." + shown) + Component subtitle = Component.translatable("config.roughlyenoughitems.configureCategories.visibility." + shown) .withStyle(shown ? ChatFormatting.GREEN : ChatFormatting.RED); int i = client.font.drawShadow(matrices, subtitle.getVisualOrderText(), xPos, y + 22, 8421504); visibilityToggleButton.getPoint().setLocation(i + 3, y + 22); visibilityToggleButton.render(matrices, mouseX, mouseY, delta); } if (shown) { - Component subtitle = new TranslatableComponent("config.roughlyenoughitems.filtering.filteringQuickCraftCategories.configure." + filteringQuickCraftCategories.getOrDefault(configuration.getCategoryIdentifier(), configuration.isQuickCraftingEnabledByDefault())) + Component subtitle = Component.translatable("config.roughlyenoughitems.filtering.filteringQuickCraftCategories.configure." + filteringQuickCraftCategories.getOrDefault(configuration.getCategoryIdentifier(), configuration.isQuickCraftingEnabledByDefault())) .withStyle(ChatFormatting.GRAY); int i = client.font.drawShadow(matrices, subtitle.getVisualOrderText(), xPos, y + 32, 8421504); quickCraftToggleButton.getPoint().setLocation(i + 3, y + 32); 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 b310bf51d..9fd0c8d99 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 @@ -269,7 +269,7 @@ public class FilteringRulesScreen extends Screen { private static Function placeholderScreen(FilteringRule r) { class PlaceholderScreen extends OptionEntriesScreen { public PlaceholderScreen(Screen parent) { - super(new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen"), parent); + super(Component.translatable("config.roughlyenoughitems.filteringRulesScreen"), parent); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java index b2fe82b92..2b535e627 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java @@ -88,7 +88,7 @@ public enum SearchFilteringRuleType implements FilteringRuleType createEntryScreen(SearchFilteringRule rule) { - return screen -> new OptionEntriesScreen(new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen"), screen) { + return screen -> new OptionEntriesScreen(Component.translatable("config.roughlyenoughitems.filteringRulesScreen"), screen) { TextFieldListEntry entry = null; BooleanListEntry show = null; List entryStacks = new ArrayList<>(); 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 3ff6caf20..768e8355a 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 @@ -43,16 +43,12 @@ import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.config.components.ConfigCategoriesListWidget; import me.shedaniel.rei.impl.client.gui.config.components.ConfigEntriesListWidget; -import me.shedaniel.rei.impl.client.gui.config.options.AllREIConfigCategories; -import me.shedaniel.rei.impl.client.gui.config.options.CompositeOption; -import me.shedaniel.rei.impl.client.gui.config.options.OptionCategory; -import me.shedaniel.rei.impl.client.gui.config.options.OptionGroup; +import me.shedaniel.rei.impl.client.gui.config.options.*; import me.shedaniel.rei.impl.client.gui.modules.Menu; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.TranslatableComponent; import org.apache.commons.lang3.mutable.Mutable; import org.apache.commons.lang3.mutable.MutableObject; import org.jetbrains.annotations.Nullable; @@ -83,7 +79,7 @@ public class REIConfigScreen extends Screen implements ConfigAccess { } public REIConfigScreen(Screen parent, List categories) { - super(new TranslatableComponent("config.roughlyenoughitems.title")); + super(ConfigUtils.translatable("config.roughlyenoughitems.title")); this.parent = parent; this.categories = CollectionUtils.map(categories, OptionCategory::copy); this.cleanRequiresLevel(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java index 0cc924884..3b621b5f5 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java @@ -43,7 +43,6 @@ import me.shedaniel.rei.impl.client.gui.screen.collapsible.CollapsibleEntriesScr import me.shedaniel.rei.impl.client.search.argument.Argument; import me.shedaniel.rei.impl.common.entry.type.collapsed.CollapsibleEntryRegistryImpl; import net.minecraft.client.Minecraft; -import net.minecraft.network.chat.TranslatableComponent; import java.util.ArrayList; import java.util.HashMap; @@ -256,7 +255,7 @@ public interface AllREIConfigOptions { throw new RuntimeException(e); } } - Minecraft.getInstance().setScreen(new ConfigReloadingScreen(new TranslatableComponent("text.rei.config.is.reloading"), PluginManager::areAnyReloading, onClose, null)); + Minecraft.getInstance().setScreen(new ConfigReloadingScreen(translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, onClose, null)); }).requiresLevel(); CompositeOption RELOAD_SEARCH = make("reset.reload_search", i -> null, (i, v) -> new Object()) .reload((access, option, onClose) -> { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java index 539be5526..c343c4e95 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ConfigUtils.java @@ -26,9 +26,8 @@ package me.shedaniel.rei.impl.client.gui.config.options; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen; import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; public interface ConfigUtils { static boolean isReducedMotion() { @@ -40,14 +39,14 @@ public interface ConfigUtils { } static MutableComponent literal(String text) { - return new TextComponent(text); + return Component.literal(text); } static MutableComponent translatable(String key) { - return new TranslatableComponent(key); + return Component.translatable(key); } static MutableComponent translatable(String key, Object... args) { - return new TranslatableComponent(key, args); + return Component.translatable(key, args); } } 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 9b2e86b1b..ad5e74d27 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 @@ -35,12 +35,11 @@ import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.impl.client.gui.config.ConfigAccess; 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.resources.language.I18n; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.FormattedCharSequence; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -59,14 +58,14 @@ public class TooltipPreviewer { boolean appendModNames = access.get(AllREIConfigOptions.APPEND_MOD_NAMES); boolean appendFavorites = access.get(AllREIConfigOptions.APPEND_FAVORITES_HINT); List entries = new ArrayList<>(); - entries.add(Tooltip.entry(new TranslatableComponent("block.minecraft.oak_planks"))); + entries.add(Tooltip.entry(ConfigUtils.translatable("block.minecraft.oak_planks"))); if (appendModNames) { - entries.add(Tooltip.entry(new TextComponent("Minecraft").withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC))); + entries.add(Tooltip.entry(ConfigUtils.literal("Minecraft").withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC))); } if (appendFavorites) { String name = ConfigObject.getInstance().getFavoriteKeyCode().getLocalizedName().getString(); entries.addAll(Stream.of(I18n.get("text.rei.favorites_tooltip", name).split("\n")) - .map(TextComponent::new).map(Tooltip::entry).toList()); + .map(ConfigUtils::literal).map(Tooltip::entry).toList()); } List components = entries.stream().flatMap(entry -> Minecraft.getInstance().font.split(entry.getAsText(), width - 12 - 4).stream()).toList(); int minWidth = components.stream().mapToInt(component -> Minecraft.getInstance().font.width(component)).max().orElse(0) + 4; @@ -97,8 +96,7 @@ public class TooltipPreviewer { RenderSystem.disableTexture(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - bufferBuilder.end(); - BufferUploader.end(bufferBuilder); + BufferUploader.drawWithShader(bufferBuilder.end()); RenderSystem.disableBlend(); RenderSystem.enableTexture(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntriesScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntriesScreen.java index 1c6d86062..21ec75301 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntriesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntriesScreen.java @@ -54,8 +54,6 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import java.util.*; @@ -69,7 +67,7 @@ public class CollapsibleEntriesScreen extends Screen { private boolean dirty = true; public CollapsibleEntriesScreen(Runnable onClose, CollapsibleConfigManager.CollapsibleConfigObject configObject) { - super(new TranslatableComponent("text.rei.collapsible.entries.title")); + super(Component.translatable("text.rei.collapsible.entries.title")); this.onClose = onClose; this.configObject = configObject; this.prepareWidgets(configObject); @@ -79,7 +77,7 @@ public class CollapsibleEntriesScreen extends Screen { this.widgets.clear(); for (CollapsibleConfigManager.CustomGroup customEntry : configObject.customGroups) { - this.widgets.add(new CollapsibleEntryWidget(true, customEntry.id, new TextComponent(customEntry.name), + this.widgets.add(new CollapsibleEntryWidget(true, customEntry.id, Component.literal(customEntry.name), CollectionUtils.filterAndMap(customEntry.stacks, EntryStackProvider::isValid, EntryStackProvider::provide), configObject, () -> { this.prepareWidgets(configObject); @@ -110,12 +108,12 @@ public class CollapsibleEntriesScreen extends Screen { public void init() { super.init(); { - Component backText = new TextComponent("↩ ").append(new TranslatableComponent("gui.back")); + Component backText = Component.literal("↩ ").append(Component.translatable("gui.back")); addRenderableWidget(new Button(4, 4, font.width(backText) + 10, 20, backText, button -> this.onClose())); } { - Component addText = new TextComponent(" + "); + Component addText = Component.literal(" + "); addRenderableWidget(new Button(width - 4 - 20, 4, 20, 20, addText, $ -> { setupCustom(new ResourceLocation("custom:" + UUID.randomUUID()), "", new ArrayList<>(), this.configObject, () -> { this.prepareWidgets(configObject); @@ -130,23 +128,23 @@ public class CollapsibleEntriesScreen extends Screen { } public static void setupCustom(ResourceLocation id, String name, List> stacks, CollapsibleConfigManager.CollapsibleConfigObject configObject, Runnable markDirty) { - Minecraft.getInstance().setScreen(new OptionEntriesScreen(new TranslatableComponent("text.rei.collapsible.entries.custom.title"), Minecraft.getInstance().screen) { + Minecraft.getInstance().setScreen(new OptionEntriesScreen(Component.translatable("text.rei.collapsible.entries.custom.title"), Minecraft.getInstance().screen) { private TextFieldListEntry entry; @Override public void addEntries(Consumer entryConsumer) { addEmpty(entryConsumer, 10); - addText(entryConsumer, new TranslatableComponent("text.rei.collapsible.entries.custom.id").withStyle(ChatFormatting.GRAY) - .append(new TextComponent(" " + id).withStyle(ChatFormatting.DARK_GRAY))); + addText(entryConsumer, Component.translatable("text.rei.collapsible.entries.custom.id").withStyle(ChatFormatting.GRAY) + .append(Component.literal(" " + id).withStyle(ChatFormatting.DARK_GRAY))); addEmpty(entryConsumer, 10); - addText(entryConsumer, new TranslatableComponent("text.rei.collapsible.entries.custom.name").withStyle(ChatFormatting.GRAY)); + addText(entryConsumer, Component.translatable("text.rei.collapsible.entries.custom.name").withStyle(ChatFormatting.GRAY)); entryConsumer.accept(this.entry = new TextFieldListEntry(width - 36, widget -> { widget.setMaxLength(40); if (this.entry != null) widget.setValue(this.entry.getWidget().getValue()); else widget.setValue(name); })); addEmpty(entryConsumer, 10); - entryConsumer.accept(new ButtonListEntry(width - 36, $ -> new TranslatableComponent("text.rei.collapsible.entries.custom.select"), ($, button) -> { + entryConsumer.accept(new ButtonListEntry(width - 36, $ -> Component.translatable("text.rei.collapsible.entries.custom.select"), ($, button) -> { CustomCollapsibleEntrySelectionScreen screen = new CustomCollapsibleEntrySelectionScreen(stacks); screen.parent = this.minecraft.screen; this.minecraft.setScreen(screen); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntryWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntryWidget.java index 90f6a617a..574a3d7a3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntryWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/CollapsibleEntryWidget.java @@ -50,8 +50,6 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; @@ -100,7 +98,7 @@ public class CollapsibleEntryWidget extends WidgetWithBounds { this.stacks = CollectionUtils.map(stacks, stack -> Widgets.createSlot(new Rectangle(0, 0, 16, 16)) .entry(stack).disableBackground()); this.configObject = configObject; - this.toggleButton = new Button(0, 0, 20, 20, new TranslatableComponent("text.rei.collapsible.entries.toggle"), button -> { + this.toggleButton = new Button(0, 0, 20, 20, Component.translatable("text.rei.collapsible.entries.toggle"), button -> { if (this.configObject.disabledGroups.contains(this.id)) { this.configObject.disabledGroups.remove(this.id); } else { @@ -109,7 +107,7 @@ public class CollapsibleEntryWidget extends WidgetWithBounds { }); this.toggleButton.setWidth(this.font.width(toggleButton.getMessage()) + 8); if (this.custom) { - this.deleteButton = new Button(0, 0, 20, 20, new TranslatableComponent("text.rei.collapsible.entries.delete"), button -> { + this.deleteButton = new Button(0, 0, 20, 20, Component.translatable("text.rei.collapsible.entries.delete"), button -> { this.configObject.customGroups.removeIf(customEntry -> customEntry.id.equals(this.id)); markDirty.run(); }); @@ -171,11 +169,11 @@ public class CollapsibleEntryWidget extends WidgetWithBounds { try (CloseableScissors scissors = scissor(poses, lineBounds)) { poses.pushPose(); poses.translate(0, -idDrawer.progress() * 10, 0); - font.drawShadow(poses, new TranslatableComponent("text.rei.collapsible.entries.count", this.stacks.size() + ""), bounds.x + 4, y, 0xFFAAAAAA); + font.drawShadow(poses, Component.translatable("text.rei.collapsible.entries.count", this.stacks.size() + ""), bounds.x + 4, y, 0xFFAAAAAA); boolean enabled = !this.configObject.disabledGroups.contains(this.id); - Component sideText = new TranslatableComponent("text.rei.collapsible.entries.enabled." + enabled); + Component sideText = Component.translatable("text.rei.collapsible.entries.enabled." + enabled); font.drawShadow(poses, sideText, bounds.getMaxX() - 4 - font.width(sideText), y, enabled ? 0xDD55FF55 : 0xDDFF5555); - renderTextScrolling(poses, new TextComponent(this.id.toString()), bounds.x + 4, y + 10, bounds.width - 8, 0xFF777777); + renderTextScrolling(poses, Component.literal(this.id.toString()), bounds.x + 4, y + 10, bounds.width - 8, 0xFF777777); poses.popPose(); } } @@ -183,15 +181,15 @@ public class CollapsibleEntryWidget extends WidgetWithBounds { if (y + 9 >= 30 && y < minecraft.screen.height) { Rectangle lineBounds = new Rectangle(bounds.x + 4, y, bounds.width - 8, 9); modIdDrawer.setTo(lineBounds.contains(mouseX, mouseY), ConfigObject.getInstance().isReducedMotion() ? 0 : 400); - int xo = font.drawShadow(poses, new TranslatableComponent("text.rei.collapsible.entries.source").append(" "), bounds.x + 4, y, 0xFFAAAAAA); + int xo = font.drawShadow(poses, Component.translatable("text.rei.collapsible.entries.source").append(" "), bounds.x + 4, y, 0xFFAAAAAA); try (CloseableScissors scissors = scissor(poses, lineBounds)) { poses.pushPose(); if (this.custom) { - renderTextScrolling(poses, TextTransformations.applyRainbow(new TranslatableComponent("text.rei.collapsible.entries.source.custom").getVisualOrderText(), xo - 1, y), xo - 1, y, bounds.getWidth() - 8, 0xFFAAAAAA); + renderTextScrolling(poses, TextTransformations.applyRainbow(Component.translatable("text.rei.collapsible.entries.source.custom").getVisualOrderText(), xo - 1, y), xo - 1, y, bounds.getWidth() - 8, 0xFFAAAAAA); } else { poses.translate(0, -modIdDrawer.progress() * 10, 0); - renderTextScrolling(poses, new TextComponent(ClientHelper.getInstance().getModFromModId(this.id.getNamespace())), xo - 1, y, bounds.getMaxX() - 4 - (xo - 1), 0xFF777777); - renderTextScrolling(poses, new TextComponent(this.id.getNamespace().toString()), xo - 1, y + 10, bounds.getMaxX() - 4 - (xo - 1), 0xFF777777); + renderTextScrolling(poses, Component.literal(ClientHelper.getInstance().getModFromModId(this.id.getNamespace())), xo - 1, y, bounds.getMaxX() - 4 - (xo - 1), 0xFF777777); + renderTextScrolling(poses, Component.literal(this.id.getNamespace().toString()), xo - 1, y + 10, bounds.getMaxX() - 4 - (xo - 1), 0xFF777777); } poses.popPose(); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/selection/CustomCollapsibleEntrySelectionScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/selection/CustomCollapsibleEntrySelectionScreen.java index 8c41d1a8a..11a2d12ed 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/selection/CustomCollapsibleEntrySelectionScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/collapsible/selection/CustomCollapsibleEntrySelectionScreen.java @@ -36,6 +36,7 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.gui.widgets.TooltipContext; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; @@ -52,8 +53,6 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -109,24 +108,24 @@ public class CustomCollapsibleEntrySelectionScreen extends Screen { private SearchFilter lastFilter = SearchFilter.matchAll(); public CustomCollapsibleEntrySelectionScreen(List> selectedStacks) { - super(new TranslatableComponent("text.rei.collapsible.entries.custom.title")); + super(Component.translatable("text.rei.collapsible.entries.custom.title")); this.selectedStacks = selectedStacks; this.searchField = new OverlaySearchField(0, 0, 0, 0); { - Component selectAllText = new TranslatableComponent("config.roughlyenoughitems.filteredEntries.selectAll"); + Component selectAllText = Component.translatable("config.roughlyenoughitems.filteredEntries.selectAll"); this.selectAllButton = new Button(0, 0, Minecraft.getInstance().font.width(selectAllText) + 10, 20, selectAllText, button -> { this.points.clear(); this.points.add(new PointPair(new Point(-Integer.MAX_VALUE / 2, -Integer.MAX_VALUE / 2), new Point(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2))); }); } { - Component selectNoneText = new TranslatableComponent("config.roughlyenoughitems.filteredEntries.selectNone"); + Component selectNoneText = Component.translatable("config.roughlyenoughitems.filteredEntries.selectNone"); this.selectNoneButton = new Button(0, 0, Minecraft.getInstance().font.width(selectNoneText) + 10, 20, selectNoneText, button -> { this.points.clear(); }); } { - Component addText = new TranslatableComponent("text.rei.collapsible.entries.custom.select.add"); + Component addText = Component.translatable("text.rei.collapsible.entries.custom.select.add"); this.addButton = new Button(0, 0, Minecraft.getInstance().font.width(addText) + 10, 20, addText, button -> { for (int i = 0; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); @@ -140,7 +139,7 @@ public class CustomCollapsibleEntrySelectionScreen extends Screen { }); } { - Component removeText = new TranslatableComponent("text.rei.collapsible.entries.custom.select.remove"); + Component removeText = Component.translatable("text.rei.collapsible.entries.custom.select.remove"); this.removeButton = new Button(0, 0, Minecraft.getInstance().font.width(removeText) + 10, 20, removeText, button -> { for (int i = 0; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); @@ -153,7 +152,7 @@ public class CustomCollapsibleEntrySelectionScreen extends Screen { }); } { - Component backText = new TextComponent("↩ ").append(new TranslatableComponent("gui.back")); + Component backText = Component.literal("↩ ").append(Component.translatable("gui.back")); this.backButton = new Button(0, 0, Minecraft.getInstance().font.width(backText) + 10, 20, backText, button -> { minecraft.setScreen(parent); this.parent = null; @@ -275,7 +274,7 @@ public class CustomCollapsibleEntrySelectionScreen extends Screen { } this.font.drawShadow(poses, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); - Component hint = new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen.hint").withStyle(ChatFormatting.YELLOW); + Component hint = Component.translatable("config.roughlyenoughitems.filteringRulesScreen.hint").withStyle(ChatFormatting.YELLOW); this.font.drawShadow(poses, hint, this.width - this.font.width(hint) - 15, 12.0F, -1); } @@ -520,7 +519,7 @@ public class CustomCollapsibleEntrySelectionScreen extends Screen { protected void queueTooltip(PoseStack matrices, int mouseX, int mouseY, float delta) { if (searchField.containsMouse(mouseX, mouseY)) return; - Tooltip tooltip = getCurrentTooltip(new Point(mouseX, mouseY)); + Tooltip tooltip = getCurrentTooltip(TooltipContext.of(new Point(mouseX, mouseY))); if (tooltip != null) { CustomCollapsibleEntrySelectionScreen.this.tooltip = tooltip; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ConfigButtonWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ConfigButtonWidget.java index 53cf7aca2..5c12cb5cd 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ConfigButtonWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/ConfigButtonWidget.java @@ -123,7 +123,7 @@ public class ConfigButtonWidget { return false; } ), - ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.reduced_motion"), + ToggleMenuEntry.of(Component.translatable("text.rei.config.menu.reduced_motion"), config::isReducedMotion, config::setReducedMotion ), diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java index d9e3f2531..e0b4030f6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/CraftableFilterButtonWidget.java @@ -114,7 +114,7 @@ public class CraftableFilterButtonWidget { entries.add(new SubMenuEntry(Component.translatable("text.rei.config.menu.search_field.input_method"), createInputMethodEntries(access, applicableInputMethods))); } - entries.add(ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.search_field.hide_entry_panel_idle"), + entries.add(ToggleMenuEntry.of(Component.translatable("text.rei.config.menu.search_field.hide_entry_panel_idle"), config::isHidingEntryPanelIfIdle, hideEntryPanelIfIdle -> { config.setHidingEntryPanelIfIdle(hideEntryPanelIfIdle); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java index 9103e1130..2277d6c44 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java @@ -207,10 +207,10 @@ public class TabContainerWidget extends GuiComponent { Runnable leftAction, Runnable rightAction) { List widgets = new ArrayList<>(); Button tabLeft, tabRight; - widgets.add(tabLeft = Widgets.createButton(new Rectangle(bounds.x, bounds.getMaxY() - tabSize + 1 - tabButtonsSize, tabButtonsSize, tabButtonsSize), new TextComponent("")) + widgets.add(tabLeft = Widgets.createButton(new Rectangle(bounds.x, bounds.getMaxY() - tabSize + 1 - tabButtonsSize, tabButtonsSize, tabButtonsSize), Component.literal("")) .onClick(button -> leftAction.run()) .tooltipLine(Component.translatable("text.rei.previous_page"))); - widgets.add(tabRight = Widgets.createButton(new Rectangle(bounds.x + bounds.width - tabButtonsSize - (isCompactTabButtons ? 0 : 1), bounds.getMaxY() - tabSize + 1 - tabButtonsSize, tabButtonsSize, tabButtonsSize), new TextComponent("")) + widgets.add(tabRight = Widgets.createButton(new Rectangle(bounds.x + bounds.width - tabButtonsSize - (isCompactTabButtons ? 0 : 1), bounds.getMaxY() - tabSize + 1 - tabButtonsSize, tabButtonsSize, tabButtonsSize), Component.literal("")) .onClick(button -> rightAction.run()) .tooltipLine(Component.translatable("text.rei.next_page"))); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java index f16d8d390..8256b7c6c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/type/collapsed/CollapsibleEntryRegistryImpl.java @@ -32,7 +32,6 @@ import me.shedaniel.rei.impl.client.config.collapsible.CollapsibleConfigManager; import me.shedaniel.rei.impl.common.InternalLogger; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import java.util.*; @@ -89,7 +88,7 @@ public class CollapsibleEntryRegistryImpl implements CollapsibleEntryRegistry { this.customEntries.clear(); for (CollapsibleConfigManager.CustomGroup customEntry : CollapsibleConfigManager.getInstance().getConfig().customGroups) { List stacks = CollectionUtils.filterAndMap(customEntry.stacks, EntryStackProvider::isValid, provider -> new HashedEntryStackWrapper(provider.provide())); - Entry entry = new Entry(customEntry.id, new TextComponent(customEntry.name), + Entry entry = new Entry(customEntry.id, Component.literal(customEntry.name), new ListMatcher(stacks), false); this.customEntries.add(entry); InternalLogger.getInstance().debug("Added custom collapsible entry group [%s] %s with %d entries", entry.getId(), entry.getName().getString(), stacks.size()); 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 06814a172..babe2c38b 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 @@ -83,10 +83,8 @@ import net.fabricmc.api.Environment; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -387,8 +385,8 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { @Nullable public Tooltip getTooltip(TooltipContext context) { Tooltip tooltip = Tooltip.create(context.getPoint()); - tooltip.add((ClientTooltipComponent) tooltipComponent.get()); - tooltip.add(new TranslatableComponent("text.auto_craft.move_items.tooltip").withStyle(ChatFormatting.YELLOW)); + tooltip.add(tooltipComponent.get()); + tooltip.add(Component.translatable("text.auto_craft.move_items.tooltip").withStyle(ChatFormatting.YELLOW)); return tooltip; } }; -- cgit