Package org.geysermc.geyser.util
Class InventoryUtils
java.lang.Object
org.geysermc.geyser.util.InventoryUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intStores the last used recipe network ID.static final org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanStack(GeyserItemStack item1, GeyserItemStack item2) static voidcloseInventory(GeyserSession session, int javaId, boolean confirm) static IntFunction<org.cloudburstmc.protocol.bedrock.data.inventory.ItemData>createUnusableSpaceBlock(String description) Returns a barrier block with custom name and lore to explain why part of the inventory is unusable.static voiddisplayInventory(GeyserSession session, Inventory inventory) static @Nullable org.cloudburstmc.math.vector.Vector3ifindAvailableWorldSpace(GeyserSession session) Finds a usable block space in the world to place a fake inventory block, and returns the position.static voidfindOrCreateItem(GeyserSession session, String itemName) Attempt to find the specified item name in the session's inventory.static voidfindOrCreateItem(GeyserSession session, org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack itemStack) static @Nullable ClickgetClickForHotbarSwap(int slot) static @Nullable InventorygetInventory(GeyserSession session, int javaId) static IntFunction<org.cloudburstmc.protocol.bedrock.data.inventory.ItemData>static @Nullable GeyserRecipegetValidRecipe(GeyserSession session, @Nullable org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack output, IntFunction<GeyserItemStack> inventoryGetter, int gridDimensions, int firstRow, int height, int firstCol, int width) Test all known recipes to find a valid matchstatic booleanisEmpty(@Nullable org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack itemStack) Checks to see if an item stack represents air or has no count.static voidopenInventory(GeyserSession session, Inventory inventory) static voidupdateCursor(GeyserSession session)
-
Field Details
-
LAST_RECIPE_NET_ID
public static int LAST_RECIPE_NET_IDStores the last used recipe network ID. Since 1.16.200 (and for server-authoritative inventories), each recipe needs a unique network ID (or else in .200 the client crashes). -
REFRESH_ITEM
public static final org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack REFRESH_ITEM
-
-
Constructor Details
-
InventoryUtils
public InventoryUtils()
-
-
Method Details
-
openInventory
-
displayInventory
-
closeInventory
-
getInventory
-
findAvailableWorldSpace
public static @Nullable org.cloudburstmc.math.vector.Vector3i findAvailableWorldSpace(GeyserSession session) Finds a usable block space in the world to place a fake inventory block, and returns the position. -
updateCursor
-
canStack
-
isEmpty
@Contract("null -> true") public static boolean isEmpty(@Nullable org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack itemStack) Checks to see if an item stack represents air or has no count. -
createUnusableSpaceBlock
public static IntFunction<org.cloudburstmc.protocol.bedrock.data.inventory.ItemData> createUnusableSpaceBlock(String description) Returns a barrier block with custom name and lore to explain why part of the inventory is unusable.- Parameters:
description- the description- Returns:
- the unusable space block
-
getUpgradeTemplate
public static IntFunction<org.cloudburstmc.protocol.bedrock.data.inventory.ItemData> getUpgradeTemplate() -
findOrCreateItem
public static void findOrCreateItem(GeyserSession session, org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack itemStack) SeefindOrCreateItem(GeyserSession, String). This is for finding a specifiedItemStack.- Parameters:
session- the Bedrock client's sessionitemStack- the item to try to find a match for. NBT will also be accounted for.
-
findOrCreateItem
Attempt to find the specified item name in the session's inventory. If it is found and in the hotbar, set the user's held item to that slot. If it is found in another part of the inventory, move it. If it is not found and the user is in creative mode, create the item, overriding the current item slot if no other hotbar slots are empty, or otherwise selecting the empty slot.This attempts to mimic Java Edition behavior as best as it can.
- Parameters:
session- the Bedrock client's sessionitemName- the Java identifier of the item to search/select
-
getClickForHotbarSwap
-
getValidRecipe
public static @Nullable GeyserRecipe getValidRecipe(GeyserSession session, @Nullable org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack output, IntFunction<GeyserItemStack> inventoryGetter, int gridDimensions, int firstRow, int height, int firstCol, int width) Test all known recipes to find a valid match- Parameters:
output- if not null, the recipe has to output this item
-