From da332633984ba3e3872c61a2d407cccd0fa08a56 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:29:26 +0300 Subject: Add ItemIcon constructor with Item --- .../cottonmc/cotton/gui/widget/icon/ItemIcon.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/main') 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) -- cgit