Package net.notcoded.codelib.util.item
Class ItemStackUtil
java.lang.Object
net.notcoded.codelib.util.item.ItemStackUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidenchant(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.item.enchantment.Enchantment enchantment, int level) Enchants an ItemStack with an enchantment and level.static net.minecraft.world.item.ItemStackgetContainerClickItem(net.minecraft.server.level.ServerPlayer player, net.minecraft.network.protocol.game.ServerboundContainerClickPacket packet) Gets the ItemStack in the player's container clickstatic ArrayList<net.minecraft.world.item.ItemStack>getInvItems(net.minecraft.server.level.ServerPlayer player) Gets all the ItemStacks in the player's inventory.static booleanhasItem(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.Item item) Checks if the inventory has the item.static booleanhasRoomFor(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.ItemStack itemStack) Checks if the inventory has enough room to store an item.static booleanisSameItem(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2) Checks if the inventory has the same item.static net.minecraft.world.item.ItemitemFromString(String name) Gets the item name, e.g.static StringitemStackToString(net.minecraft.world.item.ItemStack itemStack, boolean reversible) Gets the ItemStack name, e.g.static net.minecraft.world.item.ItemStackstringToItemStack(String string) Turns a string into an ItemStack, e.g.
-
Constructor Details
-
ItemStackUtil
public ItemStackUtil()
-
-
Method Details
-
hasRoomFor
public static boolean hasRoomFor(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.ItemStack itemStack) Checks if the inventory has enough room to store an item.- Returns:
- If the inventory has room for the item.
-
hasItem
public static boolean hasItem(net.minecraft.world.entity.player.Inventory inventory, net.minecraft.world.item.Item item) Checks if the inventory has the item.- Returns:
- If the inventory has the item.
-
isSameItem
public static boolean isSameItem(net.minecraft.world.item.ItemStack itemStack1, net.minecraft.world.item.ItemStack itemStack2) Checks if the inventory has the same item.- Parameters:
itemStack2- The original ItemStack.itemStack1- The ItemStack that's going to get compared.- Returns:
- If the inventory has the same item.
-
stringToItemStack
Turns a string into an ItemStack, e.g. diamond_sword.- Parameters:
string- Name, e.g. diamond_sword.- Returns:
- ItemStack.
-
itemStackToString
public static String itemStackToString(net.minecraft.world.item.ItemStack itemStack, boolean reversible) Gets the ItemStack name, e.g. iron_block.- Parameters:
itemStack- ItemStack.reversible- If the String can be turned back into an ItemStack with stringToItemStack.- Returns:
- ItemStack name.
-
getInvItems
public static ArrayList<net.minecraft.world.item.ItemStack> getInvItems(net.minecraft.server.level.ServerPlayer player) Gets all the ItemStacks in the player's inventory.- Parameters:
player- The player.- Returns:
- ItemStacks in ArrayList.
-
itemFromString
Gets the item name, e.g. diamond_sword.- Parameters:
name- The name.- Returns:
- The Item (nullable).
-
enchant
public static void enchant(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.item.enchantment.Enchantment enchantment, int level) Enchants an ItemStack with an enchantment and level. -
getContainerClickItem
public static net.minecraft.world.item.ItemStack getContainerClickItem(net.minecraft.server.level.ServerPlayer player, net.minecraft.network.protocol.game.ServerboundContainerClickPacket packet) Gets the ItemStack in the player's container click- Returns:
- ItemStack.
-