跳到正文
烈焰甘蔗Wiki

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 two weight values named in the API’s own javadoc, for reference:

  • Gold coins: 2000
  • Diamond: 50

⚠️ 已订正:原条目此处列了第三条「Emerald: 40」——源码里没有这个值,系编造。 证据:ThaumcraftApi.java:474-475 的 javadoc 原文只提到两个数字: 「the weight of gold coins are 2000 and a diamond is 50」。已删除。

「A weight of 2000 means … in the common bag」以及稀有袋的相对稀有度说明无法从本仓核实 (实际权重表在主 mod)。

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 FMLPostInitializationEvent to 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.

浏览全部模组