diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-10-18 16:29:26 +0300 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-10-18 16:35:42 +0300 |
commit | da332633984ba3e3872c61a2d407cccd0fa08a56 (patch) | |
tree | 6f66196dc4135c061dde1cc8a343040b7a57f50b | |
parent | 4a4a5291f26f6798f5e048b649f05ad682efd5f9 (diff) | |
download | LibGui-da332633984ba3e3872c61a2d407cccd0fa08a56.tar.gz LibGui-da332633984ba3e3872c61a2d407cccd0fa08a56.tar.bz2 LibGui-da332633984ba3e3872c61a2d407cccd0fa08a56.zip |
Add ItemIcon constructor with Item
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/icon/ItemIcon.java | 17 |
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) |