Item Utilities
Allows parsing Items and Item Stacks
Introduction
A fully functional Version of this class has first been introduced in Version 2.1.0
The Item Utilities class allows you parse Items and Item Stacks from Strings or vice versa.
Class
File: ItemUtils.java
Package: dev.soncresityindustries.es.api.v0.util
Methods
getItemOrDefault
public static Item getItemOrDefault(String itemID, @NotNull Item defaultItem) {}Returns the defaultItem value if the method runs into an error (e.g. itemID does not match an Item in Minecraft) otherwise returns the parsed Item from the itemID.
Usage
Item item = ItemUtils.getItemOrDefault(itemID, defaultItem);getItem (from String)
public static Item getItem(@NotNull String itemID) {}Returns the parsed Item from the itemID.
Throws NoSuchElementException if the item can't be parsed.
Usage
Item item = ItemUtils.getItem(itemID, defaultItem);getItem (from Identifier / ResourceLocation)
public static Item getItem(@NotNull Identifier identifier) {}Returns the parsed Item from the itemID.
Usage
Item item = ItemUtils.getItem(identifier);Tip
You can use Identifier.fromNamespaceAndPath(<ID (String)>) (MC >=1.21.11) / ResourceLocation.fromNamespaceAndPath(<ID (String)>) (MC <1.21.11) as an input as well.
getItemStackOrDefault (with count)
public static ItemStack getItemStackOrDefault(@NotNull String itemID, int count, @NotNull ItemStack defaultItemStack) {}Returns the defaultItemStack value if the method runs into an error (e.g. itemID does not match an Item in Minecraft) otherwise returns the parsed ItemStack with the provided count amount.
Usage
ItemStack itemStack = ItemUtils.getItemStackOrDefault(itemID, count, defaultItemStack);getItemStackOrDefault
public static ItemStack getItemStackOrDefault(@NotNull String itemID, @NotNull ItemStack defaultItemStack) {}Returns the defaultItemStack value if the method runs into an error (e.g. itemID does not match an Item in Minecraft) otherwise returns the parsed ItemStack with the amount of 1.
Refer to getItemStackOrDefault (with count) to customize the returned amount of items in the ItemStack.
Usage
ItemStack itemStack = ItemUtils.getItemStackOrDefault(itemID, defaultItemStack);getItemStack (with count)
public static ItemStack getItemStack(@NotNull String itemID, int count) {}Returns the parsed ItemStack from the itemID with the amount of 1.
Usage
ItemStack itemStack = ItemUtils.getItemStack(itemID, count);getItemStack
public static ItemStack getItemStack(@NotNull String itemID) {}Returns the defaultItemStack value if the method runs into an error (e.g. itemID does not match an Item in Minecraft) otherwise returns the parsed ItemStack with the amount of 1.
Refer to getItemStack (with count) to customize the returned amount of items in the ItemStack.
Usage
ItemStack itemStack = ItemUtils.getItemStack(itemID);getItemIDOrDefault (from ItemStack)
public static String getItemIDOrDefault(@NotNull ItemStack itemStack, @NotNull String defaultItemID) {}Returns the defaultItemID value if the method runs into an error otherwise returns the full Item ID of an ItemStack as a String.
Usage
String itemID = ItemUtils.getItemIDOrDefault(itemStack, defaultItemID);getItemIDOrDefault (from Item)
public static String getItemIDOrDefault(@NotNull Item item, @NotNull String defaultItemID) {}Returns the defaultItemID value if the method runs into an error otherwise returns the full Item ID of an Item as a String.
Usage
String itemID = ItemUtils.getItemIDOrDefault(item, defaultItemID);