Class AnvilCostCalculator
java.lang.Object
io.artificial.enchantments.internal.anvil.AnvilCostCalculator
Calculates anvil costs for enchantment operations.
Implements vanilla-like anvil cost calculation with support for custom enchantments. Costs are based on:
- Base operation cost (repair, combine, rename)
- Per-enchantment cost based on rarity and level
- Prior work penalty from previous anvil uses
- Treasure enchantment multiplier
- Since:
- 0.2.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateCombineCost(@NotNull Map<EnchantmentDefinition, Integer> targetEnchantments, @NotNull Map<EnchantmentDefinition, Integer> sacrificeEnchantments, int targetPriorWork, int sacrificePriorWork, boolean isTreasureBook) Calculates the cost for combining two items in an anvil.static intcalculateNewPriorWork(int currentPriorWork) Calculates the new prior work penalty after an anvil operation.static intcalculateRenameCost(String currentName, String newName, int priorWork) Calculates the cost for renaming an item.static intcalculateRepairCost(int materialCost, int priorWork) Calculates the cost for repairing an item with materials.static intGets the maximum allowed anvil cost.static booleanisTooExpensive(int cost) Checks if a cost exceeds the maximum allowed (too expensive).static intmaxPriorWork(int priorWorkA, int priorWorkB) Calculates the maximum of two prior work penalties.
-
Method Details
-
calculateCombineCost
public static int calculateCombineCost(@NotNull @NotNull Map<EnchantmentDefinition, Integer> targetEnchantments, @NotNull @NotNull Map<EnchantmentDefinition, Integer> sacrificeEnchantments, int targetPriorWork, int sacrificePriorWork, boolean isTreasureBook) Calculates the cost for combining two items in an anvil.This includes costs for:
- Base combine operation
- Each enchantment being added/upgraded
- Prior work penalties from both items
- Parameters:
targetEnchantments- enchantments on the target itemsacrificeEnchantments- enchantments on the sacrifice item (book or item)targetPriorWork- prior work penalty of target itemsacrificePriorWork- prior work penalty of sacrifice itemisTreasureBook- whether the sacrifice is a treasure book- Returns:
- the total experience cost
- Since:
- 0.2.0
-
calculateRenameCost
Calculates the cost for renaming an item.- Parameters:
currentName- the current name of the item (null if unnamed)newName- the desired new name (null to clear name)priorWork- prior work penalty of the item- Returns:
- the experience cost, or -1 if too expensive
- Since:
- 0.2.0
-
calculateRepairCost
public static int calculateRepairCost(int materialCost, int priorWork) Calculates the cost for repairing an item with materials.- Parameters:
materialCost- cost of materials usedpriorWork- prior work penalty of the item- Returns:
- the total experience cost
- Since:
- 0.2.0
-
calculateNewPriorWork
public static int calculateNewPriorWork(int currentPriorWork) Calculates the new prior work penalty after an anvil operation.Prior work penalty doubles each time an item is used in an anvil, capped at a reasonable maximum to prevent exponential growth.
- Parameters:
currentPriorWork- the current prior work penalty- Returns:
- the new prior work penalty
- Since:
- 0.2.0
-
maxPriorWork
public static int maxPriorWork(int priorWorkA, int priorWorkB) Calculates the maximum of two prior work penalties.Used when combining items - the result gets the higher of the two penalties.
- Parameters:
priorWorkA- first prior work valuepriorWorkB- second prior work value- Returns:
- the maximum prior work
- Since:
- 0.2.0
-
isTooExpensive
public static boolean isTooExpensive(int cost) Checks if a cost exceeds the maximum allowed (too expensive).- Parameters:
cost- the calculated cost- Returns:
- true if the cost exceeds the maximum
- Since:
- 0.2.0
-
getMaxCost
public static int getMaxCost()Gets the maximum allowed anvil cost.- Returns:
- the maximum cost (39)
- Since:
- 0.2.0
-