Package net.xun.lib.common.api.util
Class PlayerInventoryUtils
java.lang.Object
net.xun.lib.common.api.util.PlayerInventoryUtils
Specific utilities for managing player inventory, disable client-side by default
Methods for operating player inventory including:
- Checking and managing items in player's hands
- Searching and removing items from specific inventory sections
- Swapping or clearing items in hands
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddItemToHands(@NotNull net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.world.item.ItemStack item) Attempts to add the item to the player's main hand or offhand, whichever is empty first.static voidclearBothHands(@NotNull net.minecraft.world.entity.player.Player player) Clears both the main hand and offhand of the player.static voidextractItems(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, int amount, InventorySection section, InventoryCycleOrder order) static voidextractSingleItem(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, InventorySection section, InventoryCycleOrder order) static voidfindFirstMatchingSlot(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, InventorySection section) static booleanhasEmptyHand(@NotNull net.minecraft.world.entity.player.Player player) Checks if either of the player's hands is empty.static booleanhasEmptyHand(@NotNull net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) static booleanhasItem(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, InventorySection section) static booleanhasItemCount(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, int minCount, InventorySection section) static voidinsertItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack) static voidsetItemInMainHand(@NotNull net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.world.item.ItemStack item) Sets the item in the player's main hand.static voidsetItemInOffHand(@NotNull net.minecraft.world.entity.player.Player player, @NotNull net.minecraft.world.item.ItemStack item) Sets the item in the player's offhand.static voidswapHands(@NotNull net.minecraft.world.entity.player.Player player) Swaps items between the player's main hand and offhand.
-
Constructor Details
-
PlayerInventoryUtils
public PlayerInventoryUtils()
-
-
Method Details
-
hasEmptyHand
public static boolean hasEmptyHand(@NotNull @NotNull net.minecraft.world.entity.player.Player player) Checks if either of the player's hands is empty.- Parameters:
player- Target player, not null- Returns:
- True if either hand has an empty stack
- Throws:
NullPointerException- if player is null
-
hasEmptyHand
public static boolean hasEmptyHand(@NotNull @NotNull net.minecraft.world.entity.player.Player player, net.minecraft.world.InteractionHand hand) -
hasItemCount
public static boolean hasItemCount(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, int minCount, InventorySection section) -
hasItem
public static boolean hasItem(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, InventorySection section) -
findFirstMatchingSlot
public static void findFirstMatchingSlot(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, InventorySection section) -
swapHands
public static void swapHands(@NotNull @NotNull net.minecraft.world.entity.player.Player player) Swaps items between the player's main hand and offhand.- Parameters:
player- The player whose hands should be swapped, not null- Throws:
NullPointerException- if player is null
-
setItemInMainHand
public static void setItemInMainHand(@NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.world.item.ItemStack item) Sets the item in the player's main hand.Replaces any existing item in the main hand.
- Parameters:
player- the target player, not nullitem- the item to set, not null- Throws:
NullPointerException- if player or item is null
-
setItemInOffHand
public static void setItemInOffHand(@NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.world.item.ItemStack item) Sets the item in the player's offhand.Replaces any existing item in the offhand.
- Parameters:
player- the target player, not nullitem- the item to set, not null- Throws:
NullPointerException- if player or item is null
-
clearBothHands
public static void clearBothHands(@NotNull @NotNull net.minecraft.world.entity.player.Player player) Clears both the main hand and offhand of the player.- Parameters:
player- the target player, not null- Throws:
NullPointerException- if player is null
-
addItemToHands
public static void addItemToHands(@NotNull @NotNull net.minecraft.world.entity.player.Player player, @NotNull @NotNull net.minecraft.world.item.ItemStack item) Attempts to add the item to the player's main hand or offhand, whichever is empty first.If both hands are occupied, the item is not added.
- Parameters:
player- the target player, not nullitem- the item to add, not null- Throws:
NullPointerException- if player or item is null
-
extractItems
public static void extractItems(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, int amount, InventorySection section, InventoryCycleOrder order) -
extractSingleItem
public static void extractSingleItem(net.minecraft.world.entity.player.Player player, InventoryPredicate predicate, InventorySection section, InventoryCycleOrder order) -
insertItem
public static void insertItem(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
-