From 3ab6f974fb63b9f9232f8507e156cfc53cdf0250 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 6 Feb 2020 11:55:23 +0800 Subject: 4.0-unstable Signed-off-by: shedaniel --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 26 ++-- .../me/shedaniel/rei/api/AutoTransferHandler.java | 12 +- .../me/shedaniel/rei/api/BaseBoundsHandler.java | 33 +---- .../java/me/shedaniel/rei/api/ConfigManager.java | 12 -- .../java/me/shedaniel/rei/api/ConfigObject.java | 19 +-- .../java/me/shedaniel/rei/api/DisplayHelper.java | 31 ---- .../java/me/shedaniel/rei/api/EntryRegistry.java | 2 +- src/main/java/me/shedaniel/rei/api/EntryStack.java | 6 - .../java/me/shedaniel/rei/api/ObjectHolder.java | 54 ------- .../java/me/shedaniel/rei/api/REIPluginEntry.java | 3 +- .../java/me/shedaniel/rei/api/RecipeCategory.java | 12 -- .../java/me/shedaniel/rei/api/RecipeHelper.java | 20 +-- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 73 +++------- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 7 +- .../shedaniel/rei/gui/RecipeDisplayExporter.java | 1 + .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 157 +++++++-------------- .../rei/gui/VillagerRecipeViewingScreen.java | 33 ++--- .../shedaniel/rei/gui/credits/CreditsScreen.java | 8 +- .../rei/gui/widget/AutoCraftingButtonWidget.java | 7 +- .../me/shedaniel/rei/gui/widget/ButtonWidget.java | 54 +++++-- .../gui/widget/ClickableActionedLabelWidget.java | 26 ---- .../rei/gui/widget/ClickableLabelWidget.java | 24 +--- .../gui/widget/CraftableToggleButtonWidget.java | 3 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 5 +- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 14 +- .../rei/gui/widget/LateRenderedButton.java | 4 - .../rei/gui/widget/RecipeChoosePageWidget.java | 14 +- .../rei/gui/widget/ReloadConfigButtonWidget.java | 16 --- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 17 ++- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 5 - .../me/shedaniel/rei/impl/DisplayHelperImpl.java | 3 +- .../me/shedaniel/rei/impl/EmptyEntryStack.java | 2 +- .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 1 + .../me/shedaniel/rei/impl/ObjectHolderImpl.java | 23 --- .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 25 +--- .../java/me/shedaniel/rei/impl/ScreenHelper.java | 18 +-- .../java/me/shedaniel/rei/impl/SearchArgument.java | 8 +- .../rei/listeners/ContainerScreenHooks.java | 4 +- .../rei/plugin/DefaultAutoCraftingPlugin.java | 7 - .../me/shedaniel/rei/plugin/DefaultPlugin.java | 15 +- .../autocrafting/DefaultCategoryHandler.java | 4 +- .../plugin/crafting/DefaultCraftingCategory.java | 5 - .../rei/plugin/crafting/DefaultCustomDisplay.java | 9 +- 43 files changed, 227 insertions(+), 595 deletions(-) delete mode 100644 src/main/java/me/shedaniel/rei/api/ObjectHolder.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/ClickableActionedLabelWidget.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/ReloadConfigButtonWidget.java delete mode 100644 src/main/java/me/shedaniel/rei/impl/ObjectHolderImpl.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index c81beb237..f007f5008 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -22,7 +22,7 @@ import net.fabricmc.loader.api.ModContainer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.client.gui.screen.ingame.CraftingTableScreen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; @@ -90,9 +90,8 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { * * @param plugin the plugin instance * @return the plugin itself - * @deprecated Check REI wiki */ - @Deprecated + @ApiStatus.Internal public static REIPluginEntry registerPlugin(REIPluginEntry plugin) { plugins.put(plugin.getPluginIdentifier(), plugin); RoughlyEnoughItemsCore.LOGGER.debug("[REI] Registered plugin %s from %s", plugin.getPluginIdentifier().toString(), plugin.getClass().getSimpleName()); @@ -226,22 +225,21 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } } - @SuppressWarnings("deprecation") private void registerClothEvents() { final Identifier recipeButtonTex = new Identifier("textures/gui/recipe_button.png"); AtomicLong lastSync = new AtomicLong(-1); ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> syncRecipes(lastSync)); ClothClientHooks.SCREEN_ADD_BUTTON.register((minecraftClient, screen, abstractButtonWidget) -> { - if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof AbstractContainerScreen && abstractButtonWidget instanceof TexturedButtonWidget) + if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof ContainerScreen && abstractButtonWidget instanceof TexturedButtonWidget) if (((RecipeBookButtonWidgetHooks) abstractButtonWidget).rei_getTexture().equals(recipeButtonTex)) return ActionResult.FAIL; return ActionResult.PASS; }); ClothClientHooks.SCREEN_INIT_POST.register((minecraftClient, screen, screenHooks) -> { - if (screen instanceof AbstractContainerScreen) { + if (screen instanceof ContainerScreen) { if (screen instanceof InventoryScreen && minecraftClient.interactionManager.hasCreativeInventory()) return; - ScreenHelper.setLastContainerScreen((AbstractContainerScreen) screen); + ScreenHelper.setLastContainerScreen((ContainerScreen) screen); boolean alreadyAdded = false; for (Element element : Lists.newArrayList(screenHooks.cloth_getInputListeners())) if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) @@ -254,11 +252,11 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } }); ClothClientHooks.SCREEN_RENDER_POST.register((minecraftClient, screen, i, i1, v) -> { - if (screen instanceof AbstractContainerScreen) + if (screen instanceof ContainerScreen) ScreenHelper.getLastOverlay().render(i, i1, v); }); ClothClientHooks.SCREEN_MOUSE_DRAGGED.register((minecraftClient, screen, v, v1, i, v2, v3) -> { - if (screen instanceof AbstractContainerScreen) + if (screen instanceof ContainerScreen) if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseDragged(v, v1, i, v2, v3)) return ActionResult.SUCCESS; return ActionResult.PASS; @@ -274,13 +272,13 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ActionResult.PASS; }); ClothClientHooks.SCREEN_MOUSE_SCROLLED.register((minecraftClient, screen, v, v1, v2) -> { - if (screen instanceof AbstractContainerScreen) + if (screen instanceof ContainerScreen) if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseScrolled(v, v1, v2)) return ActionResult.SUCCESS; return ActionResult.PASS; }); ClothClientHooks.SCREEN_CHAR_TYPED.register((minecraftClient, screen, character, keyCode) -> { - if (screen instanceof AbstractContainerScreen) + if (screen instanceof ContainerScreen) if (ScreenHelper.getLastOverlay().charTyped(character, keyCode)) return ActionResult.SUCCESS; return ActionResult.PASS; @@ -288,16 +286,16 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { ClothClientHooks.SCREEN_LATE_RENDER.register((minecraftClient, screen, i, i1, v) -> { if (!ScreenHelper.isOverlayVisible()) return; - if (screen instanceof AbstractContainerScreen) + if (screen instanceof ContainerScreen) ScreenHelper.getLastOverlay().lateRender(i, i1, v); }); ClothClientHooks.SCREEN_KEY_PRESSED.register((minecraftClient, screen, i, i1, i2) -> { if (screen.getFocused() != null && screen.getFocused() instanceof TextFieldWidget || (screen.getFocused() instanceof RecipeBookWidget && ((RecipeBookGuiHooks) screen.getFocused()).rei_getSearchField() != null && ((RecipeBookGuiHooks) screen.getFocused()).rei_getSearchField().isFocused())) return ActionResult.PASS; - if (screen instanceof AbstractContainerScreen) + if (screen instanceof ContainerScreen) if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) return ActionResult.SUCCESS; - if (screen instanceof AbstractContainerScreen && configManager.getConfig().doesDisableRecipeBook() && configManager.getConfig().doesFixTabCloseContainer()) + if (screen instanceof ContainerScreen && ConfigObject.getInstance().doesDisableRecipeBook() && ConfigObject.getInstance().doesFixTabCloseContainer()) if (i == 258 && minecraftClient.options.keyInventory.matchesKey(i, i1)) { minecraftClient.player.closeContainer(); return ActionResult.SUCCESS; diff --git a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java index e1477a6d4..19b863a38 100644 --- a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java +++ b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java @@ -10,7 +10,7 @@ import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.container.Container; import java.util.function.Supplier; @@ -63,7 +63,7 @@ public interface AutoTransferHandler { } interface Context { - static Context create(boolean actuallyCrafting, AbstractContainerScreen containerScreen, RecipeDisplay recipeDisplay) { + static Context create(boolean actuallyCrafting, ContainerScreen containerScreen, RecipeDisplay recipeDisplay) { return new ContextImpl(actuallyCrafting, containerScreen, () -> recipeDisplay); } @@ -73,7 +73,7 @@ public interface AutoTransferHandler { boolean isActuallyCrafting(); - AbstractContainerScreen getContainerScreen(); + ContainerScreen getContainerScreen(); RecipeDisplay getRecipe(); @@ -139,10 +139,10 @@ public interface AutoTransferHandler { final class ContextImpl implements Context { boolean actuallyCrafting; - AbstractContainerScreen containerScreen; + ContainerScreen containerScreen; Supplier recipeDisplaySupplier; - private ContextImpl(boolean actuallyCrafting, AbstractContainerScreen containerScreen, Supplier recipeDisplaySupplier) { + private ContextImpl(boolean actuallyCrafting, ContainerScreen containerScreen, Supplier recipeDisplaySupplier) { this.actuallyCrafting = actuallyCrafting; this.containerScreen = containerScreen; this.recipeDisplaySupplier = recipeDisplaySupplier; @@ -154,7 +154,7 @@ public interface AutoTransferHandler { } @Override - public AbstractContainerScreen getContainerScreen() { + public ContainerScreen getContainerScreen() { return containerScreen; } diff --git a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java index 15d46e4de..1bd251725 100644 --- a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java +++ b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -5,14 +5,10 @@ package me.shedaniel.rei.api; -import com.google.common.collect.Lists; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import net.minecraft.client.gui.screen.Screen; -import org.jetbrains.annotations.ApiStatus; import java.util.List; -import java.util.function.Function; import java.util.function.Supplier; public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler { @@ -20,43 +16,16 @@ public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler getCurrentExclusionZones(Class currentScreenClass, boolean isOnRightSide) { + default List getExclusionZones(Class currentScreenClass) { return getExclusionZones(currentScreenClass, false); } - @Deprecated - @ApiStatus.ScheduledForRemoval - default List getCurrentExclusionZones(Class currentScreenClass, boolean isOnRightSide, boolean sort) { - return getExclusionZones(currentScreenClass, sort); - } - List getExclusionZones(Class currentScreenClass, boolean sort); int supplierSize(); - /** - * Register an exclusion zone - * - * @param screenClass the screen - * @param supplier the exclusion zone supplier, isOnRightSide -> the list of exclusion zones - * @see #registerExclusionZones(Class, Supplier) for non deprecated version - */ - @Deprecated - @ApiStatus.ScheduledForRemoval - default void registerExclusionZones(Class screenClass, Function> supplier) { - RoughlyEnoughItemsCore.LOGGER.warn("[REI] Someone is registering exclusion zones with the deprecated method: " + supplier.getClass().getName()); - registerExclusionZones(screenClass, () -> { - List zones = Lists.newArrayList(supplier.apply(false)); - zones.addAll(supplier.apply(true)); - return zones; - }); - } - /** * Register an exclusion zone * diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java index c2b785571..3f0da4e93 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -8,13 +8,11 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.RoughlyEnoughItemsCore; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; -import org.jetbrains.annotations.ApiStatus; import java.util.List; public interface ConfigManager { - @SuppressWarnings("deprecation") static ConfigManager getInstance() { return RoughlyEnoughItemsCore.getConfigManager(); } @@ -26,16 +24,6 @@ public interface ConfigManager { */ void saveConfig(); - /** - * Gets the config instance - * - * @return the config instance - * @deprecated Use {@link ConfigObject#getInstance()} - */ - @Deprecated - @ApiStatus.ScheduledForRemoval - ConfigObject getConfig(); - /** * Gets if craftable only filter is enabled * diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index fb2ca2650..c45ae56c9 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -9,8 +9,8 @@ import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.gui.config.ItemListOrdering; import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.gui.config.SearchFieldLocation; +import me.shedaniel.rei.impl.ConfigManagerImpl; import me.shedaniel.rei.impl.ConfigObjectImpl; -import net.minecraft.client.util.InputUtil; import org.jetbrains.annotations.ApiStatus; import java.lang.annotation.ElementType; @@ -20,15 +20,10 @@ import java.lang.annotation.Target; public interface ConfigObject { - @SuppressWarnings("deprecation") static ConfigObject getInstance() { - return ConfigManager.getInstance().getConfig(); + return ((ConfigManagerImpl) ConfigManager.getInstance()).getConfig(); } - @Deprecated - @ApiStatus.ScheduledForRemoval - boolean isLighterButtonHover(); - boolean isOverlayVisible(); void setOverlayVisible(boolean overlayVisible); @@ -45,11 +40,6 @@ public interface ConfigObject { boolean isToastDisplayedOnCopyIdentifier(); - @Deprecated - default boolean doesRenderEntryExtraOverlay() { - return doesRenderEntryEnchantmentGlint(); - } - boolean doesRenderEntryEnchantmentGlint(); boolean isEntryListWidgetScrolled(); @@ -104,11 +94,6 @@ public interface ConfigObject { boolean doSearchFavorites(); - @Deprecated - default InputUtil.KeyCode getFavoriteKeybind() { - return getFavoriteKeyCode().getKeyCode(); - } - ModifierKeyCode getFavoriteKeyCode(); ModifierKeyCode getRecipeKeybind(); diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 8df0c9c4f..2e1a174b1 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -17,7 +17,6 @@ import static net.minecraft.util.ActionResult.PASS; public interface DisplayHelper { - @SuppressWarnings("deprecation") static DisplayHelper getInstance() { return RoughlyEnoughItemsCore.getDisplayHelper(); } @@ -99,36 +98,6 @@ public interface DisplayHelper { return PASS; } - /** - * Checks if item slot can fit the screen - * - * @param isOnRightSide whether the user has set the overlay to the right - * @param left the left x coordinates of the stack - * @param top the top y coordinates for the stack - * @param screen the current screen - * @param fullBounds the current bounds - * @return whether the item slot can fit - * @deprecated use {@link #canItemSlotWidgetFit(int, int, Object, Rectangle)} - */ - @Deprecated - default ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, T screen, Rectangle fullBounds) { - return canItemSlotWidgetFit(left, top, screen, fullBounds); - } - - /** - * Checks if mouse is inside the overlay - * - * @param isOnRightSide whether the user has set the overlay to the right - * @param mouseX mouse's x coordinates - * @param mouseY mouse's y coordinates - * @return whether mouse is inside the overlay - * @deprecated use {@link #isInZone(double, double)} - */ - @Deprecated - default ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) { - return isInZone(mouseX, mouseY); - } - /** * Checks if mouse is inside the overlay * diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index bff5aebb5..39af13fec 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -17,7 +17,6 @@ import java.util.List; public interface EntryRegistry { - @SuppressWarnings("deprecation") static EntryRegistry getInstance() { return RoughlyEnoughItemsCore.getEntryRegistry(); } @@ -59,6 +58,7 @@ public interface EntryRegistry { * @param afterEntry the stack to put after * @param stack the stack to register * @param checkAlreadyContains whether the list should check if it is already on the list + * @see #queueRegisterEntryAfter(EntryStack, Collection) for a faster method */ @Deprecated @ApiStatus.Internal diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java index 61f9e3d71..9d36a0550 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryStack.java +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -167,11 +167,6 @@ public interface EntryStack { return setting(settings, value); } - @Deprecated - default ObjectHolder getSetting(Settings settings) { - return ObjectHolder.of(get(settings)); - } - T get(Settings settings); @Nullable QueuedTooltip getTooltip(int mouseX, int mouseY); @@ -208,7 +203,6 @@ public interface EntryStack { public static class Item { public static final Settings> RENDER_ENCHANTMENT_GLINT = new Settings<>(TRUE); - @Deprecated @ApiStatus.ScheduledForRemoval public static final Settings> RENDER_OVERLAY = RENDER_ENCHANTMENT_GLINT; private Item() { } diff --git a/src/main/java/me/shedaniel/rei/api/ObjectHolder.java b/src/main/java/me/shedaniel/rei/api/ObjectHolder.java deleted file mode 100644 index cb074d9a9..000000000 --- a/src/main/java/me/shedaniel/rei/api/ObjectHolder.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018, 2019, 2020 shedaniel - * Licensed under the MIT License (the "License"). - */ - -package me.shedaniel.rei.api; - -import me.shedaniel.rei.impl.ObjectHolderImpl; -import org.jetbrains.annotations.ApiStatus; - -public interface ObjectHolder { - @SuppressWarnings("deprecation") - static ObjectHolder of(T o) { - return new ObjectHolderImpl<>(o); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - default int intValue() { - return (int) (Object) value(); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - default long longValue() { - return (long) (Object) value(); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - default boolean booleanValue() { - return (boolean) (Object) value(); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - default float floatValue() { - return (float) (Object) value(); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - default double doubleValue() { - return (double) (Object) value(); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - default String stringValue() { - return (String) value(); - } - - T value(); -} \ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java b/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java index e7f90fd04..fbe31ba94 100644 --- a/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java +++ b/src/main/java/me/shedaniel/rei/api/REIPluginEntry.java @@ -15,7 +15,8 @@ import org.jetbrains.annotations.ApiStatus; */ public interface REIPluginEntry { - @ApiStatus.OverrideOnly + @ApiStatus.ScheduledForRemoval + @Deprecated default SemanticVersion getMinimumVersion() throws VersionParsingException { return null; } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 485e5d207..347957d63 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -127,16 +127,4 @@ public interface RecipeCategory { return -1; } - /** - * Gets whether the category will check tags, useful for potions - * - * @return whether the category will check tags - * @deprecated no longer used - */ - @Deprecated - @ApiStatus.ScheduledForRemoval - default boolean checkTags() { - return false; - } - } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index ee2243068..4e8a07f21 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; @@ -21,7 +21,6 @@ import java.util.function.Predicate; public interface RecipeHelper { - @SuppressWarnings("deprecation") static RecipeHelper getInstance() { return RoughlyEnoughItemsCore.getRecipeHelper(); } @@ -170,19 +169,6 @@ public interface RecipeHelper { */ List getDisplayVisibilityHandlers(); - /** - * Checks if the display is visible by asking recipe visibility handlers - * - * @param display the display to be checked - * @param respectConfig whether it should respect the user's config - * @return whether the display should be visible - * @deprecated {@link RecipeHelper#isDisplayVisible(RecipeDisplay)} )} - */ - @Deprecated - default boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig) { - return isDisplayVisible(display); - } - boolean isDisplayNotVisible(RecipeDisplay display); /** @@ -203,7 +189,7 @@ public interface RecipeHelper { */ void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator); - void registerScreenClickArea(Rectangle rectangle, Class> screenClass, Identifier... categories); + void registerScreenClickArea(Rectangle rectangle, Class> screenClass, Identifier... categories); > void registerRecipes(Identifier category, Class recipeClass, Function mappingFunction); @@ -215,7 +201,7 @@ public interface RecipeHelper { boolean arePluginsLoading(); interface ScreenClickArea { - Class getScreenClass(); + Class getScreenClass(); Rectangle getRectangle(); diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index d3e15b70b..c23d382b0 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -21,11 +21,12 @@ import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.util.NarratorManager; import net.minecraft.client.util.Window; import net.minecraft.client.util.math.Matrix4f; import net.minecraft.client.util.math.MatrixStack; @@ -33,6 +34,7 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvents; +import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import net.minecraft.world.GameMode; @@ -100,7 +102,6 @@ public class ContainerScreenOverlay extends WidgetWithBounds { init(); } - @SuppressWarnings("deprecation") public void init() { this.shouldReInit = false; //Update Variables @@ -123,7 +124,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { this.widgets.add(ScreenHelper.getSearchField()); ScreenHelper.getSearchField().setChangedListener(ENTRY_LIST_WIDGET::updateSearch); if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { - widgets.add(leftButton = new ButtonWidget(new Rectangle(bounds.x, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), I18n.translate("text.rei.left_arrow")) { + widgets.add(leftButton = new ButtonWidget(new Rectangle(bounds.x, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableText("text.rei.left_arrow")) { @Override public void onPressed() { ENTRY_LIST_WIDGET.previousPage(); @@ -132,22 +133,12 @@ public class ContainerScreenOverlay extends WidgetWithBounds { ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText()); } - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.previous_page")); - } - - @Override - public boolean changeFocus(boolean boolean_1) { - return false; - } - @Override public boolean containsMouse(double mouseX, double mouseY) { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } - }); - widgets.add(rightButton = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 18, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), I18n.translate("text.rei.right_arrow")) { + }.tooltip(() -> I18n.translate("text.rei.previous_page")).canChangeFocuses(false)); + widgets.add(rightButton = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 18, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableText("text.rei.right_arrow")) { @Override public void onPressed() { ENTRY_LIST_WIDGET.nextPage(); @@ -156,24 +147,14 @@ public class ContainerScreenOverlay extends WidgetWithBounds { ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText()); } - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.next_page")); - } - - @Override - public boolean changeFocus(boolean boolean_1) { - return false; - } - @Override public boolean containsMouse(double mouseX, double mouseY) { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } - }); + }.tooltip(() -> I18n.translate("text.rei.next_page")).canChangeFocuses(false)); } - widgets.add(configButton = new LateRenderedButton(getConfigButtonArea(), "") { + widgets.add(configButton = new LateRenderedButton(getConfigButtonArea(), NarratorManager.EMPTY) { @Override public void onPressed() { if (Screen.hasShiftDown()) { @@ -230,7 +211,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } }); if (ConfigObject.getInstance().doesShowUtilsButtons()) { - widgets.add(new ButtonWidget(ConfigObject.getInstance().isLowerConfigButton() ? new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20) : new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20), "") { + widgets.add(new ButtonWidget(ConfigObject.getInstance().isLowerConfigButton() ? new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20) : new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20), NarratorManager.EMPTY) { @Override public void onPressed() { MinecraftClient.getInstance().player.sendChatMessage(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName())); @@ -242,24 +223,14 @@ public class ContainerScreenOverlay extends WidgetWithBounds { super.render(mouseX, mouseY, delta); } - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.gamemode_button.tooltip", getGameModeText(getNextGameMode(Screen.hasShiftDown())))); - } - - @Override - public boolean changeFocus(boolean boolean_1) { - return false; - } - @Override public boolean containsMouse(double mouseX, double mouseY) { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } - }); + }.tooltip(() -> I18n.translate("text.rei.gamemode_button.tooltip", getGameModeText(getNextGameMode(Screen.hasShiftDown())))).canChangeFocuses(false)); int xxx = ConfigObject.getInstance().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10; for (Weather weather : Weather.values()) { - widgets.add(new ButtonWidget(new Rectangle(xxx, 35, 20, 20), "") { + widgets.add(new ButtonWidget(new Rectangle(xxx, 35, 20, 20), NarratorManager.EMPTY) { @Override public void onPressed() { MinecraftClient.getInstance().player.sendChatMessage(ConfigObject.getInstance().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); @@ -273,21 +244,11 @@ public class ContainerScreenOverlay extends WidgetWithBounds { blit(getBounds().x + 3, getBounds().y + 3, weather.getId() * 14, 14, 14, 14); } - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.weather_button.tooltip", I18n.translate(weather.getTranslateKey()))); - } - - @Override - public boolean changeFocus(boolean boolean_1) { - return false; - } - @Override public boolean containsMouse(double mouseX, double mouseY) { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } - }); + }.tooltip(() -> I18n.translate("text.rei.weather_button.tooltip", I18n.translate(weather.getTranslateKey()))).canChangeFocuses(false)); xxx += ConfigObject.getInstance().isLeftHandSidePanel() ? -25 : 25; } } @@ -443,10 +404,10 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } if (OverlaySearchField.isSearching) { setBlitOffset(200); - if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen) { + if (MinecraftClient.getInstance().currentScreen instanceof ContainerScreen) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; int left = hooks.rei_getContainerLeft(), top = hooks.rei_getContainerTop(); - for (Slot slot : ((AbstractContainerScreen) MinecraftClient.getInstance().currentScreen).getContainer().slotList) + for (Slot slot : ((ContainerScreen) MinecraftClient.getInstance().currentScreen).getContainer().slots) if (!slot.hasStack() || !ENTRY_LIST_WIDGET.canLastSearchTermsBeAppliedTo(EntryStack.create(slot.getStack()))) fillGradient(left + slot.xPosition, top + slot.yPosition, left + slot.xPosition + 16, top + slot.yPosition + 16, -601874400, -601874400); } @@ -454,7 +415,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { } RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.renderWidgets(mouseX, mouseY, delta); - if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { + if (MinecraftClient.getInstance().currentScreen instanceof ContainerScreen && ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) @@ -559,7 +520,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { return true; } ItemStack itemStack = null; - if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen) + if (MinecraftClient.getInstance().currentScreen instanceof ContainerScreen) if (ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot() != null && !ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot().getStack().isEmpty()) itemStack = ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot().getStack(); if (itemStack != null && !itemStack.isEmpty()) { @@ -601,7 +562,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public boolean mouseClicked(double double_1, double double_2, int int_1) { if (!ScreenHelper.isOverlayVisible()) return false; - if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { + if (MinecraftClient.getInstance().currentScreen instanceof ContainerScreen && ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index d44ec610e..626f9ffb6 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -20,8 +20,9 @@ import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.util.NarratorManager; import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; @@ -84,7 +85,7 @@ public class PreRecipeViewingScreen extends Screen { protected void init() { this.children.clear(); this.widgets.clear(); - this.widgets.add(new ButtonWidget(new Rectangle(width / 2 - 100, height - 40, 200, 20), "") { + this.widgets.add(new ButtonWidget(new Rectangle(width / 2 - 100, height - 40, 200, 20), NarratorManager.EMPTY) { @Override public void render(int mouseX, int mouseY, float delta) { enabled = isSet; @@ -150,7 +151,7 @@ public class PreRecipeViewingScreen extends Screen { public boolean keyPressed(int int_1, int int_2, int int_3) { if (int_1 == 256 || this.minecraft.options.keyInventory.matchesKey(int_1, int_2)) { MinecraftClient.getInstance().openScreen(parent); - if (parent instanceof AbstractContainerScreen) + if (parent instanceof ContainerScreen) ScreenHelper.getLastOverlay().init(); return true; } diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java b/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java index 1dd447eb1..4586ea272 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java @@ -43,6 +43,7 @@ public final class RecipeDisplayExporter extends Widget { INSTANCE.exportRecipe(rectangle, widgets); } + @SuppressWarnings("deprecation") private void exportRecipe(Rectangle rectangle, List widgets) { Framebuffer framebuffer = new Framebuffer(rectangle.width * 8, rectangle.height * 8, true, MinecraftClient.IS_SYSTEM_MAC); framebuffer.setClearColor(0, 0, 0, 0); diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index d8e3d8cdc..15ef1cd24 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -23,12 +23,12 @@ import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.Window; import net.minecraft.client.util.math.Matrix4f; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; +import net.minecraft.text.TranslatableText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -172,96 +172,52 @@ public class RecipeViewingScreen extends Screen { this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight); this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1); ButtonWidget w, w2; - this.widgets.add(w = new ButtonWidget(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), I18n.translate("text.rei.left_arrow")) { - @Override - public void onPressed() { - categoryPages--; - if (categoryPages < 0) - categoryPages = MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1; - RecipeViewingScreen.this.init(); - } - }); - this.widgets.add(w2 = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), I18n.translate("text.rei.right_arrow")) { - @Override - public void onPressed() { - categoryPages++; - if (categoryPages > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1) - categoryPages = 0; - RecipeViewingScreen.this.init(); - } - }); + this.widgets.add(w = ButtonWidget.create(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow"), buttonWidget -> { + categoryPages--; + if (categoryPages < 0) + categoryPages = MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1; + RecipeViewingScreen.this.init(); + })); + this.widgets.add(w2 = ButtonWidget.create(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow"), buttonWidget -> { + categoryPages++; + if (categoryPages > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1) + categoryPages = 0; + RecipeViewingScreen.this.init(); + })); w.enabled = w2.enabled = categories.size() > tabsPerPage; - widgets.add(categoryBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 5, 12, 12), I18n.translate("text.rei.left_arrow")) { - @Override - public void onPressed() { - int currentCategoryIndex = categories.indexOf(selectedCategory); - currentCategoryIndex--; - if (currentCategoryIndex < 0) - currentCategoryIndex = categories.size() - 1; - selectedCategory = (RecipeCategory) categories.get(currentCategoryIndex); - categoryPages = MathHelper.floor(currentCategoryIndex / (double) tabsPerPage); - page = 0; - RecipeViewingScreen.this.init(); - } - - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.previous_category")); - } - }); - widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 7), "") { - @Override - public void render(int mouseX, int mouseY, float delta) { - setText(selectedCategory.getCategoryName()); - super.render(mouseX, mouseY, delta); - } - - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.view_all_categories")); - } - - @Override - public void onLabelClicked() { - MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - ClientHelper.getInstance().executeViewAllRecipesKeyBind(); - } - }); - widgets.add(categoryNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12), I18n.translate("text.rei.right_arrow")) { - @Override - public void onPressed() { - int currentCategoryIndex = categories.indexOf(selectedCategory); - currentCategoryIndex++; - if (currentCategoryIndex >= categories.size()) - currentCategoryIndex = 0; - selectedCategory = (RecipeCategory) categories.get(currentCategoryIndex); - categoryPages = MathHelper.floor(currentCategoryIndex / (double) tabsPerPage); - page = 0; - RecipeViewingScreen.this.init(); - } - - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.next_category")); - } - }); + widgets.add(categoryBack = ButtonWidget.create(new Rectangle(bounds.getX() + 5, bounds.getY() + 5, 12, 12), new TranslatableText("text.rei.left_arrow"), buttonWidget -> { + int currentCategoryIndex = categories.indexOf(selectedCategory); + currentCategoryIndex--; + if (currentCategoryIndex < 0) + currentCategoryIndex = categories.size() - 1; + selectedCategory = (RecipeCategory) categories.get(currentCategoryIndex); + categoryPages = MathHelper.floor(currentCategoryIndex / (double) tabsPerPage); + page = 0; + RecipeViewingScreen.this.init(); + }).tooltip(() -> I18n.translate("text.rei.previous_category"))); + widgets.add(LabelWidget.createClickable(new Point(bounds.getCenterX(), bounds.getY() + 7), selectedCategory.getCategoryName(), clickableLabelWidget -> { + MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); + ClientHelper.getInstance().executeViewAllRecipesKeyBind(); + }).tooltip(() -> I18n.translate("text.rei.view_all_categories"))); + widgets.add(categoryNext = ButtonWidget.create(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12), new TranslatableText("text.rei.right_arrow"), buttonWidget -> { + int currentCategoryIndex = categories.indexOf(selectedCategory); + currentCategoryIndex++; + if (currentCategoryIndex >= categories.size()) + currentCategoryIndex = 0; + selectedCategory = (RecipeCategory) categories.get(currentCategoryIndex); + categoryPages = MathHelper.floor(currentCategoryIndex / (double) tabsPerPage); + page = 0; + RecipeViewingScreen.this.init(); + }).tooltip(() -> I18n.translate("text.rei.next_category"))); categoryBack.enabled = categories.size() > 1; categoryNext.enabled = categories.size() > 1; - widgets.add(recipeBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 19, 12, 12), I18n.translate("text.rei.left_arrow")) { - @Override - public void onPressed() { - page--; - if (page < 0) - page = getTotalPages(selectedCategory) - 1; - RecipeViewingScreen.this.init(); - } - - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.previous_page")); - } - }); + widgets.add(recipeBack = ButtonWidget.create(new Rectangle(bounds.getX() + 5, bounds.getY() + 19, 12, 12), new TranslatableText("text.rei.left_arrow"), buttonWidget -> { + page--; + if (page < 0) + page = getTotalPages(selectedCategory) - 1; + RecipeViewingScreen.this.init(); + }).tooltip(() -> I18n.translate("text.rei.previous_page"))); widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 21), "") { @Override public void render(int mouseX, int mouseY, float delta) { @@ -269,32 +225,19 @@ public class RecipeViewingScreen extends Screen { super.render(mouseX, mouseY, delta); } - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.choose_page")); - } - @Override public void onLabelClicked() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); RecipeViewingScreen.this.choosePageActivated = true; RecipeViewingScreen.this.init(); } - }.clickable(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight())); - widgets.add(recipeNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), I18n.translate("text.rei.right_arrow")) { - @Override - public void onPressed() { - page++; - if (page >= getTotalPages(selectedCategory)) - page = 0; - RecipeViewingScreen.this.init(); - } - - @Override - public Optional getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.next_page")); - } - }); + }.clickable(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight()).tooltip(() -> I18n.translate("text.rei.choose_page"))); + widgets.add(recipeNext = ButtonWidget.create(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), new TranslatableText("text.rei.right_arrow"), buttonWidget -> { + page++; + if (page >= getTotalPages(selectedCategory)) + page = 0; + RecipeViewingScreen.this.init(); + }).tooltip(() -> I18n.translate("text.rei.next_page"))); recipeBack.enabled = recipeNext.enabled = categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight(); int tabV = isCompactTabs ? 166 : 192; for (int i = 0; i < tabsPerPage; i++) { diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 382d1c76c..133827ee2 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -26,6 +26,7 @@ import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.util.NarratorManager; import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; import net.minecraft.text.TranslatableText; @@ -148,7 +149,7 @@ public class VillagerRecipeViewingScreen extends Screen { int finalIndex = index; RecipeEntry recipeEntry; recipeRenderers.add(recipeEntry = category.getSimpleRenderer(recipeDisplay)); - buttonWidgets.add(new ButtonWidget(new Rectangle(bounds.x + 5, 0, recipeEntry.getWidth(), recipeEntry.getHeight()), "") { + buttonWidgets.add(new ButtonWidget(new Rectangle(bounds.x + 5, 0, recipeEntry.getWidth(), recipeEntry.getHeight()), NarratorManager.EMPTY) { @Override public void onPressed() { selectedRecipeIndex = finalIndex; @@ -203,24 +204,18 @@ public class VillagerRecipeViewingScreen extends Screen { } } ButtonWidget w, w2; - this.widgets.add(w = new ButtonWidget(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow")) { - @Override - public void onPressed() { - tabsPage--; - if (tabsPage < 0) - tabsPage = MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1; - VillagerRecipeViewingScreen.this.init(); - } - }); - this.widgets.add(w2 = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow")) { - @Override - public void onPressed() { - tabsPage++; - if (tabsPage > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1) - tabsPage = 0; - VillagerRecipeViewingScreen.this.init(); - } - }); + this.widgets.add(w = ButtonWidget.create(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow"), buttonWidget -> { + tabsPage--; + if (tabsPage < 0) + tabsPage = MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1; + VillagerRecipeViewingScreen.this.init(); + })); + this.widgets.add(w2 = ButtonWidget.create(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow"), buttonWidget -> { + tabsPage++; + if (tabsPage > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1) + tabsPage = 0; + VillagerRecipeViewingScreen.this.init(); + })); w.enabled = w2.enabled = categories.size() > tabsPerPage; this.widgets.add(new ClickableLabelWidget(new Point(bounds.x + 4 + scrollListBounds.width / 2, bounds.y + 6), categories.get(selectedCategoryIndex).getCategoryName()) { diff --git a/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java b/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java index b927fed7c..68df9b36f 100644 --- a/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java @@ -11,7 +11,7 @@ import me.shedaniel.rei.impl.ScreenHelper; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.metadata.CustomValue; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.client.gui.widget.AbstractPressableButtonWidget; import net.minecraft.client.resource.language.I18n; import net.minecraft.text.LiteralText; @@ -36,7 +36,7 @@ public class CreditsScreen extends Screen { public boolean keyPressed(int int_1, int int_2, int int_3) { if (int_1 == 256 && this.shouldCloseOnEsc()) { this.minecraft.openScreen(parent); - if (parent instanceof AbstractContainerScreen) + if (parent instanceof ContainerScreen) ScreenHelper.getLastOverlay().init(); return true; } @@ -54,7 +54,7 @@ public class CreditsScreen extends Screen { CustomValue.CvObject jsonObject = rei.getMetadata().getCustomValue("rei:translators").getAsObject(); jsonObject.forEach(entry -> { CustomValue value = entry.getValue(); - String behind = value.getType() == CustomValue.CvType.ARRAY ? Lists.newArrayList(value.getAsArray().iterator()).stream().map(json -> json.getAsString()).sorted(String::compareToIgnoreCase).collect(Collectors.joining(", ")) : value.getAsString(); + String behind = value.getType() == CustomValue.CvType.ARRAY ? Lists.newArrayList(value.getAsArray().iterator()).stream().map(CustomValue::getAsString).sorted(String::compareToIgnoreCase).collect(Collectors.joining(", ")) : value.getAsString(); translators.add(String.format(" %s - %s", entry.getKey(), behind)); }); } @@ -77,7 +77,7 @@ public class CreditsScreen extends Screen { @Override public void onPress() { CreditsScreen.this.minecraft.openScreen(parent); - if (parent instanceof AbstractContainerScreen) + if (parent instanceof ContainerScreen) ScreenHelper.getLastOverlay().init(); } }); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java index 6ac7c525d..8dfc6c80d 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -15,8 +15,9 @@ import me.shedaniel.rei.gui.toast.CopyRecipeIdentifierToast; import me.shedaniel.rei.impl.ClientHelperImpl; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.utils.CollectionUtils; -import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.ContainerScreen; import net.minecraft.client.resource.language.I18n; +import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; @@ -32,13 +33,13 @@ public class AutoCraftingButtonWidget extends ButtonWidget { private String extraTooltip; private List errorTooltip; private List setupDisplay; - private AbstractContainerScreen containerScreen; + private ContainerScreen containerScreen; private boolean visible = false; private RecipeCategory category; private Rectangle displayBounds; public AutoCraftingButtonWidget(Rectangle displayBounds, Rectangle rectangle, String text, Supplier displaySupplier, List setupDisplay, RecipeCategory recipeCategory) { - super(rectangle, text); + super(rectangle, new LiteralText(text)); this.displayBounds = displayBounds; this.displaySupplier = displaySupplier; Optional recipe = displaySupplier.get().getRecipeLocation(); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java index 1a73c552f..4191978f4 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ButtonWidget.java @@ -12,6 +12,7 @@ import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.gui.Element; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.sound.SoundEvents; +import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -20,24 +21,57 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Supplier; public abstract class ButtonWidget extends WidgetWithBounds { protected static final Identifier BUTTON_LOCATION = new Identifier("roughlyenoughitems", "textures/gui/button.png"); protected static final Identifier BUTTON_LOCATION_DARK = new Identifier("roughlyenoughitems", "textures/gui/button_dark.png"); - public boolean enabled; - public boolean focused; + public boolean enabled = true; + public boolean focused = false; + private boolean canChangeFocuses = true; private String text; private Rectangle bounds; + private Supplier tooltipSupplier; - public ButtonWidget(Rectangle rectangle, Text text) { - this(rectangle, Objects.requireNonNull(text).asFormattedString()); + protected ButtonWidget(Rectangle rectangle, Text text) { + this.bounds = Objects.requireNonNull(rectangle); + this.text = Objects.requireNonNull(text).asFormattedString(); } - public ButtonWidget(Rectangle rectangle, String text) { - this.bounds = Objects.requireNonNull(rectangle); - this.enabled = true; - this.text = Objects.requireNonNull(text); + public static ButtonWidget create(Rectangle point, String text, Consumer onClick) { + return create(point, new LiteralText(text), onClick); + } + + public static ButtonWidget create(Rectangle point, Text text, Consumer onClick) { + ButtonWidget[] widget = {null}; + widget[0] = new ButtonWidget(point, text) { + @Override + public void onPressed() { + onClick.accept(widget[0]); + } + }; + return widget[0]; + } + + public ButtonWidget tooltip(Supplier tooltipSupplier) { + this.tooltipSupplier = tooltipSupplier; + return this; + } + + public ButtonWidget enabled(boolean enabled) { +