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.

InventoryAssert

Section Constants

Inventories are divided into sections. HRTK defines constants for the three standard sections:
ConstantValueDescription
SECTION_STORAGE0Main storage area
SECTION_ARMOR1Armor equipment slots
SECTION_HOTBAR2Hotbar slots

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

Examples

@InventoryTest
void hotbarSlotContainsSword(WorldTestContext ctx) {
    Object entity = ctx.spawnEntity("hytale:player_test", 0, 64, 0);
    ctx.waitTicks(1);

    Object inventory = getInventory(ctx, entity);
    InventoryAssert.assertSlotContains(
        inventory,
        InventoryAssert.SECTION_HOTBAR,  // section 2
        0,                                // slot index
        "hytale:wood_sword",             // expected item
        1                                 // expected quantity
    );
}
@InventoryTest
void newEntityHasEmptyInventory(WorldTestContext ctx) {
    Object entity = ctx.spawnEntity("hytale:kweebec", 0, 64, 0);
    ctx.waitTicks(1);

    Object inventory = getInventory(ctx, entity);
    InventoryAssert.assertInventoryEmpty(inventory);
}
@InventoryTest
void inventoryContainsGold(WorldTestContext ctx) {
    Object entity = ctx.spawnEntity("hytale:kweebec", 0, 64, 0);
    ctx.waitTicks(1);

    // Give the entity a gold coin via your game logic
    giveItem(ctx, entity, "hytale:gold_coin", 5);
    ctx.waitTicks(1);

    Object inventory = getInventory(ctx, entity);
    InventoryAssert.assertInventoryContains(inventory, "hytale:gold_coin");
}
@HytaleTest
void itemStackHasCorrectValues() {
    Object stack = createItemStack("hytale:iron_ingot", 32);
    InventoryAssert.assertItemStackEquals(stack, "hytale:iron_ingot", 32);
}

LootAssert

Loot assertions work on List<?> of dropped item stacks — the kind of list you get when an entity dies or a loot table is rolled.

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

Examples

@FlowTest
void kweebecDropsHide(WorldTestContext ctx) {
    Object entity = ctx.spawnEntity("hytale:kweebec", 0, 64, 0);
    ctx.waitTicks(1);

    killEntity(ctx, entity);
    List<?> drops = ctx.awaitCondition(
        () -> collectDrops(ctx, 0, 64, 0), 60
    );

    LootAssert.assertDropsContain(drops, "hytale:kweebec_hide");
}
@FlowTest
void bossDropsMinimumGold(WorldTestContext ctx) {
    Object boss = ctx.spawnEntity("mymod:boss_mob", 0, 64, 0);
    ctx.waitTicks(1);

    killEntity(ctx, boss);
    List<?> drops = ctx.awaitCondition(
        () -> collectDrops(ctx, 0, 64, 0), 100
    );

    LootAssert.assertDropsContain(drops, "hytale:gold_coin", 10);
}
@HytaleTest
void peacefulEntityDropsNothing() {
    List<?> drops = Collections.emptyList();
    LootAssert.assertNoDrops(drops);
}
@FlowTest
void lootTableDropsBetween2And5Stacks(WorldTestContext ctx) {
    List<?> drops = rollLootTable("mymod:standard_chest");
    LootAssert.assertDropCountBetween(drops, 2, 5);
}
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.

Isolation

Inventory and loot tests typically mutate entity state. Use IsolationStrategy.DEDICATED_WORLD:
@HytaleSuite(value = "Inventory Tests", isolation = IsolationStrategy.DEDICATED_WORLD)
@Tag("inventory")
public class InventoryTests { }

Next Steps