Skip to main content
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:
ConstantValueDescription
SECTION_STORAGE0Main storage area (backpack, general inventory)
SECTION_ARMOR1Armor equipment slots (helmet, chestplate, leggings, boots)
SECTION_HOTBAR2Hotbar 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

MethodDescription
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

MethodDescription
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:
  1. Spawn an NPC that has an inventory component
  2. Give items using ctx.giveItem(entity, itemId, count)
  3. Retrieve the inventory with ctx.getInventory(entity)
  4. Assert on slots, sections, or the whole inventory
For loot tests, the pattern is slightly different:
  1. Spawn an NPC, then kill it
  2. Collect drops using ctx.awaitCondition(() -> ctx.collectDrops(...), maxTicks)
  3. 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