aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-10-18 16:29:26 +0300
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-10-18 16:35:42 +0300
commitda332633984ba3e3872c61a2d407cccd0fa08a56 (patch)
tree6f66196dc4135c061dde1cc8a343040b7a57f50b /src/main/java/io
parent4a4a5291f26f6798f5e048b649f05ad682efd5f9 (diff)
downloadLibGui-da332633984ba3e3872c61a2d407cccd0fa08a56.tar.gz
LibGui-da332633984ba3e3872c61a2d407cccd0fa08a56.tar.bz2
LibGui-da332633984ba3e3872c61a2d407cccd0fa08a56.zip
Add ItemIcon constructor with Item
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
index 3ce8eaa..2abe617 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java
@@ -6,8 +6,11 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import java.util.Objects;
+
/**
* An icon that draws an item stack.
*
@@ -20,9 +23,21 @@ public class ItemIcon implements Icon {
* Constructs an item icon.
*
* @param stack the drawn item stack
+ * @throws NullPointerException if the stack is null
*/
public ItemIcon(ItemStack stack) {
- this.stack = stack;
+ this.stack = Objects.requireNonNull(stack, "stack");
+ }
+
+ /**
+ * Constructs an item icon with the item's default stack.
+ *
+ * @param item the drawn item
+ * @throws NullPointerException if the item is null
+ * @since 3.2.0
+ */
+ public ItemIcon(Item item) {
+ this(Objects.requireNonNull(item, "item").getStackForRender());
}
@Environment(EnvType.CLIENT)