Class AnvilCostCalculator

java.lang.Object
io.artificial.enchantments.internal.anvil.AnvilCostCalculator

public final class AnvilCostCalculator extends Object
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 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 item
      sacrificeEnchantments - enchantments on the sacrifice item (book or item)
      targetPriorWork - prior work penalty of target item
      sacrificePriorWork - prior work penalty of sacrifice item
      isTreasureBook - whether the sacrifice is a treasure book
      Returns:
      the total experience cost
      Since:
      0.2.0
    • calculateRenameCost

      public static int calculateRenameCost(String currentName, String newName, int priorWork)
      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 used
      priorWork - 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 value
      priorWorkB - 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