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 longAn arbitrary, negative long used to delay the opening of virtual inventories until the client is likely ready for it.static final org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanacceptsAsInput(GeyserSession session, org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay slotDisplay, GeyserItemStack itemStack) Returns if the provided item stack would be accepted by the slot display.static booleancanStack(GeyserItemStack item1, GeyserItemStack item2) static voidcloseInventory(GeyserSession session, int javaId, boolean confirm) Closes the inventory that matches the java id.static voidcloseInventory(GeyserSession session, InventoryHolder<?> holder, 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 StringdebugInventory(@Nullable InventoryHolder<? extends Inventory> holder) static voiddisplayInventory(InventoryHolder<?> holder) Prepares and displays the current 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 @Nullable ClickgetClickForHotbarSwap(int slot) static @Nullable InventoryHolder<?>getInventory(GeyserSession session, int javaId) A util method to get an (open) inventory based on a Java id.static IntFunction<org.cloudburstmc.protocol.bedrock.data.inventory.ItemData>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 voidopenAndUpdateInventory(InventoryHolder<?> holder) Opens and updates an inventorystatic voidopenInventory(InventoryHolder<?> holder) The main entrypoint to open an inventory.static voidopenPendingInventory(GeyserSession session) Called when the Bedrock client is ready to open a pending inventory.static voidsendJavaContainerClose(InventoryHolder<? extends Inventory> holder) 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 -
MAGIC_VIRTUAL_INVENTORY_HACK
public static final long MAGIC_VIRTUAL_INVENTORY_HACKAn arbitrary, negative long used to delay the opening of virtual inventories until the client is likely ready for it. TheBedrockNetworkStackLatencyTranslatorwill then callopenPendingInventory(GeyserSession), which would finish opening the inventory.- See Also:
-
-
Constructor Details
-
InventoryUtils
public InventoryUtils()
-
-
Method Details
-
openInventory
The main entrypoint to open an inventory. It will mark inventories as pending when the client isn't ready to open the new inventory yet.- Parameters:
holder- the new inventory to open
-
openPendingInventory
Called when the Bedrock client is ready to open a pending inventory. Due to the nature of possible changes in the delayed time, this method also re-checks for changes that might have occurred in the time. For example, a queued virtual inventory might be "outdated", so we wouldn't open it. -
displayInventory
Prepares and displays the current inventory. If necessary, it will queue the opening of virtual inventories.- Parameters:
holder- the inventory to display
-
openAndUpdateInventory
Opens and updates an inventory -
closeInventory
Closes the inventory that matches the java id.- Parameters:
session- the session to close the inventory forjavaId- the id of the inventory to closeconfirm- whether to wait for the session to process the close before opening a new inventory.
-
closeInventory
public static void closeInventory(GeyserSession session, InventoryHolder<?> holder, boolean confirm) -
getInventory
A util method to get an (open) inventory based on a Java id. This method should be used overGeyserSession.getOpenInventory()(orGeyserSession.getInventoryHolder()) to account for an edge-case where the Java server expects Geyser to have the player inventory open while we're using a virtual lectern for theClientboundOpenBookPacket. -
sendJavaContainerClose
-
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() -
getTotemOfUndying
public static IntFunction<org.cloudburstmc.protocol.bedrock.data.inventory.ItemData> getTotemOfUndying() -
getClickForHotbarSwap
-
acceptsAsInput
public static boolean acceptsAsInput(GeyserSession session, org.geysermc.mcprotocollib.protocol.data.game.recipe.display.slot.SlotDisplay slotDisplay, GeyserItemStack itemStack) Returns if the provided item stack would be accepted by the slot display. -
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
-
debugInventory
-