HRTK provides two assertion classes for item-related testing: InventoryAssert for verifying inventory contents by section and slot, and LootAssert for verifying drop lists after entity kills or loot table rolls.
Inventory and loot testing catches bugs that are easy to miss manually - items placed in the wrong slot, stacks that exceed their maximum, loot tables that drop nothing, or equipment that fails to appear in the armor section. Automated tests verify these mechanics consistently across every build.
Item IDs and drop list IDs used in examples depend on the game’s item registry. Replace with your mod’s actual item and drop list identifiers.
Inventory Section Constants
Inventories in Hytale are divided into sections. HRTK defines constants for the three standard sections:
| Constant | Value | Description |
|---|
SECTION_STORAGE | 0 | Main storage area (backpack, general inventory) |
SECTION_ARMOR | 1 | Armor equipment slots (helmet, chestplate, leggings, boots) |
SECTION_HOTBAR | 2 | Hotbar slots (quick-access items the player can switch between) |
These constants keep your test code readable. Instead of writing magic numbers like 0 or 2, you write InventoryAssert.SECTION_HOTBAR.
Complete Example Suite
InventoryAssert Methods
| Method | Description |
|---|
assertSlotContains(inventory, section, slot, itemId, quantity) | Slot has expected item and count |
assertSlotEmpty(inventory, section, slot) | Slot is empty |
assertInventoryContains(inventory, itemId) | Any slot in any section has the item |
assertInventoryEmpty(inventory) | All slots in all sections are empty |
assertItemStackEquals(stack, itemId, quantity) | Item stack matches expected values |
LootAssert Methods
| Method | Description |
|---|
assertDropsContain(drops, itemId) | Drops include at least one stack of the item |
assertDropsContain(drops, itemId, minQuantity) | Drops include the item with at least N total |
assertDropCount(drops, expected) | Drops list has exactly N stacks |
assertDropCountBetween(drops, min, max) | Drop count is within range (inclusive) |
assertNoDrops(drops) | Drops list is empty |
Inventory Testing Patterns
Inventory tests follow a consistent pattern:
- Spawn an NPC that has an inventory component
- Give items using
ctx.giveItem(entity, itemId, count)
- Retrieve the inventory with
ctx.getInventory(entity)
- Assert on slots, sections, or the whole inventory
For loot tests, the pattern is slightly different:
- Spawn an NPC, then kill it
- Collect drops using
ctx.awaitCondition(() -> ctx.collectDrops(...), maxTicks)
- Assert on the drop list contents
When testing randomized loot, use @RepeatedTest to run the test multiple times and catch edge cases in drop distributions. Combine with assertDropCountBetween for range-based validation.
Next Steps