From 9e990de7685960391d78ca2cca0ff68bebe1a8cd Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 16 Mar 2020 16:19:25 +0800 Subject: 4.0.13 Signed-off-by: shedaniel --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 22 +++---- .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 4 +- .../me/shedaniel/rei/api/AutoTransferHandler.java | 28 ++++---- .../me/shedaniel/rei/api/DrawableConsumer.java | 3 +- src/main/java/me/shedaniel/rei/api/EntryStack.java | 19 +++++- src/main/java/me/shedaniel/rei/api/REIHelper.java | 13 +++- .../java/me/shedaniel/rei/api/RecipeCategory.java | 6 +- .../java/me/shedaniel/rei/api/RecipeHelper.java | 6 +- .../java/me/shedaniel/rei/api/widgets/Slot.java | 16 ++++- .../java/me/shedaniel/rei/api/widgets/Tooltip.java | 59 +++++++++++++++++ .../java/me/shedaniel/rei/api/widgets/Widgets.java | 77 +++++++++++++++------- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 48 +++++++------- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 8 +-- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 32 +++++---- .../rei/gui/VillagerRecipeViewingScreen.java | 19 +++--- .../rei/gui/config/entry/FilteringEntry.java | 6 +- .../shedaniel/rei/gui/credits/CreditsScreen.java | 6 +- .../me/shedaniel/rei/gui/entries/RecipeEntry.java | 9 ++- .../rei/gui/entries/SimpleRecipeEntry.java | 28 ++++---- .../rei/gui/widget/AutoCraftingButtonWidget.java | 17 ++--- .../me/shedaniel/rei/gui/widget/ButtonWidget.java | 5 +- .../rei/gui/widget/CategoryBaseWidget.java | 8 ++- .../rei/gui/widget/ClickableLabelWidget.java | 5 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 3 +- .../me/shedaniel/rei/gui/widget/EntryWidget.java | 13 ++-- .../rei/gui/widget/FavoritesListWidget.java | 3 +- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 3 +- .../me/shedaniel/rei/gui/widget/QueuedTooltip.java | 37 ++++++----- .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 6 ++ .../rei/gui/widget/RecipeChoosePageWidget.java | 8 ++- .../shedaniel/rei/gui/widget/SlotBaseWidget.java | 7 ++ .../me/shedaniel/rei/gui/widget/TabWidget.java | 5 +- .../java/me/shedaniel/rei/gui/widget/Widget.java | 4 ++ .../me/shedaniel/rei/impl/ClientHelperImpl.java | 4 +- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 2 +- .../me/shedaniel/rei/impl/DisplayHelperImpl.java | 1 + .../me/shedaniel/rei/impl/EmptyEntryStack.java | 6 +- .../me/shedaniel/rei/impl/FluidEntryStack.java | 7 +- .../java/me/shedaniel/rei/impl/ItemEntryStack.java | 7 +- .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 12 ++-- .../java/me/shedaniel/rei/impl/RenderingEntry.java | 4 +- .../java/me/shedaniel/rei/impl/ScreenHelper.java | 50 +++++++++----- .../java/me/shedaniel/rei/impl/SearchArgument.java | 5 +- .../rei/impl/widgets/BurningFireWidget.java | 3 +- .../shedaniel/rei/impl/widgets/DrawableWidget.java | 4 +- .../widgets/FillRectangleDrawableConsumer.java | 6 +- .../me/shedaniel/rei/impl/widgets/LabelWidget.java | 12 ++-- .../me/shedaniel/rei/impl/widgets/PanelWidget.java | 12 ++-- .../rei/impl/widgets/TexturedDrawableConsumer.java | 6 +- .../listeners/AbstractInventoryScreenHooks.java | 2 +- .../rei/listeners/ContainerScreenHooks.java | 4 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 26 ++++---- .../plugin/DefaultPotionEffectExclusionZones.java | 4 +- .../plugin/DefaultRecipeBookExclusionZones.java | 8 +-- .../rei/plugin/DefaultServerContainerPlugin.java | 2 +- .../autocrafting/DefaultCategoryHandler.java | 4 +- .../autocrafting/DefaultRecipeBookHandler.java | 20 +++--- .../plugin/beacon/DefaultBeaconBaseCategory.java | 18 ++--- .../composting/DefaultCompostingCategory.java | 8 --- .../containers/CraftingContainerInfoWrapper.java | 8 +-- .../plugin/crafting/DefaultCraftingCategory.java | 4 +- .../rei/plugin/fuel/DefaultFuelCategory.java | 8 +-- .../information/DefaultInformationCategory.java | 8 --- 63 files changed, 498 insertions(+), 300 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java (limited to 'src/main/java/me') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 7145848f8..617f246b0 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -40,10 +40,10 @@ 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.CraftingTableScreen; +import net.minecraft.client.gui.screen.ingame.CraftingScreen; import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.screen.ingame.InventoryScreen; -import net.minecraft.client.gui.screen.ingame.ScreenWithHandler; import net.minecraft.client.gui.screen.recipebook.RecipeBookGhostSlots; import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget; @@ -54,7 +54,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.RecipeManager; -import net.minecraft.screen.CraftingTableScreenHandler; +import net.minecraft.screen.CraftingScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.text.LiteralText; import net.minecraft.util.ActionResult; @@ -188,7 +188,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { }); ClientSidePacketRegistry.INSTANCE.register(RoughlyEnoughItemsNetwork.NOT_ENOUGH_ITEMS_PACKET, (packetContext, packetByteBuf) -> { Screen currentScreen = MinecraftClient.getInstance().currentScreen; - if (currentScreen instanceof CraftingTableScreen) { + if (currentScreen instanceof CraftingScreen) { RecipeBookWidget recipeBookGui = ((RecipeBookProvider) currentScreen).getRecipeBookWidget(); RecipeBookGhostSlots ghostSlots = ((RecipeBookGuiHooks) recipeBookGui).rei_getGhostSlots(); ghostSlots.reset(); @@ -205,12 +205,12 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } ghostSlots.addSlot(Ingredient.ofItems(Items.STONE), 381203812, 12738291); - CraftingTableScreenHandler screenHandler = ((CraftingTableScreen) currentScreen).getScreenHandler(); + CraftingScreenHandler screenHandler = ((CraftingScreen) currentScreen).getScreenHandler(); for (int i = 0; i < input.size(); i++) { List stacks = input.get(i); if (!stacks.isEmpty()) { Slot slot = screenHandler.getSlot(i + screenHandler.getCraftingResultSlotIndex() + 1); - ghostSlots.addSlot(Ingredient.ofStacks(stacks.toArray(new ItemStack[0])), slot.xPosition, slot.yPosition); + ghostSlots.addSlot(Ingredient.ofStacks(stacks.toArray(new ItemStack[0])), slot.x, slot.y); } } } @@ -253,7 +253,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { continue; ActionResult result = decider.shouldScreenBeOverlayed(screen); if (result != ActionResult.PASS) - return result == ActionResult.FAIL || ScreenHelper.getLastScreenWithHandlerHooks() == null; + return result == ActionResult.FAIL || ScreenHelper.getLastHandledScreen() == null; } return true; } @@ -263,7 +263,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { long[] lastSync = {-1}; ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> syncRecipes(lastSync)); ClothClientHooks.SCREEN_ADD_BUTTON.register((minecraftClient, screen, abstractButtonWidget) -> { - if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof ScreenWithHandler && abstractButtonWidget instanceof TexturedButtonWidget) + if (ConfigObject.getInstance().doesDisableRecipeBook() && screen instanceof HandledScreen && abstractButtonWidget instanceof TexturedButtonWidget) if (((RecipeBookButtonWidgetHooks) abstractButtonWidget).rei_getTexture().equals(recipeButtonTex)) return ActionResult.FAIL; return ActionResult.PASS; @@ -273,8 +273,8 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return; if (shouldReturn(screen.getClass())) return; - if (screen instanceof ScreenWithHandler) - ScreenHelper.setLastScreenWithHandler((ScreenWithHandler) screen); + if (screen instanceof HandledScreen) + ScreenHelper.setLastHandledScreen((HandledScreen) screen); boolean alreadyAdded = false; for (Element element : Lists.newArrayList(screenHooks.cloth_getChildren())) if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) @@ -335,7 +335,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ActionResult.PASS; if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) return ActionResult.SUCCESS; - if (screen instanceof ScreenWithHandler && ConfigObject.getInstance().doesDisableRecipeBook() && ConfigObject.getInstance().doesFixTabCloseContainer()) + if (screen instanceof HandledScreen && ConfigObject.getInstance().doesDisableRecipeBook() && ConfigObject.getInstance().doesFixTabCloseContainer()) if (i == 258 && minecraftClient.options.keyInventory.matchesKey(i, i1)) { minecraftClient.player.closeHandledScreen(); return ActionResult.SUCCESS; diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 2519bace6..f62fef279 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -31,7 +31,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.item.ItemStack; -import net.minecraft.screen.CraftingScreenHandler; +import net.minecraft.screen.AbstractRecipeScreenHandler; import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.screen.ScreenHandler; import net.minecraft.server.network.ServerPlayerEntity; @@ -96,7 +96,7 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { try { InputSlotCrafter.start(category, screenHandler, player, input, shift); } catch (InputSlotCrafter.NotEnoughMaterialsException e) { - if (!(screenHandler instanceof CraftingScreenHandler)) + if (!(screenHandler instanceof AbstractRecipeScreenHandler)) return; PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); buf.writeInt(input.size()); diff --git a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java index 70ba2dd55..63f1d08a1 100644 --- a/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java +++ b/src/main/java/me/shedaniel/rei/api/AutoTransferHandler.java @@ -28,7 +28,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.ScreenWithHandler; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.screen.ScreenHandler; import org.jetbrains.annotations.ApiStatus; @@ -82,8 +82,8 @@ public interface AutoTransferHandler { } interface Context { - static Context create(boolean actuallyCrafting, ScreenWithHandler containerScreen, RecipeDisplay recipeDisplay) { - return new ContextImpl(actuallyCrafting, containerScreen, () -> recipeDisplay); + static Context create(boolean actuallyCrafting, HandledScreen handledScreen, RecipeDisplay recipeDisplay) { + return new ContextImpl(actuallyCrafting, handledScreen, () -> recipeDisplay); } default MinecraftClient getMinecraft() { @@ -92,12 +92,18 @@ public interface AutoTransferHandler { boolean isActuallyCrafting(); - ScreenWithHandler getScreenWithHandler(); + HandledScreen getHandledScreen(); @Deprecated @ApiStatus.ScheduledForRemoval - default ScreenWithHandler getContainerScreen() { - return getScreenWithHandler(); + default HandledScreen getScreenWithHandler() { + return getHandledScreen(); + } + + @Deprecated + @ApiStatus.ScheduledForRemoval + default HandledScreen getContainerScreen() { + return getHandledScreen(); } RecipeDisplay getRecipe(); @@ -174,12 +180,12 @@ public interface AutoTransferHandler { @ApiStatus.Internal final class ContextImpl implements Context { boolean actuallyCrafting; - ScreenWithHandler screenWithHandler; + HandledScreen handledScreen; Supplier recipeDisplaySupplier; - private ContextImpl(boolean actuallyCrafting, ScreenWithHandler screenWithHandler, Supplier recipeDisplaySupplier) { + private ContextImpl(boolean actuallyCrafting, HandledScreen handledScreen, Supplier recipeDisplaySupplier) { this.actuallyCrafting = actuallyCrafting; - this.screenWithHandler = screenWithHandler; + this.handledScreen = handledScreen; this.recipeDisplaySupplier = recipeDisplaySupplier; } @@ -189,8 +195,8 @@ public interface AutoTransferHandler { } @Override - public ScreenWithHandler getScreenWithHandler() { - return screenWithHandler; + public HandledScreen getHandledScreen() { + return handledScreen; } @Override diff --git a/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java b/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java index 77ebfd9f7..cef309c89 100644 --- a/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java +++ b/src/main/java/me/shedaniel/rei/api/DrawableConsumer.java @@ -24,10 +24,11 @@ package me.shedaniel.rei.api; import net.minecraft.client.gui.DrawableHelper; +import org.jetbrains.annotations.NotNull; /** * Consumer of a {@link DrawableHelper} and information of mouse and delta. */ public interface DrawableConsumer { - void render(DrawableHelper helper, int mouseX, int mouseY, float delta); + void render(@NotNull DrawableHelper helper, int mouseX, int mouseY, float delta); } diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java index 376ae2aef..c2d5241e2 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryStack.java +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -25,7 +25,9 @@ package me.shedaniel.rei.api; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import me.shedaniel.math.Point; import me.shedaniel.math.api.Rectangle; +import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.impl.EmptyEntryStack; import me.shedaniel.rei.impl.FluidEntryStack; @@ -229,7 +231,22 @@ public interface EntryStack { T get(Settings settings); - @Nullable QueuedTooltip getTooltip(int mouseX, int mouseY); + /** + * @deprecated Use {@link #getTooltip(Point)} + */ + @Nullable + @Deprecated + @ApiStatus.ScheduledForRemoval + default QueuedTooltip getTooltip(int mouseX, int mouseY) { + return null; + } + + @Nullable + default Tooltip getTooltip(Point point) { + QueuedTooltip tooltip = getTooltip(point.x, point.y); + if (tooltip == null) return null; + return Tooltip.create(new Point(tooltip.getX(), tooltip.getY()), tooltip.getText()); + } void render(Rectangle bounds, int mouseX, int mouseY, float delta); diff --git a/src/main/java/me/shedaniel/rei/api/REIHelper.java b/src/main/java/me/shedaniel/rei/api/REIHelper.java index 578d3d4bf..5c8c80209 100644 --- a/src/main/java/me/shedaniel/rei/api/REIHelper.java +++ b/src/main/java/me/shedaniel/rei/api/REIHelper.java @@ -23,10 +23,12 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.gui.widget.TextFieldWidget; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -46,6 +48,15 @@ public interface REIHelper { List getInventoryStacks(); - void addTooltip(@Nullable QueuedTooltip tooltip); + /** + * @deprecated Use {@link #queueTooltip(Tooltip)} or {@link Tooltip#queue()} + */ + @Deprecated + @ApiStatus.ScheduledForRemoval + default void addTooltip(@Nullable QueuedTooltip tooltip) { + queueTooltip(tooltip); + } + + void queueTooltip(@Nullable Tooltip tooltip); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 631217963..d491231b8 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -24,12 +24,12 @@ package me.shedaniel.rei.api; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; -import me.shedaniel.rei.gui.widget.PanelWidget; -import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; +import me.shedaniel.rei.impl.widgets.PanelWidget; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.util.Identifier; import org.jetbrains.annotations.ApiStatus; @@ -87,7 +87,7 @@ public interface RecipeCategory { @ApiStatus.ScheduledForRemoval @Deprecated default List setupDisplay(Supplier recipeDisplaySupplier, me.shedaniel.math.api.Rectangle bounds) { - return Collections.singletonList(new RecipeBaseWidget(bounds)); + return Collections.singletonList(Widgets.createCategoryBase(bounds)); } /** diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index dfb2db0bd..122100fb0 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -25,7 +25,7 @@ package me.shedaniel.rei.api; import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import net.minecraft.client.gui.screen.ingame.ScreenWithHandler; +import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; import net.minecraft.util.Identifier; @@ -220,7 +220,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); @@ -232,7 +232,7 @@ public interface RecipeHelper { boolean arePluginsLoading(); interface ScreenClickArea { - Class getScreenClass(); + Class getScreenClass(); Rectangle getRectangle(); diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Slot.java b/src/main/java/me/shedaniel/rei/api/widgets/Slot.java index b5db286aa..285dddd22 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/Slot.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/Slot.java @@ -23,9 +23,11 @@ package me.shedaniel.rei.api.widgets; +import me.shedaniel.math.Point; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.List; @@ -123,5 +125,17 @@ public abstract class Slot extends WidgetWithBounds { public abstract List getEntries(); - public abstract QueuedTooltip getCurrentTooltip(int mouseX, int mouseY); + /** + * @deprecated use {@link #getCurrentTooltip(Point)} + */ + @Nullable + @Deprecated + public QueuedTooltip getCurrentTooltip(int mouseX, int mouseY) { + return null; + } + + @Nullable + public Tooltip getCurrentTooltip(Point point) { + return getCurrentTooltip(point.x, point.y); + } } diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java b/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java new file mode 100644 index 000000000..147fcbf37 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/widgets/Tooltip.java @@ -0,0 +1,59 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.widgets; + +import me.shedaniel.math.Point; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.gui.widget.QueuedTooltip; + +import java.util.Collection; +import java.util.List; + +public interface Tooltip { + static Tooltip create(Point point, Collection texts) { + return QueuedTooltip.create(point, texts); + } + + static Tooltip create(Point point, String... texts) { + return QueuedTooltip.create(point, texts); + } + + static Tooltip create(Collection texts) { + return QueuedTooltip.create(texts); + } + + static Tooltip create(String... texts) { + return QueuedTooltip.create(texts); + } + + int getX(); + + int getY(); + + List getText(); + + default void queue() { + REIHelper.getInstance().queueTooltip(this); + } +} diff --git a/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java b/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java index 286120716..da1f1ad02 100644 --- a/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java +++ b/src/main/java/me/shedaniel/rei/api/widgets/Widgets.java @@ -43,96 +43,127 @@ import java.util.function.Consumer; public final class Widgets { private Widgets() {} - public static Widget createDrawableWidget(DrawableConsumer drawable) { + @NotNull + public static Widget createDrawableWidget(@NotNull DrawableConsumer drawable) { return new DrawableWidget(drawable); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds) { return createTexturedWidget(identifier, bounds, 0, 0); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, int width, int height) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, int width, int height) { return createTexturedWidget(identifier, x, y, 0, 0, width, height); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds, float u, float v) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds, float u, float v) { return createTexturedWidget(identifier, bounds, u, v, 256, 256); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, float u, float v, int width, int height) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, float u, float v, int width, int height) { return createTexturedWidget(identifier, x, y, u, v, width, height, 256, 256); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds, float u, float v, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds, float u, float v, int textureWidth, int textureHeight) { return createTexturedWidget(identifier, bounds.x, bounds.y, u, v, bounds.width, bounds.height, bounds.width, bounds.height, textureWidth, textureHeight); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) { return createTexturedWidget(identifier, x, y, u, v, width, height, width, height, textureWidth, textureHeight); } - public static Widget createTexturedWidget(Identifier identifier, Rectangle bounds, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, @NotNull Rectangle bounds, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight) { return createTexturedWidget(identifier, bounds.x, bounds.y, u, v, bounds.width, bounds.height, uWidth, vHeight, textureWidth, textureHeight); } - public static Widget createTexturedWidget(Identifier identifier, int x, int y, float u, float v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight) { + @NotNull + public static Widget createTexturedWidget(@NotNull Identifier identifier, int x, int y, float u, float v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight) { return createDrawableWidget(new TexturedDrawableConsumer(identifier, x, y, width, height, u, v, uWidth, vHeight, textureWidth, textureHeight)); } - public static Widget createFilledRectangle(Rectangle rectangle, int color) { + @NotNull + public static Widget createFilledRectangle(@NotNull Rectangle rectangle, int color) { return createDrawableWidget(new FillRectangleDrawableConsumer(rectangle, color)); } - public static Label createLabel(Point point, @NotNull String text) { + @NotNull + public static Label createLabel(@NotNull Point point, @NotNull String text) { return new LabelWidget(point, text); } - public static Label createClickableLabel(Point point, @NotNull String text, @Nullable Consumer