Skip to content

Player Inventory

The inventory system manages player item storage including hotbar, main storage, armor, utility slots, and backpack.

com.hypixel.hytale.server.core.inventory

Player inventory is divided into sections, each with a unique section ID. Each section is a separate InventoryComponent subclass registered as an ECS component on the EntityStore. Active slots track which item the player currently has selected in each section.

Section IDConstantCapacityPurpose
-1HOTBAR_SECTION_ID9Main hotbar (0-8)
-2STORAGE_SECTION_ID36Main storage (4x9 grid)
-3ARMOR_SECTION_ID6Armor equipment
-5UTILITY_SECTION_ID4Consumables (food, potions)
-8TOOLS_SECTION_ID23Tools (deprecated)
-9BACKPACK_SECTION_IDVariableExpandable storage

Each inventory section is a separate InventoryComponent subclass registered as an ECS component:

package com.hypixel.hytale.server.core.inventory;
public abstract class InventoryComponent implements Component<EntityStore> {
public ItemContainer getInventory();
public void ensureCapacity(short capacity, List<ItemStack> remainder);
public void markDirty();
public boolean consumeIsDirty();
public boolean consumeNeedsSaving();
}
SubclassComponentType accessorActive slot
InventoryComponent.HotbarInventoryComponent.Hotbar.getComponentType()getActiveSlot() / setActiveSlot(byte)
InventoryComponent.StorageInventoryComponent.Storage.getComponentType()
InventoryComponent.ArmorInventoryComponent.Armor.getComponentType()
InventoryComponent.UtilityInventoryComponent.Utility.getComponentType()getActiveSlot() / setActiveSlot(byte)
InventoryComponent.BackpackInventoryComponent.Backpack.getComponentType()
InventoryComponent.ToolInventoryComponent.Tool.getComponentType()getActiveSlot() / setActiveSlot(byte)
InventoryComponent.CombinedInventoryComponent.Combined.getComponentType()

Use the static getCombined() method to build a CombinedItemContainer from multiple component types:

CombinedItemContainer combined = InventoryComponent.getCombined(
accessor, ref, InventoryComponent.HOTBAR_FIRST
);

Predefined ordering arrays:

ArraySections (in order)
HOTBAR_FIRSTHotbar, Storage
STORAGE_FIRSTStorage, Hotbar
HOTBAR_STORAGE_BACKPACKHotbar, Storage, Backpack
BACKPACK_STORAGE_HOTBARBackpack, Storage, Hotbar
ARMOR_HOTBAR_UTILITY_STORAGEArmor, Hotbar, Utility, Storage
EVERYTHINGArmor, Hotbar, Utility, Storage, Backpack
ItemStack heldItem = InventoryComponent.getItemInHand(accessor, ref);

This checks the Tool component first, then falls back to the Hotbar component.

InventoryChangeEvent is an ECS event fired when an inventory component changes. It replaces the former LivingEntityInventoryChangeEvent.

package com.hypixel.hytale.server.core.inventory;
public class InventoryChangeEvent extends EcsEvent {
public ComponentType<EntityStore, ? extends InventoryComponent> getComponentType();
public InventoryComponent getInventory();
public ItemContainer getItemContainer();
public Transaction getTransaction();
}

The Inventory class still exists as a thin wrapper that delegates to the component system:

package com.hypixel.hytale.server.core.inventory;
@Deprecated(forRemoval = true)
public class Inventory {
public static final int HOTBAR_SECTION_ID = -1;
public static final int STORAGE_SECTION_ID = -2;
public static final int ARMOR_SECTION_ID = -3;
public static final int UTILITY_SECTION_ID = -5;
public static final int TOOLS_SECTION_ID = -8;
public static final int BACKPACK_SECTION_ID = -9;
public ItemContainer getHotbar();
public ItemContainer getStorage();
public ItemContainer getArmor();
public ItemContainer getUtility();
public ItemContainer getTools();
public ItemContainer getBackpack();
public ItemContainer getSectionById(int sectionId);
public byte getActiveHotbarSlot();
public void setActiveHotbarSlot(
Ref<EntityStore> ref, byte slot,
ComponentAccessor<EntityStore> componentAccessor
);
public ItemStack getActiveHotbarItem();
public ItemStack getItemInHand();
public byte getActiveUtilitySlot();
public void setActiveUtilitySlot(
Ref<EntityStore> ref, byte slot,
ComponentAccessor<EntityStore> componentAccessor
);
public ItemStack getUtilityItem();
public void moveItem(
int fromSectionId, int fromSlotId,
int quantity,
int toSectionId, int toSlotId
);
public void smartMoveItem(
Ref<EntityStore> ref,
int fromSectionId, int fromSlotId,
int quantity,
SmartMoveType moveType,
PlayerSettings settings,
ComponentAccessor<EntityStore> accessor
);
public List<ItemStack> dropAllItemStacks();
public void clear();
}

The armor section has 6 slots corresponding to ItemArmorSlot:

Slot IndexPosition
0Head
1Chest
2Legs
3Feet
4Cape
5Accessory
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
// access via ECS component system
Ref<EntityStore> ref = /* entity reference */;
ComponentAccessor<EntityStore> accessor = /* accessor */;
InventoryComponent.Hotbar hotbar = accessor.getComponent(
ref, InventoryComponent.Hotbar.getComponentType()
);
InventoryComponent.Storage storage = accessor.getComponent(
ref, InventoryComponent.Storage.getComponentType()
);
InventoryComponent.Armor armor = accessor.getComponent(
ref, InventoryComponent.Armor.getComponentType()
);
// access underlying item container
if (hotbar != null) {
ItemContainer hotbarContainer = hotbar.getInventory();
}
// get currently held item (checks Tool then Hotbar component)
ItemStack heldItem = InventoryComponent.getItemInHand(accessor, ref);
// get active hotbar slot (0-8)
InventoryComponent.Hotbar hotbar = accessor.getComponent(
ref, InventoryComponent.Hotbar.getComponentType()
);
if (hotbar != null) {
byte activeSlot = hotbar.getActiveSlot();
ItemStack activeItem = hotbar.getActiveItem();
hotbar.setActiveSlot((byte) 3);
}
// utility items
InventoryComponent.Utility utility = accessor.getComponent(
ref, InventoryComponent.Utility.getComponentType()
);
if (utility != null) {
ItemStack utilityItem = utility.getActiveItem();
utility.setActiveSlot((byte) 1);
}
// Move 1 item from hotbar slot 0 to storage slot 10
inventory.moveItem(
Inventory.HOTBAR_SECTION_ID, 0, // From
1, // Quantity
Inventory.STORAGE_SECTION_ID, 10 // To
);
// Move entire stack
ItemContainer hotbar = inventory.getHotbar();
ItemStack item = hotbar.getItemAt(0);
int quantity = item != null ? item.getQuantity() : 0;
inventory.moveItem(
Inventory.HOTBAR_SECTION_ID, 0,
quantity,
Inventory.STORAGE_SECTION_ID, 10
);
import com.hypixel.hytale.protocol.SmartMoveType;
import com.hypixel.hytale.server.core.modules.entity.player.PlayerSettings;
// Auto-equip armor or merge stacks
inventory.smartMoveItem(
ref,
Inventory.STORAGE_SECTION_ID, 15,
1,
SmartMoveType.EquipOrMergeStack,
playerSettings,
accessor
);
// Move to hotbar or open window container
inventory.smartMoveItem(
ref,
Inventory.STORAGE_SECTION_ID, 20,
1,
SmartMoveType.PutInHotbarOrWindow,
playerSettings,
accessor
);
// Take all items from a container (e.g., chest)
var takeTransaction = inventory.takeAll(externalContainerId, playerSettings);
// Put all storage items into container
var putTransaction = inventory.putAll(externalContainerId);
// Quick stack matching items to container
var quickTransaction = inventory.quickStack(externalContainerId);
// Drop all items (on death)
List<ItemStack> droppedItems = inventory.dropAllItemStacks();
// Clear entire inventory
inventory.clear();
import com.hypixel.hytale.server.core.inventory.InventoryComponent;
import com.hypixel.hytale.server.core.inventory.container.CombinedItemContainer;
// search hotbar first, then storage
CombinedItemContainer hotbarFirst = InventoryComponent.getCombined(
accessor, ref, InventoryComponent.HOTBAR_FIRST
);
// search everything (armor, hotbar, utility, storage, backpack)
CombinedItemContainer everything = InventoryComponent.getCombined(
accessor, ref, InventoryComponent.EVERYTHING
);
// iterate over combined container to find an item
for (short i = 0; i < everything.getCapacity(); i++) {
ItemStack stack = everything.getItemStack(i);
if (!ItemStack.isEmpty(stack) && stack.getItem().getId().equals("iron_sword")) {
// found the item at slot i
break;
}
}
// Get armor container
ItemContainer armor = inventory.getArmor();
// Get specific armor piece
ItemStack helmet = armor.getItemAt(0); // Head
ItemStack chest = armor.getItemAt(1); // Chest
ItemStack legs = armor.getItemAt(2); // Legs
ItemStack feet = armor.getItemAt(3); // Feet
ItemStack cape = armor.getItemAt(4); // Cape
ItemStack accessory = armor.getItemAt(5); // Accessory
// Check if slot is empty
if (armor.isEmpty(0)) {
// No helmet equipped
}
// get currently held item via the static helper
ItemStack heldItem = InventoryComponent.getItemInHand(accessor, ref);
if (heldItem != null) {
Item item = heldItem.getItem();
String itemId = item.getId();
int quantity = heldItem.getQuantity();
if (item.getWeapon() != null) {
// holding a weapon
} else if (item.getTool() != null) {
// holding a tool
} else if (item.getBlock() != null) {
// holding a placeable block
}
}

Options for intelligent item placement:

ValueTypeDescription
0EquipOrMergeStackTry to equip as armor first, then merge with existing stacks across hotbar and storage
1PutInHotbarOrWindowMove to hotbar or open window container; swaps between hotbar and storage if already in one of those
2PutInHotbarOrBackpackMove to hotbar first, falls back to backpack/storage/hotbar combined
  • Hotbar: 0-8 (9 slots)
  • Storage: 0-35 (36 slots, 4 rows x 9 columns)
  • Armor: 0-5 (Head, Chest, Legs, Feet, Cape, Accessory)
  • Utility: 0-3 (4 slots)
  • Inactive indicator: -1 (no active slot)