From 1d75b59eaf6ab3a1d73457f5fffe56f23bf1a5f1 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Tue, 22 Jun 2021 19:33:57 +0300 Subject: Minor tweaks to WItemSlot.get/setIcon - JD improvements - Fixed @'since tags - Warning when you're setting an icon for a widget with more than 1 visible slot --- .../cottonmc/cotton/gui/widget/WItemSlot.java | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java index e1f0bce..f25a2f2 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java @@ -13,6 +13,8 @@ import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.ValidatedSlot; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.widget.icon.Icon; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -58,6 +60,7 @@ import java.util.function.Predicate; * */ public class WItemSlot extends WWidget { + private static final Logger LOGGER = LogManager.getLogger(); private static final Predicate DEFAULT_FILTER = stack -> true; private final List peers = new ArrayList<>(); @Nullable @@ -152,24 +155,31 @@ public class WItemSlot extends WWidget { } /** - * Sets the icon to this slot. Can be used for labeling slots for certain activities. + * {@return the icon if set, otherwise null} * - * @param icon the icon - * @since 4.0.0 + * @since 4.1.0 */ - public WItemSlot setIcon(@Nullable Icon icon) { - this.icon = icon; - return this; + @Nullable + public Icon getIcon() { + return this.icon; } /** + * Sets the icon to this slot. Can be used for labeling slots for certain activities. * - * @return icon if set, otherwise null - * @since 4.0.0 + * @param icon the icon + * @return this slot widget + * @since 4.1.0 */ - @Nullable - public Icon getIcon() { - return this.icon; + public WItemSlot setIcon(@Nullable Icon icon) { + this.icon = icon; + + if (icon != null && (slotsWide * slotsHigh) > 1) { + // TODO: Should these types of warnings be visible in the screen itself in a dev env? + LOGGER.warn("Setting icon {} for item slot {} with more than 1 slot ({})", icon, this, slotsWide * slotsHigh); + } + + return this; } /** -- cgit