Infusion Enchantment
Infusion Enchantment is a special variant of infusion crafting used to apply enchantments to items. It is performed at the Infusion Altar and allows enchantments that cannot normally coexist, with instability and XP cost mechanics.
Registration
ThaumcraftApi.addInfusionEnchantmentRecipe(String research,
Enchantment input, // Enchantment to apply
int instability, // Instability ticks per application
AspectList aspects, // Essentia cost
ItemStack[] recipe) // Component items
Parameters
| Parameter | Type | Description |
|---|---|---|
research |
String |
Research key required |
input |
Enchantment |
The enchantment to apply to the item |
instability |
int |
Instability added per craft operation |
aspects |
AspectList |
Essentia cost |
recipe |
ItemStack[] |
Component items placed around the altar |
Example
ThaumcraftApi.addInfusionEnchantmentRecipe(
"INFUSION_ENCHANT_RESEARCH",
Enchantment.sharpness,
8,
new AspectList()
.add(Aspect.WEAPON, 20)
.add(Aspect.FIRE, 10),
new ItemStack[] {
new ItemStack(Items.diamond_sword),
new ItemStack(Items.blaze_rod),
new ItemStack(Items.ender_pearl)
});
InfusionEnchantmentRecipe Class
public class InfusionEnchantmentRecipe {
public AspectList aspects;
public String research;
public ItemStack[] components;
public Enchantment enchantment;
public int recipeXP;
public int instability;
}
Constructor
public InfusionEnchantmentRecipe(String research, Enchantment input, int instability,
AspectList aspects, ItemStack[] recipe)
The recipeXP field is auto-calculated as Math.max(1, input.getMinEnchantability(1) / 3).
Fields
| Field | Type | Description |
|---|---|---|
aspects |
AspectList |
Essentia cost |
research |
String |
Required research key |
components |
ItemStack[] |
Required surrounding components |
enchantment |
Enchantment |
The enchantment being applied |
recipeXP |
int |
Base XP cost (auto-calculated from enchantment) |
instability |
int |
Instability per craft |
Methods
| Method | Returns | Description |
|---|---|---|
matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) |
boolean |
Checks if recipe matches the altar setup |
getEnchantment() |
Enchantment |
The enchantment to apply |
getAspects() |
AspectList |
Essentia cost |
getResearch() |
String |
Required research key |
calcInstability(ItemStack recipeInput) |
int |
input 上全部附魔等级之和 / 2 + instability(见下文订正) |
calcXP(ItemStack recipeInput) |
int |
XP cost: recipeXP × (1 + existing enchantment level) |
getEssentiaMod(ItemStack recipeInput) |
float |
目标附魔等级 + Σ(其他附魔等级 × 0.1),无 0~1 上限(见下文订正) |
matches()
The match logic validates:
- Research is complete (if required)
- The central item can accept this enchantment (
canApply) - The central item is a valid tool (
isItemTool) - Existing enchantments on the item are compatible (no conflict via
canApplyTogether) - The enchantment is not already at max level on the item
- All components are present in the altar’s input pool
// Enchantment compatibility check
if (!enchantment.canApply(central) || !central.getItem().isItemTool(central)) {
return false;
}
// Check existing enchantments for conflicts
Map map1 = EnchantmentHelper.getEnchantments(central);
Iterator iterator = map1.keySet().iterator();
while (iterator.hasNext()) {
int j1 = ((Integer) iterator.next()).intValue();
Enchantment ench = Enchantment.enchantmentsList[j1];
if (j1 == enchantment.effectId &&
EnchantmentHelper.getEnchantmentLevel(j1, central) >= ench.getMaxLevel()) {
return false; // Already at max level
}
if (enchantment.effectId != ench.effectId &&
(!enchantment.canApplyTogether(ench) || !ench.canApplyTogether(enchantment))) {
return false; // Conflicting enchantment
}
}
calcXP()
public int calcXP(ItemStack recipeInput) {
return recipeXP * (1 + EnchantmentHelper.getEnchantmentLevel(enchantment.effectId, recipeInput));
}
XP cost increases based on the existing level of the same enchantment on the input item. This means re-enchanting an already-enchanted item costs more.
calcInstability()
⚠️ 已订正:原条目写成「直接
return instability;,recipeInput仅供子类重写」——这是错的。 API 里的实现实际会累加recipeInput上的全部附魔等级。 正确实现(证据:crafting/InfusionEnchantmentRecipe.java:125-135):public int calcInstability(ItemStack recipeInput) { int i = 0; Map map1 = EnchantmentHelper.getEnchantments(recipeInput); Iterator iterator = map1.keySet().iterator(); while (iterator.hasNext()) { int j1 = ((Integer)iterator.next()).intValue(); i += EnchantmentHelper.getEnchantmentLevel(j1, recipeInput); } return (i/2) + instability; }
返回值为 (输入物品所有附魔等级之和 / 2) + 配方基础 instability。整数除法向下取整。
getEssentiaMod()
public float getEssentiaMod(ItemStack recipeInput) {
float mod = EnchantmentHelper.getEnchantmentLevel(enchantment.effectId, recipeInput);
// 叠加其他每个附魔的等级 × 0.1
return mod;
}
⚠️ 已订正:原条目写「Returns a modifier (0.0–1.0)」——这是错的,该方法没有 0~1 的取值上限。 正确公式(证据:
crafting/InfusionEnchantmentRecipe.java:141-152):返回值 = 本配方附魔在输入物品上的等级 + Σ(其他每个附魔在输入物品上的等级 × 0.1f)高等级附魔会让该值远超 1.0(例:目标附魔 5 级 + 两个 5 级其他附魔 = 5 + 0.5 + 0.5 = 6.0)。
Aspect Compatibility
Infusion enchantments require matching essentia aspects just like regular infusion recipes. The AspectList defines the essentia types and amounts needed. Aspects are drained from the Vis pool in the same way as standard infusion crafting.
Finding Recipes
// Iterate all recipes looking for InfusionEnchantmentRecipe
for (Object r : ThaumcraftApi.getCraftingRecipes()) {
if (r instanceof InfusionEnchantmentRecipe) {
InfusionEnchantmentRecipe er = (InfusionEnchantmentRecipe) r;
// ...
}
}