Contents
- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- getContainerForItemPickup(Ref, Item, PlayerSettings, ComponentAccessor)
- getContainerForItemPickup(Ref, Item, PlayerSettings, PickupLocation, ComponentAccessor)
- smartMoveItem(Ref, int, int, int, SmartMoveType, PlayerSettings, ComponentAccessor)
- moveItem(Ref, int, int, int, int, int, ComponentAccessor)
- prepareAbilityCoreRemoval(Ref, ItemContainer, int, ComponentAccessor)
- moveItemFromCheckToInventory(Ref, ItemStack, ItemContainer, short, int, PlayerSettings, ComponentAccessor)
- takeAll(Ref, int, PlayerSettings, ComponentAccessor)
- takeAllWithPriority(Ref, ItemContainer, PlayerSettings, ComponentAccessor)
- putAll(Ref, int, ComponentAccessor)
- quickStack(Ref, int, ComponentAccessor)
- getSectionById(Ref, int, ComponentAccessor)
- containsBrokenItem(Ref, ComponentAccessor)
- dropAllItemStacks(Ref, ComponentAccessor)
- clear(Ref, ComponentAccessor)
- sortStorage(Ref, ComponentAccessor)
- getActiveSlot(Ref, int, ComponentAccessor)
- setActiveSlot(Ref, int, byte, ComponentAccessor)
- createEquipmentUpdate(Ref, ComponentAccessor, PlayerSettings, InventoryComponent.Armor, InventoryComponent.Utility)
Class InventoryUtils
java.lang.Object
com.hypixel.hytale.server.core.inventory.InventoryUtils
Static utility methods for reading from and mutating entity inventory state via the ECS component model.
All methods operate on InventoryComponent subtypes attached to an entity reference
and require a ComponentAccessor for component lookup.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear(Ref<EntityStore> ref, ComponentAccessor<EntityStore> accessor) Clears all item stacks from every inventory section on the entity (storage, armor, hotbar, utility, and backpack).static booleancontainsBrokenItem(Ref<EntityStore> ref, ComponentAccessor<EntityStore> accessor) Determines whether the given entity has a broken item in their inventory.static EquipmentUpdatecreateEquipmentUpdate(Ref<EntityStore> ref, ComponentAccessor<EntityStore> componentAccessor, PlayerSettings playerSettings, InventoryComponent.Armor armorComponent, InventoryComponent.Utility utilityComponent) Creates anEquipmentUpdatebased on the components from the provided entity.dropAllItemStacks(Ref<EntityStore> ref, ComponentAccessor<EntityStore> accessor) Drops all item stacks from every inventory section on the entity (storage, armor, hotbar, utility, and backpack).static bytegetActiveSlot(Ref<EntityStore> ref, int inventorySectionId, ComponentAccessor<EntityStore> componentAccessor) Fetches the active slot for the specified inventory section.static ItemContainergetContainerForItemPickup(Ref<EntityStore> ref, Item item, PlayerSettings playerSettings, ComponentAccessor<EntityStore> componentAccessor) Returns the appropriateItemContainerto placeiteminto when it is picked up, using the player's configured pickup preferences.static ItemContainergetContainerForItemPickup(Ref<EntityStore> ref, Item item, PlayerSettings playerSettings, PickupLocation overridePickupLocation, ComponentAccessor<EntityStore> componentAccessor) Returns the appropriateItemContainerto placeiteminto when it is picked up.static ItemContainergetSectionById(Ref<EntityStore> ref, int id, ComponentAccessor<EntityStore> componentAccessor) Returns theItemContainerfor the inventory section identified byidon the entity.static voidmoveItem(Ref<EntityStore> ref, int fromSectionId, int fromSlotId, int quantity, int toSectionId, int toSlotId, ComponentAccessor<EntityStore> componentAccessor) Movesquantityof an item from one inventory section and slot to another.static MoveTransaction<ItemStackTransaction> moveItemFromCheckToInventory(Ref<EntityStore> ref, ItemStack itemStack, ItemContainer targetContainer, short fromSlotId, int quantity, PlayerSettings settings, ComponentAccessor<EntityStore> componentAccessor) Movesquantityof the item atfromSlotIdintargetContainerinto the container determined bygetContainerForItemPickup(Ref, Item, PlayerSettings, ComponentAccessor)for the item's type.static booleanprepareAbilityCoreRemoval(Ref<EntityStore> ref, ItemContainer fromContainer, int fromSlotId, ComponentAccessor<EntityStore> componentAccessor) Enforces ability-line consistency when a line's Core rune leaves the ability slots without a replacement (quick-move, drop).putAll(Ref<EntityStore> ref, int inventorySectionId, ComponentAccessor<EntityStore> componentAccessor) Moves all items from the entity's storage inventory into the container identified byinventorySectionId.quickStack(Ref<EntityStore> ref, int inventorySectionId, ComponentAccessor<EntityStore> componentAccessor) Moves items from the hotbar (then storage) into the container identified byinventorySectionId, merging stacks where possible.static voidsetActiveSlot(Ref<EntityStore> ref, int inventorySectionId, byte slot, ComponentAccessor<EntityStore> componentAccessor) Deprecated.static voidsmartMoveItem(Ref<EntityStore> ref, int fromSectionId, int fromSlotId, int quantity, SmartMoveType moveType, PlayerSettings settings, ComponentAccessor<EntityStore> accessor) Performs a smart move of the item atfromSectionId/fromSlotIdaccording tomoveType.static voidsortStorage(Ref<EntityStore> ref, ComponentAccessor<EntityStore> accessor) Sorts the storage inventory by item type.takeAll(Ref<EntityStore> ref, int inventorySectionId, PlayerSettings settings, ComponentAccessor<EntityStore> componentAccessor) Moves all items from the container identified byinventorySectionIdinto the entity's inventory, respecting per-item-type pickup priority viasettings.takeAllWithPriority(Ref<EntityStore> ref, ItemContainer fromContainer, PlayerSettings settings, ComponentAccessor<EntityStore> componentAccessor) Moves all items fromfromContainerinto the entity's inventory, respecting per-item-type pickup priority viasettings.
-
Constructor Details
-
InventoryUtils
public InventoryUtils()
-
-
Method Details
-
getContainerForItemPickup
@Nonnull public static ItemContainer getContainerForItemPickup(@Nonnull Ref<EntityStore> ref, @Nonnull Item item, PlayerSettings playerSettings, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Returns the appropriateItemContainerto placeiteminto when it is picked up, using the player's configured pickup preferences. Delegates togetContainerForItemPickup(Ref, Item, PlayerSettings, PickupLocation, ComponentAccessor)with no override location.- Parameters:
ref- The entity reference of the associated entity.item- The item being picked up.playerSettings- The player's inventory pickup preferences.componentAccessor- TheComponentAccessorfor component access.- Returns:
- the container the item should be placed into.
-
getContainerForItemPickup
@Nonnull public static ItemContainer getContainerForItemPickup(@Nonnull Ref<EntityStore> ref, @Nonnull Item item, PlayerSettings playerSettings, @Nullable PickupLocation overridePickupLocation, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Returns the appropriateItemContainerto placeiteminto when it is picked up. IfoverridePickupLocationis non-null it is used directly; otherwise the container is chosen based on the item's type and the player's configured pickup preferences.- Parameters:
ref- The entity reference of the associated entity.item- The item being picked up.playerSettings- The player's inventory pickup preferences.overridePickupLocation- If non-null, bypasses per-item-type routing and uses this location directly.componentAccessor- TheComponentAccessorfor component access.- Returns:
- the container the item should be placed into.
-
smartMoveItem
public static void smartMoveItem(@Nonnull Ref<EntityStore> ref, int fromSectionId, int fromSlotId, int quantity, @Nonnull SmartMoveType moveType, PlayerSettings settings, @Nonnull ComponentAccessor<EntityStore> accessor) Performs a smart move of the item atfromSectionId/fromSlotIdaccording tomoveType. The behaviour varies by move type:SmartMoveType.EquipOrMergeStack— tries to equip the item as armor first; if that fails, merges the stack into any open windows and then into the full inventory.SmartMoveType.PutInHotbarOrWindow— moves items from windows to inventory, and from inventory sections to the opposing section (hotbar ↔ storage), trying open windows first for player entities.SmartMoveType.PutInHotbarOrBackpack— routes the item to the backpack when it originates outside the backpack, otherwise uses normal pickup priority.
- Parameters:
ref- The entity reference of the associated entity.fromSectionId- The section ID of the container the item is being moved from.fromSlotId- The slot index within that section.quantity- The quantity to move.moveType- The smart-move strategy to apply.settings- The player's inventory settings, used for pickup priority routing.accessor- TheComponentAccessorfor component access.
-
moveItem
public static void moveItem(@Nonnull Ref<EntityStore> ref, int fromSectionId, int fromSlotId, int quantity, int toSectionId, int toSlotId, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Movesquantityof an item from one inventory section and slot to another. For player entities, if the move involves the currently active hotbar slot, aSmartMoveType.EquipOrMergeStackinteraction chain is fired first so that item-swap interactions can run before the move completes. The move is skipped silently if either section is not found on the entity.- Parameters:
ref- The entity reference of the associated entity.fromSectionId- The section ID to move the item from.fromSlotId- The slot index within the source section.quantity- The quantity to move.toSectionId- The section ID to move the item to.toSlotId- The slot index within the destination section.componentAccessor- TheComponentAccessorfor component access.
-
prepareAbilityCoreRemoval
public static boolean prepareAbilityCoreRemoval(@Nonnull Ref<EntityStore> ref, @Nonnull ItemContainer fromContainer, int fromSlotId, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Enforces ability-line consistency when a line's Core rune leaves the ability slots without a replacement (quick-move, drop). The line's supports are rehomed first (rune bag, then storage, then hotbar). When they cannot all be rehomed the removal is vetoed, and the ability slots plus any window backed by them resync the client's prediction.- Returns:
truewhen the removal may proceed.
-
moveItemFromCheckToInventory
@Nonnull public static MoveTransaction<ItemStackTransaction> moveItemFromCheckToInventory(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, @Nonnull ItemContainer targetContainer, short fromSlotId, int quantity, PlayerSettings settings, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Movesquantityof the item atfromSlotIdintargetContainerinto the container determined bygetContainerForItemPickup(Ref, Item, PlayerSettings, ComponentAccessor)for the item's type.- Parameters:
ref- The entity reference of the associated entity.itemStack- The item stack being moved, used to determine the destination container.targetContainer- The container the item is currently in.fromSlotId- The slot index withintargetContainerto move from.quantity- The quantity to move.settings- The player's inventory settings, used for pickup priority routing.componentAccessor- TheComponentAccessorfor component access.- Returns:
- the
MoveTransactiondescribing the result of the move.
-
takeAll
@Nullable public static ListTransaction<MoveTransaction<ItemStackTransaction>> takeAll(@Nonnull Ref<EntityStore> ref, int inventorySectionId, PlayerSettings settings, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Moves all items from the container identified byinventorySectionIdinto the entity's inventory, respecting per-item-type pickup priority viasettings. Returnsnullif the section is not found on the entity.- Parameters:
ref- The entity reference of the associated entity.inventorySectionId- The section ID of the container to take items from.settings- The player's inventory settings, used for pickup priority routing.componentAccessor- TheComponentAccessorfor component access.- Returns:
- a transaction listing each individual move, or
nullif the section was not found.
-
takeAllWithPriority
@Nonnull public static ListTransaction<MoveTransaction<ItemStackTransaction>> takeAllWithPriority(@Nonnull Ref<EntityStore> ref, ItemContainer fromContainer, PlayerSettings settings, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Moves all items fromfromContainerinto the entity's inventory, respecting per-item-type pickup priority viasettings.- Parameters:
ref- The entity reference of the associated entity.fromContainer- The container whose items should be moved.settings- The player's inventory settings, used for pickup priority routing.componentAccessor- TheComponentAccessorfor component access.- Returns:
- a transaction listing each individual move.
-
putAll
@Nullable public static ListTransaction<MoveTransaction<ItemStackTransaction>> putAll(@Nonnull Ref<EntityStore> ref, int inventorySectionId, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Moves all items from the entity's storage inventory into the container identified byinventorySectionId. Returnsnullif the target section or theInventoryComponent.Storagecomponent is not found on the entity.- Parameters:
ref- The entity reference of the associated entity.inventorySectionId- The section ID of the container to move items into.componentAccessor- TheComponentAccessorfor component access.- Returns:
- a transaction listing each individual move, or
nullif a required component was not found.
-
quickStack
@Nullable public static ListTransaction<MoveTransaction<ItemStackTransaction>> quickStack(@Nonnull Ref<EntityStore> ref, int inventorySectionId, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Moves items from the hotbar (then storage) into the container identified byinventorySectionId, merging stacks where possible. Returnsnullif the target section is not found on the entity.- Parameters:
ref- The entity reference of the associated entity.inventorySectionId- The section ID of the container to quick-stack items into.componentAccessor- TheComponentAccessorfor component access.- Returns:
- a transaction listing each individual move, or
nullif the section was not found.
-
getSectionById
@Nullable public static ItemContainer getSectionById(@Nonnull Ref<EntityStore> ref, int id, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Returns theItemContainerfor the inventory section identified byidon the entity. Negative IDs map to built-in inventory sections (seeInventoryComponent.HOTBAR_SECTION_IDand related constants); non-negative IDs are treated as open window IDs and are only resolved for player entities.- Parameters:
ref- The entity reference of the associated entity.id- The section ID to look up.componentAccessor- TheComponentAccessorfor component access.- Returns:
- the
ItemContainerfor the section, ornullif not found.
-
containsBrokenItem
public static boolean containsBrokenItem(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor) Determines whether the given entity has a broken item in their inventory.- Parameters:
ref- The entity reference of the entity to check.accessor- TheComponentAccessorfor component access.- Returns:
trueif the entity has a broken item in their inventory,falseotherwise.
-
dropAllItemStacks
@Nonnull public static List<ItemStack> dropAllItemStacks(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor) Drops all item stacks from every inventory section on the entity (storage, armor, hotbar, utility, and backpack).- Parameters:
ref- The entity reference.accessor- TheComponentAccessorfor component access.- Returns:
- a list of all dropped
ItemStacks.
-
clear
public static void clear(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor) Clears all item stacks from every inventory section on the entity (storage, armor, hotbar, utility, and backpack).- Parameters:
ref- The entity reference.accessor- TheComponentAccessorfor component access.
-
sortStorage
public static void sortStorage(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor) Sorts the storage inventory by item type.- Parameters:
ref- The entity reference.accessor- TheComponentAccessorfor component access.
-
getActiveSlot
public static byte getActiveSlot(@Nonnull Ref<EntityStore> ref, int inventorySectionId, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Fetches the active slot for the specified inventory section.- Parameters:
ref- The entity reference of the associated entity.inventorySectionId- The section ID of the inventory (must beInventoryComponent.HOTBAR_SECTION_ID,InventoryComponent.UTILITY_SECTION_ID, orInventoryComponent.TOOLS_SECTION_ID).componentAccessor- TheComponentAccessorfor component access.- Returns:
- the active slot index, or
InventoryComponent.INACTIVE_SLOT_INDEXif the corresponding component is not present on the entity. - Throws:
IllegalArgumentException- ifinventorySectionIddoes not support an active slot.
-
setActiveSlot
@Deprecated public static void setActiveSlot(@Nonnull Ref<EntityStore> ref, int inventorySectionId, byte slot, @Nonnull ComponentAccessor<EntityStore> componentAccessor) Deprecated.Make use ofActiveSlotInventoryComponent.setActiveSlot(byte, Ref, ComponentAccessor)instead.Sets the active slot for the specified inventory section and fires aInventorySetActiveSlotEventso registered systems can react (e.g. clearing tool state, recalculating entity stats).- Parameters:
ref- The entity reference of the associated entity.inventorySectionId- The ID of the inventory section to set the active slot for (e.g.InventoryComponent.HOTBAR_SECTION_ID).slot- The slot index to set as active.componentAccessor- TheComponentAccessorfor component access.- Throws:
IllegalArgumentException- ifinventorySectionIddoes not support an active slot.
-
createEquipmentUpdate
@Nonnull public static EquipmentUpdate createEquipmentUpdate(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nullable PlayerSettings playerSettings, @Nullable InventoryComponent.Armor armorComponent, @Nullable InventoryComponent.Utility utilityComponent) Creates anEquipmentUpdatebased on the components from the provided entity.- Parameters:
ref- The entity reference of the entity that we are creating the packet for.componentAccessor- TheComponentAccessor<EntityStore>for component access.playerSettings- The player settings component, ornullif the entity doesn't have one.armorComponent- TheInventoryComponent.Armorcomponent, ornullif the entity doesn't have one.utilityComponent- TheInventoryComponent.Utilitycomponent, ornullif the entity doesn't have one.- Returns:
- the constructed
EquipmentUpdatepacket.
-
ActiveSlotInventoryComponent.setActiveSlot(byte, Ref, ComponentAccessor)instead.