Loot Bag System
Thaumcraft treasure bags are loot containers that drop from certain defeated mobs. Mods can register custom loot to appear in the three bag tiers.
Bag Tiers
| Tier | Rarity Index | Description |
|---|---|---|
| Common | 0 |
Most frequent drops, smallest bags |
| Uncommon | 1 |
Moderate rarity, medium bags |
| Rare | 2 |
Rare drops, largest bags |
API Registration
addLootBagItem
public static void addLootBagItem(ItemStack item, int weight, int... bagTypes)
Adds a possible loot item to the specified bag type(s).
| Parameter | Type | Description |
|---|---|---|
item |
ItemStack |
The item that can appear in the bag |
weight |
int |
Relative weight (higher = more common); gold coins = 2000, diamond = 50 |
bagTypes |
int... |
Which bag tiers to include. Pass nothing for common only. |
// Add to all bag types
ThaumcraftApi.addLootBagItem(new ItemStack(Items.gold_ingot), 200);
// Common bag only
ThaumcraftApi.addLootBagItem(new ItemStack(Items.iron_ingot), 100, 0);
// Uncommon and rare bags
ThaumcraftApi.addLootBagItem(new ItemStack(MyModItems.rare_drop), 50, 1, 2);
WeightedRandomLoot
Package: thaumcraft.api.internal
The internal class managing the loot pools.
public class WeightedRandomLoot extends WeightedRandom.Item {
public ItemStack item;
public WeightedRandomLoot(ItemStack stack, int weight)
public static ArrayList<WeightedRandomLoot> lootBagCommon;
public static ArrayList<WeightedRandomLoot> lootBagUncommon;
public static ArrayList<WeightedRandomLoot> lootBagRare;
}
Extends WeightedRandom.Item (Forge) for weighted random selection. Each bag type uses its own ArrayList.
Weight Reference
The vanilla weight values Thaumcraft uses for reference:
- Gold coins:
2000 - Diamond:
50 - Emerald:
40
A weight of 2000 means the item is as common as gold coins in the common bag. For rare bags, the same weight indicates relative rarity compared to other rare loot.
Implementation Notes
- Loot is selected via weighted random from the appropriate pool when the bag is opened
- Multiple items can be selected from the same bag based on bag tier (common → few items, rare → many items)
- Items with the same weight have an equal chance
- Registration is additive — it does not replace Thaumcraft’s existing loot
- Registration should occur during
FMLPostInitializationEventto avoid conflicts
Example: Full Registration
// In your mod's FMLPostInitEvent handler
public void postInit(FMLPostInitializationEvent event) {
// Common and uncommon items
ThaumcraftApi.addLootBagItem(
new ItemStack(Items.gold_nugget), 500, 0, 1
);
// Uncommon-only rare ingredient
ThaumcraftApi.addLootBagItem(
new ItemStack(MyModItems.mysteriousEssence), 30, 1
);
// Rare-only legendary item
ThaumcraftApi.addLootBagItem(
new ItemStack(MyModItems.arcaneArtifact), 10, 2
);
}
Integration with Other Systems
The loot bag system is independent of entity loot tables. Bags are generated by Thaumcraft entities (e.g., monsters) and the bag opening UI draws from the registered WeightedRandomLoot pools. There is no direct API to trigger a bag drop — that is handled internally by Thaumcraft mob AI and death handlers.