aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorfrqnny <45723631+frqnny@users.noreply.github.com>2021-06-22 12:19:07 -0400
committerGitHub <noreply@github.com>2021-06-22 19:19:07 +0300
commita8a2d36a9bb32fe15a391a65666717ed26e0eb70 (patch)
tree43ed80f3884fce5b9ad9a2d3d2718f5280cfab31 /src/main/java
parent8d7ddd12a2226a54533b68cdc9294e6118585c3b (diff)
downloadLibGui-a8a2d36a9bb32fe15a391a65666717ed26e0eb70.tar.gz
LibGui-a8a2d36a9bb32fe15a391a65666717ed26e0eb70.tar.bz2
LibGui-a8a2d36a9bb32fe15a391a65666717ed26e0eb70.zip
Add Icon API to WItemSlot (#119)
* Add Icon API to WItemSlot * Fix checkstyle * Clean up test description
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java28
1 files changed, 28 insertions, 0 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 1667bee..e1f0bce 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
@@ -12,6 +12,7 @@ import net.minecraft.screen.slot.SlotActionType;
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.jetbrains.annotations.Nullable;
import java.util.ArrayList;
@@ -62,6 +63,8 @@ public class WItemSlot extends WWidget {
@Nullable
@Environment(EnvType.CLIENT)
private BackgroundPainter backgroundPainter = null;
+ @Nullable
+ private Icon icon = null;
private Inventory inventory;
private int startIndex = 0;
private int slotsWide = 1;
@@ -149,6 +152,27 @@ public class WItemSlot extends WWidget {
}
/**
+ * Sets the icon to this slot. Can be used for labeling slots for certain activities.
+ *
+ * @param icon the icon
+ * @since 4.0.0
+ */
+ public WItemSlot setIcon(@Nullable Icon icon) {
+ this.icon = icon;
+ return this;
+ }
+
+ /**
+ *
+ * @return icon if set, otherwise null
+ * @since 4.0.0
+ */
+ @Nullable
+ public Icon getIcon() {
+ return this.icon;
+ }
+
+ /**
* Returns true if the contents of this {@code WItemSlot} can be modified by players.
*
* @return true if items can be inserted into or taken from this slot widget, false otherwise
@@ -330,6 +354,10 @@ public class WItemSlot extends WWidget {
if (backgroundPainter != null) {
backgroundPainter.paintBackground(matrices, x, y, this);
}
+
+ if (icon != null) {
+ icon.paint(matrices, x + 1, y + 1, 16);
+ }
}
@Nullable