Class EnchantContextBuilder

java.lang.Object
johnsmith.enchantingoverhauled.menu.enchant.controller.EnchantContextBuilder

public class EnchantContextBuilder extends Object
A fluent builder that manages the complex generation pipeline of generating available enchantment options for the Enchanting Altar menu.

Evaluates the existing Target enchantments, overlaps and resolves Source catalyst enchantments, and randomly generates missing slots via the Table, returning a deterministic List of EnchantContext.

  • Method Summary

    Modifier and Type
    Method
    Description
    begin(net.minecraft.world.item.ItemStack target, net.minecraft.world.item.ItemStack source, int power, int baseSeed)
    Initializes a new pipeline builder instance.
    build(ToIntFunction<net.minecraft.world.item.enchantment.Enchantment> costCalculator)
    Finalizes the generated contexts, sorting actionable options to the top of the list, assigning their specific slot indexes, and calculating their dynamic resource costs via the provided strategy function.
    List<net.minecraft.world.item.enchantment.EnchantmentInstance>
    generateEnchantments(net.minecraft.util.RandomSource random, net.minecraft.world.item.ItemStack target, boolean treasureAllowed, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Generates a randomized list of possible enchantments for an item based on its enchantability, filtered by available themed power providers.
    List<net.minecraft.world.item.enchantment.EnchantmentInstance>
    getEnchantmentsAsList(net.minecraft.world.item.enchantment.ItemEnchantments enchantments)
    Converts an ItemEnchantments component into a List of EnchantmentInstance objects.
    List<net.minecraft.world.item.enchantment.EnchantmentInstance>
    getPossibleEntries(net.minecraft.world.item.ItemStack target, boolean treasureAllowed, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
    Gets a list of all enchantment entries that can possibly be applied to the given item, filtered by the available themed power providers.
    boolean
    hasThemedPowerProvider(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos tablePos, net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey)
    Checks if an enchanting table has any valid power providers for a *specific theme* nearby.
    Reads the enchantments from the provided source catalyst and applies them to the context.
    withTableEnchantments(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.util.RandomSource random)
    Randomly generates new vanilla-style enchantment options to fill any remaining empty cap slots up to the configured max enchantment limit.
    Reads all enchantments currently present on the target item, tracking their true levels and cap contributions while respecting Config.CURSE_CONCEALMENT_MODE for UI slot creation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • begin

      public static EnchantContextBuilder begin(net.minecraft.world.item.ItemStack target, net.minecraft.world.item.ItemStack source, int power, int baseSeed)
      Initializes a new pipeline builder instance.
      Parameters:
      target - The target item to be enchanted.
      source - The secondary catalyst item (e.g., a Tome).
      power - The calculated enchanting power derived from nearby bookshelves.
      baseSeed - The player's current deterministic enchantment seed.
      Returns:
      A new builder instance.
    • withTargetEnchantments

      public EnchantContextBuilder withTargetEnchantments()
      Reads all enchantments currently present on the target item, tracking their true levels and cap contributions while respecting Config.CURSE_CONCEALMENT_MODE for UI slot creation. Visible target enchantments are sorted by priority (Overleveled > Maxed > Upgradable) and inserted into the context list.
      Returns:
      The builder instance for chaining.
    • withSourceEnchantments

      public EnchantContextBuilder withSourceEnchantments()
      Reads the enchantments from the provided source catalyst and applies them to the context. Overwrites existing target context slots if an upgrade/transfer conflict is found, reveals concealed target curses against their true applied level when challenged by an unconcealed source curse, or appends them as new options if functionally compatible and within the cap budget.
      Returns:
      The builder instance for chaining.
    • withTableEnchantments

      public EnchantContextBuilder withTableEnchantments(net.minecraft.world.level.Level world, net.minecraft.core.BlockPos pos, net.minecraft.util.RandomSource random)
      Randomly generates new vanilla-style enchantment options to fill any remaining empty cap slots up to the configured max enchantment limit. Ensures compatibility with already assigned contexts and concealed target enchantments to prevent mutually exclusive rules.
      Parameters:
      world - The active level.
      pos - The block position.
      random - The deterministic random generator initialized with the player's seed.
      Returns:
      The builder instance for chaining.
    • build

      public List<EnchantContext> build(ToIntFunction<net.minecraft.world.item.enchantment.Enchantment> costCalculator)
      Finalizes the generated contexts, sorting actionable options to the top of the list, assigning their specific slot indexes, and calculating their dynamic resource costs via the provided strategy function.
      Parameters:
      costCalculator - The strategy function calculating base resource cost for an enchantment.
      Returns:
      The final immutable list of contexts to be dispatched to the UI.
    • getEnchantmentsAsList

      public List<net.minecraft.world.item.enchantment.EnchantmentInstance> getEnchantmentsAsList(net.minecraft.world.item.enchantment.ItemEnchantments enchantments)
      Converts an ItemEnchantments component into a List of EnchantmentInstance objects.
      Parameters:
      enchantments - The component to process.
      Returns:
      A List of entries.
    • generateEnchantments

      public List<net.minecraft.world.item.enchantment.EnchantmentInstance> generateEnchantments(net.minecraft.util.RandomSource random, net.minecraft.world.item.ItemStack target, boolean treasureAllowed, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Generates a randomized list of possible enchantments for an item based on its enchantability, filtered by available themed power providers.
    • getPossibleEntries

      public List<net.minecraft.world.item.enchantment.EnchantmentInstance> getPossibleEntries(net.minecraft.world.item.ItemStack target, boolean treasureAllowed, net.minecraft.world.level.Level level, net.minecraft.core.BlockPos pos)
      Gets a list of all enchantment entries that can possibly be applied to the given item, filtered by the available themed power providers.
    • hasThemedPowerProvider

      public boolean hasThemedPowerProvider(net.minecraft.world.level.Level level, net.minecraft.core.BlockPos tablePos, net.minecraft.resources.ResourceKey<EnchantmentTheme> themeKey)
      Checks if an enchanting table has any valid power providers for a *specific theme* nearby.