Enchant API

Overview

The enchantment system extends beyond vanilla Minecraft enchantments, providing custom effects with configurable levels, chances, and trigger conditions. Enchantments can be tied to specific materials and have complex probability-based activation systems.


Enchantment Registration

void registerEnchant(String id, APIEnchant enchant)

  • Description: Registers a new custom enchantment in the system

  • Parameters:

    • id - Unique identifier for the enchantment

    • enchant - APIEnchant implementation defining the enchantment behavior

  • Usage: Plugin initialization, dynamic enchantment loading

  • Note: This allows external plugins to create their own enchantments


Player Enchantment Management

Level Operations

void addEnchantLevel(UUID uuid, String enchant, double level)

  • Description: Increases a player's enchantment level

  • Parameters:

    • uuid - Player's unique identifier

    • enchant - Enchantment identifier

    • level - Levels to add (can be fractional)

  • Usage: Reward progression, enchantment upgrades, leveling systems

double getEnchantLevel(UUID uuid, String enchant)

  • Description: Gets a player's current level in a specific enchantment

  • Parameters:

    • uuid - Player's unique identifier

    • enchant - Enchantment identifier

  • Returns: Current enchantment level (0.0 if not learned)

  • Usage: Display progression, calculate effects, requirement checking

void removeEnchantLevel(UUID uuid, String enchant, double level)

  • Description: Decreases a player's enchantment level

  • Parameters:

    • uuid - Player's unique identifier

    • enchant - Enchantment identifier

    • level - Levels to remove (can be fractional)

  • Usage: Penalties, rebalancing, temporary level reduction

Chance Calculation

double getEnchantChance(UUID uuid, String enchant)

  • Description: Gets the current activation chance for a player's enchantment level

  • Parameters:

    • uuid - Player's unique identifier

    • enchant - Enchantment identifier

  • Returns: Activation chance as decimal (0.0 to 1.0)

  • Usage: Display probability, calculate expected outcomes


Enchantment Activation

Manual Triggering

void triggerCustomEnchant(Player player, String enchant, int mobId)

  • Description: Forcefully triggers an enchantment effect

  • Parameters:

    • player - Player triggering the enchantment

    • enchant - Enchantment to trigger

    • mobId - Target mob entity ID

  • Usage: Guaranteed activation, testing, special abilities

boolean tryTriggerCustomEnchant(Player player, String enchant, int mobId)

  • Description: Attempts to trigger an enchantment based on its activation chance

  • Parameters:

    • player - Player attempting to trigger

    • enchant - Enchantment to attempt

    • mobId - Target mob entity ID

  • Returns: True if enchantment activated, false otherwise

  • Usage: Natural enchantment activation, combat systems


Enchantment Configuration

Level Constraints

double getEnchantMaxLevel(String enchant)

  • Description: Gets the maximum level for an enchantment

  • Parameters: enchant - Enchantment identifier

  • Returns: Maximum achievable level

  • Usage: Progression caps, validation, upgrade limits

double getEnchantStartingLevel(String enchant)

  • Description: Gets the starting level for new players

  • Parameters: enchant - Enchantment identifier

  • Returns: Initial level value

  • Usage: New player initialization, reset operations

double getEnchantMaxChance(String enchant)

  • Description: Gets the maximum activation chance for an enchantment

  • Parameters: enchant - Enchantment identifier

  • Returns: Maximum chance value (typically 1.0 for 100%)

  • Usage: Balance checking, progression planning

Last updated

Was this helpful?