Player Inventory
Player Inventory
Section titled “Player Inventory”The inventory system manages player item storage including hotbar, main storage, armor, utility slots, and backpack.
Package Location
Section titled “Package Location”com.hypixel.hytale.server.core.inventory
Overview
Section titled “Overview”Player inventory is divided into sections, each with a unique section ID. Active slots track which item the player currently has selected in each section.
Inventory Sections
Section titled “Inventory Sections”| Section ID | Constant | Capacity | Purpose |
|---|---|---|---|
| -1 | HOTBAR_SECTION_ID | 9 | Main hotbar (0-8) |
| -2 | STORAGE_SECTION_ID | 36 | Main storage (4x9 grid) |
| -3 | ARMOR_SECTION_ID | 6 | Armor equipment |
| -5 | UTILITY_SECTION_ID | 4 | Consumables (food, potions) |
| -8 | TOOLS_SECTION_ID | 23 | Tools (deprecated) |
| -9 | BACKPACK_SECTION_ID | Variable | Expandable storage |
Core Class
Section titled “Core Class”Inventory
Section titled “Inventory”Main inventory management class:
package com.hypixel.hytale.server.core.inventory;
public class Inventory { // Section ID constants 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;
// Container access public ItemContainer getHotbar(); public ItemContainer getStorage(); public ItemContainer getArmor(); public ItemContainer getUtility(); public ItemContainer getTools(); public ItemContainer getBackpack(); public ItemContainer getSectionById(int sectionId);
// Active slot management - Hotbar public byte getActiveHotbarSlot(); public void setActiveHotbarSlot(byte slot); public ItemStack getActiveHotbarItem(); public ItemStack getItemInHand();
// Active slot management - Utility public byte getActiveUtilitySlot(); public void setActiveUtilitySlot(byte slot); public ItemStack getUtilityItem();
// Active slot management - Tools (deprecated) public byte getActiveToolsSlot(); public void setActiveToolsSlot(byte slot); public ItemStack getToolsItem();
// Item operations public void moveItem( int fromSectionId, int fromSlotId, int quantity, int toSectionId, int toSlotId );
public void smartMoveItem( int fromSectionId, int fromSlotId, int quantity, SmartMoveType moveType );
// Bulk operations public ListTransaction<MoveTransaction<ItemStackTransaction>> takeAll( int inventorySectionId );
public ListTransaction<MoveTransaction<ItemStackTransaction>> putAll( int inventorySectionId );
public ListTransaction<MoveTransaction<ItemStackTransaction>> quickStack( int inventorySectionId );
public List<ItemStack> dropAllItemStacks(); public void clear();
// Combined containers public CombinedItemContainer getCombinedHotbarFirst(); public CombinedItemContainer getCombinedStorageFirst(); public CombinedItemContainer getCombinedArmorHotbarStorage(); public CombinedItemContainer getCombinedEverything();}Armor Slots
Section titled “Armor Slots”The armor section has 6 slots corresponding to ItemArmorSlot:
| Slot Index | Position |
|---|---|
| 0 | Head |
| 1 | Chest |
| 2 | Legs |
| 3 | Feet |
| 4 | Cape |
| 5 | Accessory |
Usage Examples
Section titled “Usage Examples”Accessing Inventory Containers
Section titled “Accessing Inventory Containers”import com.hypixel.hytale.server.core.inventory.Inventory;import com.hypixel.hytale.server.core.entity.entities.Player;import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
// Get player inventoryPlayer player = /* player reference */;Inventory inventory = player.getInventory();
// Access containersItemContainer hotbar = inventory.getHotbar(); // 9 slotsItemContainer storage = inventory.getStorage(); // 36 slotsItemContainer armor = inventory.getArmor(); // 6 slotsItemContainer utility = inventory.getUtility(); // 4 slotsItemContainer backpack = inventory.getBackpack(); // Variable size
// Access by section IDItemContainer section = inventory.getSectionById(Inventory.HOTBAR_SECTION_ID);Working with Active Slots
Section titled “Working with Active Slots”// Get currently held item (main hand)ItemStack heldItem = inventory.getItemInHand();
// Get active hotbar slot (0-8)byte activeSlot = inventory.getActiveHotbarSlot();
// Change active slotinventory.setActiveHotbarSlot((byte) 3);
// Get specific hotbar itemItemStack hotbarItem = inventory.getActiveHotbarItem();
// Utility itemsItemStack utilityItem = inventory.getUtilityItem();inventory.setActiveUtilitySlot((byte) 1);Moving Items
Section titled “Moving Items”// Move 1 item from hotbar slot 0 to storage slot 10inventory.moveItem( Inventory.HOTBAR_SECTION_ID, 0, // From 1, // Quantity Inventory.STORAGE_SECTION_ID, 10 // To);
// Move entire stackItemContainer 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);Smart Move
Section titled “Smart Move”import com.hypixel.hytale.server.core.inventory.SmartMoveType;
// Auto-equip armor or merge stacksinventory.smartMoveItem( Inventory.STORAGE_SECTION_ID, 15, 1, SmartMoveType.EquipOrMergeStack);
// Move to hotbar if possible, otherwise storageinventory.smartMoveItem( Inventory.STORAGE_SECTION_ID, 20, 1, SmartMoveType.ToHotbar);Bulk Operations
Section titled “Bulk Operations”// Take all items from a container (e.g., chest)var takeTransaction = inventory.takeAll(externalContainerId);
// Put all storage items into containervar putTransaction = inventory.putAll(externalContainerId);
// Quick stack matching items to containervar quickTransaction = inventory.quickStack(externalContainerId);
// Drop all items (on death)List<ItemStack> droppedItems = inventory.dropAllItemStacks();
// Clear entire inventoryinventory.clear();Combined Containers
Section titled “Combined Containers”// Search hotbar first, then storageCombinedItemContainer hotbarFirst = inventory.getCombinedHotbarFirst();
// Search storage first, then hotbarCombinedItemContainer storageFirst = inventory.getCombinedStorageFirst();
// Search armor, hotbar, storageCombinedItemContainer armorHotbarStorage = inventory.getCombinedArmorHotbarStorage();
// Search everythingCombinedItemContainer everything = inventory.getCombinedEverything();
// Find item in combined containerItemStack foundItem = everything.findItem(item -> item.getItem().getId().equals("iron_sword"));Working with Armor
Section titled “Working with Armor”// Get armor containerItemContainer armor = inventory.getArmor();
// Get specific armor pieceItemStack helmet = armor.getItemAt(0); // HeadItemStack chest = armor.getItemAt(1); // ChestItemStack legs = armor.getItemAt(2); // LegsItemStack feet = armor.getItemAt(3); // FeetItemStack cape = armor.getItemAt(4); // CapeItemStack accessory = armor.getItemAt(5); // Accessory
// Check if slot is emptyif (armor.isEmpty(0)) { // No helmet equipped}Checking Item in Hand
Section titled “Checking Item in Hand”// Get currently held itemItemStack heldItem = inventory.getItemInHand();
if (heldItem != null) { Item item = heldItem.getItem(); String itemId = item.getId(); int quantity = heldItem.getQuantity();
// Check item type if (item.getWeapon() != null) { // Holding a weapon } else if (item.getTool() != null) { // Holding a tool } else if (item.getBlock() != null) { // Holding a placeable block }}SmartMoveType
Section titled “SmartMoveType”Options for intelligent item placement:
| Type | Description |
|---|---|
EquipOrMergeStack | Auto-equip armor/tools, or merge with existing stacks |
ToHotbar | Move to hotbar if possible |
ToStorage | Move to main storage |
ToArmor | Equip in appropriate armor slot |
Slot Indices
Section titled “Slot Indices”- 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)
Related
Section titled “Related”- Inventory System - Full inventory API
- Entity System - Player entity
- Item System - Item types and stacks